PeFile check MZ offset to PE header
modified: pefile.cpp
This commit is contained in:
parent
b413f3da26
commit
143f0accef
@ -162,10 +162,17 @@ int PeFile::readFileHeader()
|
|||||||
|
|
||||||
if (h.mz == 'M' + 'Z'*256) // dos exe
|
if (h.mz == 'M' + 'Z'*256) // dos exe
|
||||||
{
|
{
|
||||||
if (h.relocoffs >= 0x40) // new format exe
|
unsigned const delta = (h.relocoffs >= 0x40)
|
||||||
pe_offset += h.nexepos;
|
? h.nexepos // new format exe
|
||||||
else
|
: (h.p512*512+h.m512 - h.m512 ? 512 : 0);
|
||||||
pe_offset += h.p512*512+h.m512 - h.m512 ? 512 : 0;
|
|
||||||
|
if ((pe_offset + delta) < delta // wrap-around
|
||||||
|
|| (pe_offset + delta) > file_size) {
|
||||||
|
char buf[64]; snprintf(buf, sizeof(buf),
|
||||||
|
"bad PE delta %#x at offset %#x", delta, pe_offset);
|
||||||
|
throwCantPack(buf);
|
||||||
|
}
|
||||||
|
pe_offset += delta;
|
||||||
}
|
}
|
||||||
else if (get_le32(&h) == 'P' + 'E'*256)
|
else if (get_le32(&h) == 'P' + 'E'*256)
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user