1
0
Fork 0

Improve performance and crash resistance when loading PE files containing 1000 or more sections. Tested on https://github.com/corkami/pocs/blob/master/PE/bin/65535sects.exe. Technically performance was already very good, but that was only due to crashing instantly

This commit is contained in:
Mattiwatti 2018-03-24 07:35:41 +01:00 committed by Duncan Ogilvie
parent f515484790
commit 0bb2efcb2c
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
2 changed files with 3 additions and 2 deletions

View File

@ -153,7 +153,7 @@ void MemUpdateMap()
{
duint start = (duint)currentPage.mbi.BaseAddress;
duint end = start + currentPage.mbi.RegionSize;
for(int j = 0, k = 0; j < SectionNumber; j++)
for(duint j = 0, k = 0; (j < (duint)SectionNumber) && (k + IMAGE_SIZEOF_SHORT_NAME < MAX_MODULE_SIZE); j++)
{
const auto & currentSection = sections.at(j);
duint secStart = currentSection.addr;

View File

@ -575,8 +575,9 @@ void GetModuleInfo(MODINFO & Info, ULONG_PTR FileMapVA)
}
// Enumerate all PE sections
Info.sections.clear();
WORD sectionCount = Info.headers->FileHeader.NumberOfSections;
Info.sections.clear();
Info.sections.reserve(sectionCount);
PIMAGE_SECTION_HEADER ntSection = IMAGE_FIRST_SECTION(Info.headers);
for(WORD i = 0; i < sectionCount; i++)