Handle ELF notes with arrays.

This commit is contained in:
2018-03-15 10:30:13 +00:00
parent 8644a36e40
commit 7c9d288fcb

View File

@@ -155,10 +155,13 @@ namespace libexeinfo
interpreter = StringHandlers.CToString(buffer);
break;
case phType.PT_NOTE when buffer.Length > 12:
uint namesz = BitConverter.ToUInt32(buffer, 0);
uint descsz = BitConverter.ToUInt32(buffer, 4);
uint notetype = BitConverter.ToUInt32(buffer, 8);
pos = 12;
pos = 0;
while(pos < buffer.Length)
{
uint namesz = BitConverter.ToUInt32(buffer, pos + 0);
uint descsz = BitConverter.ToUInt32(buffer, pos + 4);
uint notetype = BitConverter.ToUInt32(buffer, pos + 8);
pos += 12;
if(IsBigEndian)
{
@@ -179,8 +182,12 @@ namespace libexeinfo
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);
}
break;
}
}
@@ -418,10 +425,13 @@ namespace libexeinfo
}
else if(sectionNames[i].StartsWith(".note") && buffer.Length > 12)
{
uint namesz = BitConverter.ToUInt32(buffer, 0);
uint descsz = BitConverter.ToUInt32(buffer, 4);
uint notetype = BitConverter.ToUInt32(buffer, 8);
pos = 12;
pos = 0;
while(pos < buffer.Length)
{
uint namesz = BitConverter.ToUInt32(buffer, pos);
uint descsz = BitConverter.ToUInt32(buffer, pos + 4);
uint notetype = BitConverter.ToUInt32(buffer, pos + 8);
pos += 12;
if(IsBigEndian)
{
@@ -442,8 +452,13 @@ namespace libexeinfo
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;
notes.Add(sectionNames[i], note);
string notename = note.type != 1 ? $"{sectionNames[i]}.{note.type}" : sectionNames[i];
if(!notes.ContainsKey(notename))
notes.Add(notename, note);
}
}
}