mirror of
https://github.com/claunia/libexeinfo.git
synced 2025-12-16 19:14:24 +00:00
Handle ELF notes with arrays.
This commit is contained in:
@@ -155,32 +155,39 @@ namespace libexeinfo
|
|||||||
interpreter = StringHandlers.CToString(buffer);
|
interpreter = StringHandlers.CToString(buffer);
|
||||||
break;
|
break;
|
||||||
case phType.PT_NOTE when buffer.Length > 12:
|
case phType.PT_NOTE when buffer.Length > 12:
|
||||||
uint namesz = BitConverter.ToUInt32(buffer, 0);
|
pos = 0;
|
||||||
uint descsz = BitConverter.ToUInt32(buffer, 4);
|
while(pos < buffer.Length)
|
||||||
uint notetype = BitConverter.ToUInt32(buffer, 8);
|
|
||||||
pos = 12;
|
|
||||||
|
|
||||||
if(IsBigEndian)
|
|
||||||
{
|
{
|
||||||
namesz = Swapping.Swap(namesz);
|
uint namesz = BitConverter.ToUInt32(buffer, pos + 0);
|
||||||
descsz = Swapping.Swap(descsz);
|
uint descsz = BitConverter.ToUInt32(buffer, pos + 4);
|
||||||
notetype = Swapping.Swap(notetype);
|
uint notetype = BitConverter.ToUInt32(buffer, pos + 8);
|
||||||
|
pos += 12;
|
||||||
|
|
||||||
|
if(IsBigEndian)
|
||||||
|
{
|
||||||
|
namesz = Swapping.Swap(namesz);
|
||||||
|
descsz = Swapping.Swap(descsz);
|
||||||
|
notetype = Swapping.Swap(notetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
ElfNote note = new ElfNote
|
||||||
|
{
|
||||||
|
name = Encoding.ASCII.GetString(buffer, pos, (int)(namesz - 1)),
|
||||||
|
type = notetype,
|
||||||
|
contents = new byte[descsz]
|
||||||
|
};
|
||||||
|
|
||||||
|
pos += (int)namesz;
|
||||||
|
|
||||||
|
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
||||||
|
|
||||||
|
Array.Copy(buffer, pos, note.contents, 0, descsz);
|
||||||
|
pos += (int)descsz;
|
||||||
|
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
||||||
|
|
||||||
|
RequiredOperatingSystem = GetOsByNote(note, interpreter, IsBigEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElfNote note = new ElfNote
|
|
||||||
{
|
|
||||||
name = Encoding.ASCII.GetString(buffer, pos, (int)(namesz - 1)),
|
|
||||||
type = notetype,
|
|
||||||
contents = new byte[descsz]
|
|
||||||
};
|
|
||||||
|
|
||||||
pos += (int)namesz;
|
|
||||||
|
|
||||||
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
|
||||||
|
|
||||||
Array.Copy(buffer, pos, note.contents, 0, descsz);
|
|
||||||
|
|
||||||
RequiredOperatingSystem = GetOsByNote(note, interpreter, IsBigEndian);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,32 +425,40 @@ namespace libexeinfo
|
|||||||
}
|
}
|
||||||
else if(sectionNames[i].StartsWith(".note") && buffer.Length > 12)
|
else if(sectionNames[i].StartsWith(".note") && buffer.Length > 12)
|
||||||
{
|
{
|
||||||
uint namesz = BitConverter.ToUInt32(buffer, 0);
|
pos = 0;
|
||||||
uint descsz = BitConverter.ToUInt32(buffer, 4);
|
while(pos < buffer.Length)
|
||||||
uint notetype = BitConverter.ToUInt32(buffer, 8);
|
|
||||||
pos = 12;
|
|
||||||
|
|
||||||
if(IsBigEndian)
|
|
||||||
{
|
{
|
||||||
namesz = Swapping.Swap(namesz);
|
uint namesz = BitConverter.ToUInt32(buffer, pos);
|
||||||
descsz = Swapping.Swap(descsz);
|
uint descsz = BitConverter.ToUInt32(buffer, pos + 4);
|
||||||
notetype = Swapping.Swap(notetype);
|
uint notetype = BitConverter.ToUInt32(buffer, pos + 8);
|
||||||
|
pos += 12;
|
||||||
|
|
||||||
|
if(IsBigEndian)
|
||||||
|
{
|
||||||
|
namesz = Swapping.Swap(namesz);
|
||||||
|
descsz = Swapping.Swap(descsz);
|
||||||
|
notetype = Swapping.Swap(notetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
ElfNote note = new ElfNote
|
||||||
|
{
|
||||||
|
name = Encoding.ASCII.GetString(buffer, pos, (int)(namesz - 1)),
|
||||||
|
type = notetype,
|
||||||
|
contents = new byte[descsz]
|
||||||
|
};
|
||||||
|
|
||||||
|
pos += (int)namesz;
|
||||||
|
|
||||||
|
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
||||||
|
|
||||||
|
Array.Copy(buffer, pos, note.contents, 0, descsz);
|
||||||
|
pos += (int)descsz;
|
||||||
|
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
||||||
|
|
||||||
|
string notename = note.type != 1 ? $"{sectionNames[i]}.{note.type}" : sectionNames[i];
|
||||||
|
if(!notes.ContainsKey(notename))
|
||||||
|
notes.Add(notename, note);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElfNote note = new ElfNote
|
|
||||||
{
|
|
||||||
name = Encoding.ASCII.GetString(buffer, pos, (int)(namesz - 1)),
|
|
||||||
type = notetype,
|
|
||||||
contents = new byte[descsz]
|
|
||||||
};
|
|
||||||
|
|
||||||
pos += (int)namesz;
|
|
||||||
|
|
||||||
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
|
|
||||||
|
|
||||||
Array.Copy(buffer, pos, note.contents, 0, descsz);
|
|
||||||
|
|
||||||
notes.Add(sectionNames[i], note);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user