16 const bool allowExceptionsFromBuffer =
false;
22 this->
dos = (IMAGE_DOS_HEADER*)
buf->getContentAt(offset,
sizeof(IMAGE_DOS_HEADER), allowExceptionsFromBuffer);
23 if (!
dos)
throw ExeException(
"Could not wrap PECore: invalid DOS Header!");
25 offset =
dos->e_lfanew +
sizeof(DWORD);
26 this->
fHdr = (IMAGE_FILE_HEADER*)
buf->getContentAt(offset,
sizeof(IMAGE_FILE_HEADER), allowExceptionsFromBuffer);
29 offset = offset +
sizeof(IMAGE_FILE_HEADER);
30 WORD *magic = (WORD*)
buf->getContentAt(offset,
sizeof(WORD), allowExceptionsFromBuffer);
31 if (!magic)
throw ExeException(
"Could not wrap PECore: invalid FileHeader");
34 const size_t ntHdrSize = (mode ==
Executable::BITS_32) ?
sizeof(IMAGE_OPTIONAL_HEADER32) :
sizeof(IMAGE_OPTIONAL_HEADER64);
35 BYTE *ntHdrPtr =
buf->getContentAt(offset, ntHdrSize, allowExceptionsFromBuffer);
39 this->
opt32 = (IMAGE_OPTIONAL_HEADER32*)ntHdrPtr;
42 this->
opt64 = (IMAGE_OPTIONAL_HEADER64*)ntHdrPtr;
46 throw ExeException(
"Could not wrap PECore: invalid OptionalHeader");