3#define DEFAULT_IMGBASE 0x10000
16 bool allowExceptions =
true;
21 this->
dos = (IMAGE_DOS_HEADER*)
buf->
getContentAt(offset,
sizeof(IMAGE_DOS_HEADER), allowExceptions);
22 if (
dos == NULL)
throw ExeException(
"Could not wrap PECore: invalid DOS Header!");
24 offset =
dos->e_lfanew +
sizeof(DWORD);
25 this->
fHdr = (IMAGE_FILE_HEADER*)
buf->
getContentAt(offset,
sizeof(IMAGE_FILE_HEADER), allowExceptions);
28 offset = offset +
sizeof(IMAGE_FILE_HEADER);
29 WORD *magic = (WORD*)
buf->
getContentAt(offset,
sizeof(WORD), allowExceptions);
30 if (magic == NULL)
throw ExeException(
"Could not wrap PECore: invalid FileHeader");
33 if ((*magic) == pe::OH_NT64) {
38 this->
opt32 = (IMAGE_OPTIONAL_HEADER32*)
buf->
getContentAt(offset,
sizeof(IMAGE_OPTIONAL_HEADER32), allowExceptions);
41 this->
opt64 = (IMAGE_OPTIONAL_HEADER64*)
buf->
getContentAt(offset,
sizeof(IMAGE_OPTIONAL_HEADER64), allowExceptions);
43 if ( this->
opt32 == NULL && this->
opt64 == NULL) {
44 throw ExeException(
"Could not wrap PECore : invalid OptionalHeader");
68 const offset_t signSize =
sizeof(DWORD);
69 return offset + signSize;
78 return offset +
sizeof(IMAGE_FILE_HEADER);
84 return sizeof(IMAGE_NT_HEADERS64);
86 return sizeof(IMAGE_NT_HEADERS32);
106 return opt32->SectionAlignment;
110 return opt64->SectionAlignment;
119 imgSize =
opt32->SizeOfImage;
122 imgSize =
opt64->SizeOfImage;
131 hdrsSize =
opt32->SizeOfHeaders;
134 hdrsSize =
opt64->SizeOfHeaders;
143 imgBase =
opt32->ImageBase;
146 imgBase =
opt64->ImageBase;
158 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)
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