3#define DEFAULT_IMGBASE 0x10000
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");
70 const offset_t signSize =
sizeof(DWORD);
71 return offset + signSize;
80 return offset +
sizeof(IMAGE_FILE_HEADER);
86 return sizeof(IMAGE_NT_HEADERS64);
88 return sizeof(IMAGE_NT_HEADERS32);
101 return offset + size;
108 return opt32->SectionAlignment;
112 return opt64->SectionAlignment;
121 imgSize =
opt32->SizeOfImage;
124 imgSize =
opt64->SizeOfImage;
133 hdrsSize =
opt32->SizeOfHeaders;
136 hdrsSize =
opt64->SizeOfHeaders;
145 imgBase =
opt32->ImageBase;
148 imgBase =
opt64->ImageBase;
160 if (maxOffset >= 0x80000000) {
const offset_t INVALID_ADDR
virtual BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
virtual bufsize_t getAlignment(Executable::addr_type aType) const
bufsize_t hdrsSize() const
offset_t peOptHdrOffset() const
IMAGE_OPTIONAL_HEADER32 * opt32
bool wrap(AbstractByteBuffer *v_buf)
virtual offset_t getImageBase()
offset_t peFileHdrOffset() const
virtual bufsize_t getImageSize()
offset_t peSignatureOffset() const
bufsize_t peNtHeadersSize() const
offset_t secHdrsOffset() const
IMAGE_OPTIONAL_HEADER64 * opt64
Executable::exe_bits getHdrBitMode() const