BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
PECore.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Executable.h"
4#include "pe_formats.h"
5
6//class for internal use of PEFile
7class PECore
8{
9public:
10
12 : buf(NULL), dos(NULL), fHdr(NULL), opt32(NULL), opt64(NULL) {}
13
14 virtual ~PECore()
15 {
16 reset();
17 }
18
19 bool wrap(AbstractByteBuffer *v_buf);
20
21 virtual offset_t getRawSize() const { return static_cast<offset_t>(buf->getContentSize()); }
22
23 virtual bufsize_t getAlignment(Executable::addr_type aType) const;
24 virtual offset_t getImageBase(bool recalculate = false);
25 virtual bufsize_t getImageSize();
26
31 offset_t secHdrsOffset() const;
34 bufsize_t hdrsSize() const;
35
36 void setImageSize(bufsize_t newSize)
37 {
38 if (opt32) {
39 this->opt32->SizeOfImage = newSize;
40 }
41 else if (opt64) {
42 this->opt64->SizeOfImage = newSize;
43 }
44 }
45
46 IMAGE_FILE_HEADER *getFileHeader() const
47 {
48 return fHdr;
49 }
50
51protected:
52 void reset();
54
55 IMAGE_DOS_HEADER *dos;
56 IMAGE_FILE_HEADER* fHdr;
57 IMAGE_OPTIONAL_HEADER32* opt32;
58 IMAGE_OPTIONAL_HEADER64* opt64;
59
60friend class PEFile;
61};
62
uint32_t bufsize_t
uint64_t offset_t
virtual bufsize_t getContentSize()=0
Definition PECore.h:8
Executable::exe_arch getHdrArch() const
Definition PECore.cpp:59
virtual ~PECore()
Definition PECore.h:14
virtual bufsize_t getAlignment(Executable::addr_type aType) const
Definition PECore.cpp:119
bufsize_t hdrsSize() const
Definition PECore.cpp:144
offset_t peOptHdrOffset() const
Definition PECore.cpp:89
IMAGE_OPTIONAL_HEADER32 * opt32
Definition PECore.h:57
bool wrap(AbstractByteBuffer *v_buf)
Definition PECore.cpp:13
virtual offset_t getImageBase(bool recalculate=false)
Definition PECore.cpp:156
offset_t peFileHdrOffset() const
Definition PECore.cpp:79
AbstractByteBuffer * buf
Definition PECore.h:53
void reset()
Definition PECore.cpp:5
virtual bufsize_t getImageSize()
Definition PECore.cpp:132
IMAGE_FILE_HEADER * getFileHeader() const
Definition PECore.h:46
PECore()
Definition PECore.h:11
offset_t peSignatureOffset() const
Definition PECore.cpp:73
IMAGE_FILE_HEADER * fHdr
Definition PECore.h:56
bufsize_t peNtHeadersSize() const
Definition PECore.cpp:98
virtual offset_t getRawSize() const
Definition PECore.h:21
offset_t secHdrsOffset() const
Definition PECore.cpp:106
IMAGE_OPTIONAL_HEADER64 * opt64
Definition PECore.h:58
Executable::exe_bits getHdrBitMode() const
Definition PECore.cpp:51
void setImageSize(bufsize_t newSize)
Definition PECore.h:36
IMAGE_DOS_HEADER * dos
Definition PECore.h:55