BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
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
6std::map<ExeFactory::exe_type, ExeBuilder*> ExeFactory::builders;
7
9{
10 if (builders.size() > 0) {
11 return; // already initialized
12 }
13 builders[MZ] = new DOSExeBuilder();
14 builders[PE] = new PEFileBuilder();
15}
16
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
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
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
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}
virtual Executable * build(AbstractByteBuffer *buf)=0
virtual bool signatureMatches(AbstractByteBuffer *buf)=0
virtual QString typeName()=0
static exe_type findMatching(AbstractByteBuffer *buf)
static std::map< exe_type, ExeBuilder * > builders
Definition ExeFactory.h:29
static void destroy()
static Executable * build(AbstractByteBuffer *buf, exe_type type)
static void init()
Definition ExeFactory.cpp:8
static QString getTypeName(exe_type type)