BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
DataDirEntryWrapper.cpp
Go to the documentation of this file.
2#include "pe/PEFile.h"
3
4DataDirEntryWrapper::DataDirEntryWrapper(PEFile* pe, pe:: dir_entry v_entryType)
5 : PENodeWrapper(pe), entryType(v_entryType)
6{
7 wrap();
8}
9
11{
12
13 if (m_PE == NULL) return NULL;
14
15 IMAGE_DATA_DIRECTORY *d = m_PE->getDataDirectory();
16 return d;
17}
18
20{
22 const size_t recordsCount = dDir ? dDir->getDirsCount() : 0;
23 if (this->entryType >= recordsCount) return INVALID_ADDR;
24
25 IMAGE_DATA_DIRECTORY *d = getDataDirectory();
26 if (!d) return INVALID_ADDR;
27
28 offset_t rva = static_cast<offset_t>(d[this->entryType].VirtualAddress);
29 if (rva == 0) return INVALID_ADDR;
30 return rva;
31}
32
34{
36 const size_t recordsCount = dDir ? dDir->getDirsCount() : 0;
37 if (this->entryType >= recordsCount) return 0;
38
39 IMAGE_DATA_DIRECTORY *d = getDataDirectory();
40 if (!d) return 0;
41
42 bufsize_t dirSize = static_cast<bufsize_t>(d[this->entryType].Size);
43 if (!trimToExeSize) {
44 return dirSize;
45 }
46
47 if (!this->m_Exe) return 0; // should never happen
48
49 offset_t dirRva = d[this->entryType].VirtualAddress;
50 offset_t dirRaw = this->m_Exe->rvaToRaw(dirRva);
51 if (dirRaw == INVALID_ADDR) {
52 return 0;
53 }
54 bufsize_t fullSize = this->m_Exe->getContentSize();
55 bufsize_t remainingSize = bufsize_t(fullSize - dirRaw);
56
57 return (dirSize < remainingSize) ? dirSize : remainingSize;
58}
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
bufsize_t getDirEntrySize(bool trimToExeSize=false)
offset_t getDirEntryAddress()
int entryType
DataDirEntryWrapper(PEFile *pe, pe::dir_entry v_entryType)
IMAGE_DATA_DIRECTORY * getDataDirectory()
virtual bool wrap()
virtual ExeElementWrapper * getWrapper(size_t wrapperId)
Definition MappedExe.cpp:13
virtual offset_t rvaToRaw(offset_t rva)=0
virtual bufsize_t getContentSize()
Definition Executable.h:59
@ WR_DATADIR
Definition PEFile.h:53
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition PEFile.cpp:292