BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
parser
pe
DataDirEntryWrapper.cpp
Go to the documentation of this file.
1
#include "
pe/DataDirEntryWrapper.h
"
2
#include "
pe/PEFile.h
"
3
4
DataDirEntryWrapper::DataDirEntryWrapper
(
PEFile
* pe, pe:: dir_entry v_entryType)
5
:
PENodeWrapper
(pe), entryType(v_entryType)
6
{
7
wrap
();
8
}
9
10
IMAGE_DATA_DIRECTORY*
DataDirEntryWrapper::getDataDirectory
()
11
{
12
13
if
(
m_PE
== NULL)
return
NULL;
14
15
IMAGE_DATA_DIRECTORY *d =
m_PE
->
getDataDirectory
();
16
return
d;
17
}
18
19
offset_t
DataDirEntryWrapper::getDirEntryAddress
()
20
{
21
DataDirWrapper
*dDir =
dynamic_cast<
DataDirWrapper
*
>
(
m_PE
->
getWrapper
(
PEFile::WR_DATADIR
));
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
33
bufsize_t
DataDirEntryWrapper::getDirEntrySize
(
bool
trimToExeSize)
34
{
35
DataDirWrapper
*dDir =
dynamic_cast<
DataDirWrapper
*
>
(
m_PE
->
getWrapper
(
PEFile::WR_DATADIR
));
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
}
bufsize_t
uint32_t bufsize_t
Definition
AbstractByteBuffer.h:14
INVALID_ADDR
const offset_t INVALID_ADDR
Definition
AbstractByteBuffer.h:18
offset_t
uint64_t offset_t
Definition
AbstractByteBuffer.h:17
DataDirEntryWrapper.h
PEFile.h
DataDirEntryWrapper::getDirEntrySize
bufsize_t getDirEntrySize(bool trimToExeSize=false)
Definition
DataDirEntryWrapper.cpp:33
DataDirEntryWrapper::getDirEntryAddress
offset_t getDirEntryAddress()
Definition
DataDirEntryWrapper.cpp:19
DataDirEntryWrapper::entryType
int entryType
Definition
DataDirEntryWrapper.h:20
DataDirEntryWrapper::DataDirEntryWrapper
DataDirEntryWrapper(PEFile *pe, pe::dir_entry v_entryType)
Definition
DataDirEntryWrapper.cpp:4
DataDirEntryWrapper::getDataDirectory
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition
DataDirEntryWrapper.cpp:10
DataDirWrapper
Definition
DataDirWrapper.h:6
DataDirWrapper::getDirsCount
size_t getDirsCount()
Definition
DataDirWrapper.cpp:21
ExeElementWrapper::m_Exe
Executable * m_Exe
Definition
ExeElementWrapper.h:65
ExeNodeWrapper::wrap
virtual bool wrap()
Definition
ExeNodeWrapper.h:16
ExeWrappersContainer::getWrapper
virtual ExeElementWrapper * getWrapper(size_t wrapperId)
Definition
MappedExe.cpp:13
Executable::rvaToRaw
virtual offset_t rvaToRaw(offset_t rva)=0
Executable::getContentSize
virtual bufsize_t getContentSize()
Definition
Executable.h:59
PEFile
Definition
PEFile.h:45
PEFile::WR_DATADIR
@ WR_DATADIR
Definition
PEFile.h:53
PEFile::getDataDirectory
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition
PEFile.cpp:292
PENodeWrapper
Definition
PENodeWrapper.h:25
PENodeWrapper::m_PE
PEFile * m_PE
Definition
PENodeWrapper.h:36
Generated by
1.12.0