BearParser
Portable Executable parsing library (from PE-bear)
Toggle main menu visibility
Loading...
Searching...
No Matches
parser
ExeFactory.cpp
Go to the documentation of this file.
1
#include "
ExeFactory.h
"
2
3
#include "
pe/DOSExe.h
"
4
#include "
pe/PEFile.h
"
5
6
std::map<ExeFactory::exe_type, ExeBuilder*>
ExeFactory::builders
;
7
8
void
ExeFactory::init
()
9
{
10
if
(
builders
.size() > 0) {
11
return
;
// already initialized
12
}
13
builders
[
MZ
] =
new
DOSExeBuilder
();
14
builders
[
PE
] =
new
PEFileBuilder
();
15
}
16
17
void
ExeFactory::destroy
()
18
{
19
std::map<exe_type, ExeBuilder*>::iterator itr;
20
for
(itr =
builders
.begin(); itr !=
builders
.end(); ++itr) {
21
ExeBuilder
* builder = itr->second;
22
delete
builder;
23
}
24
builders
.clear();
25
}
26
27
ExeFactory::exe_type
ExeFactory::findMatching
(
AbstractByteBuffer
*buf)
28
{
29
if
(!buf)
return
NONE
;
30
31
ExeFactory::init
();
//ensue that the builders are initialized
32
33
std::map<exe_type, ExeBuilder*>::iterator itr;
34
for
(itr =
builders
.begin(); itr !=
builders
.end(); ++itr) {
35
36
ExeBuilder
* builder = itr->second;
37
if
(builder == NULL)
continue
;
38
39
if
(builder->
signatureMatches
(buf)) {
40
return
itr->first;
41
}
42
}
43
return
NONE
;
44
}
45
46
Executable
*
ExeFactory::build
(
AbstractByteBuffer
*buf,
exe_type
type)
47
{
48
ExeFactory::init
();
//ensue that the builders are initialized
49
50
if
(
builders
.find(type) ==
builders
.end()) {
51
return
NULL;
52
}
53
ExeBuilder
* builder =
builders
[type];
54
if
(!builder)
return
NULL;
55
56
return
builder->
build
(buf);
57
}
58
59
QString
ExeFactory::getTypeName
(
exe_type
type)
60
{
61
ExeFactory::init
();
//ensue that the builders are initialized
62
63
if
(
builders
.find(type) ==
builders
.end())
return
"Not supported"
;
64
65
ExeBuilder
* builder =
builders
[type];
66
if
(builder == NULL)
return
"Not supported"
;
67
68
return
builder->
typeName
();
69
}
DOSExe.h
ExeFactory.h
PEFile.h
AbstractByteBuffer
Definition
AbstractByteBuffer.h:36
DOSExeBuilder
Definition
DOSExe.h:8
ExeBuilder
Definition
Executable.h:14
ExeBuilder::build
virtual Executable * build(AbstractByteBuffer *buf)=0
ExeBuilder::signatureMatches
virtual bool signatureMatches(AbstractByteBuffer *buf)=0
ExeBuilder::typeName
virtual QString typeName()=0
ExeFactory::findMatching
static exe_type findMatching(AbstractByteBuffer *buf)
Definition
ExeFactory.cpp:27
ExeFactory::builders
static std::map< exe_type, ExeBuilder * > builders
Definition
ExeFactory.h:29
ExeFactory::destroy
static void destroy()
Definition
ExeFactory.cpp:17
ExeFactory::build
static Executable * build(AbstractByteBuffer *buf, exe_type type)
Definition
ExeFactory.cpp:46
ExeFactory::init
static void init()
Definition
ExeFactory.cpp:8
ExeFactory::getTypeName
static QString getTypeName(exe_type type)
Definition
ExeFactory.cpp:59
ExeFactory::exe_type
exe_type
Definition
ExeFactory.h:14
ExeFactory::MZ
@ MZ
Definition
ExeFactory.h:17
ExeFactory::PE
@ PE
Definition
ExeFactory.h:16
ExeFactory::NONE
@ NONE
Definition
ExeFactory.h:15
Executable
Definition
Executable.h:26
PEFileBuilder
Definition
PEFile.h:34
Generated by
1.17.0