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); 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; 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) if(IsBigEndian)
{ {
@@ -179,8 +182,12 @@ namespace libexeinfo
pos += pos % 4 != 0 ? 4 - pos % 4 : 0; pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
Array.Copy(buffer, pos, note.contents, 0, descsz); Array.Copy(buffer, pos, note.contents, 0, descsz);
pos += (int)descsz;
pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
RequiredOperatingSystem = GetOsByNote(note, interpreter, IsBigEndian); RequiredOperatingSystem = GetOsByNote(note, interpreter, IsBigEndian);
}
break; break;
} }
} }
@@ -418,10 +425,13 @@ 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; uint namesz = BitConverter.ToUInt32(buffer, pos);
uint descsz = BitConverter.ToUInt32(buffer, pos + 4);
uint notetype = BitConverter.ToUInt32(buffer, pos + 8);
pos += 12;
if(IsBigEndian) if(IsBigEndian)
{ {
@@ -442,8 +452,13 @@ namespace libexeinfo
pos += pos % 4 != 0 ? 4 - pos % 4 : 0; pos += pos % 4 != 0 ? 4 - pos % 4 : 0;
Array.Copy(buffer, pos, note.contents, 0, descsz); 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);
}
} }
} }