3#define DEFAULT_IMGBASE 0x10000
21 bool allowExceptions =
true;
26 this->
dos = (IMAGE_DOS_HEADER*)
buf->
getContentAt(offset,
sizeof(IMAGE_DOS_HEADER), allowExceptions);
27 if (
dos == NULL)
throw ExeException(
"Could not wrap PECore: invalid DOS Header!");
29 offset =
dos->e_lfanew +
sizeof(DWORD);
30 this->
fHdr = (IMAGE_FILE_HEADER*)
buf->
getContentAt(offset,
sizeof(IMAGE_FILE_HEADER), allowExceptions);
34 offset = offset +
sizeof(IMAGE_FILE_HEADER);
35 WORD *magic = (WORD*)
buf->
getContentAt(offset,
sizeof(WORD), allowExceptions);
36 if (magic == NULL)
throw ExeException(
"Could not wrap PECore: invalid FileHeader");
39 if ((*magic) == pe::OH_NT64) {
44 this->
opt32 = (IMAGE_OPTIONAL_HEADER32*)
buf->
getContentAt(offset,
sizeof(IMAGE_OPTIONAL_HEADER32), allowExceptions);
47 this->
opt64 = (IMAGE_OPTIONAL_HEADER64*)
buf->
getContentAt(offset,
sizeof(IMAGE_OPTIONAL_HEADER64), allowExceptions);
49 if ( this->
opt32 == NULL && this->
opt64 == NULL) {
50 throw ExeException(
"Could not wrap PECore : invalid OptionalHeader");
103 return opt32->SectionAlignment;
107 return opt64->SectionAlignment;
116 imgSize =
opt32->SizeOfImage;
119 imgSize =
opt64->SizeOfImage;
128 hdrsSize =
opt32->SizeOfHeaders;
131 hdrsSize =
opt64->SizeOfHeaders;
140 imgBase =
opt32->ImageBase;
143 imgBase =
opt64->ImageBase;
155 if (maxOffset >= 0x80000000) {
const offset_t INVALID_ADDR
virtual BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
Executable::exe_bits getHdrBitMode()
virtual bufsize_t getAlignment(Executable::addr_type aType)
offset_t peSignatureOffset()
IMAGE_OPTIONAL_HEADER32 * opt32
bool wrap(AbstractByteBuffer *v_buf)
virtual offset_t getImageBase()
virtual bufsize_t getImageSize()
offset_t peOptHdrOffset()
offset_t peFileHdrOffset()
IMAGE_OPTIONAL_HEADER64 * opt64