-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathreconstruct.cpp
More file actions
104 lines (83 loc) · 2.05 KB
/
reconstruct.cpp
File metadata and controls
104 lines (83 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <list>
#include <loader.h>
#include <disasm.h>
#include <cfg.h>
#include <options.h>
extern "C" {
#include "backend.h"
}
struct options options;
/* convert our backend format to their backend format */
static int backend_object_to_Binary(Binary& bin, backend_object *obj)
{
bin.filename = std::string("Unknown");
bin.entry = backend_get_entry_point(obj);
bin.type_str = std::string("Unknown");
switch(backend_get_type(obj))
{
case OBJECT_TYPE_NONE:
break;
case OBJECT_TYPE_PE32:
case OBJECT_TYPE_PE_ROM:
case OBJECT_TYPE_PE32PLUS:
bin.type = Binary::BIN_TYPE_PE;
break;
case OBJECT_TYPE_ELF32:
case OBJECT_TYPE_ELF64:
bin.type = Binary::BIN_TYPE_ELF;
break;
}
switch(backend_get_arch(obj))
{
case OBJECT_ARCH_UNKNOWN:
bin.arch = Binary::ARCH_NONE;
bin.bits = 0;
break;
case OBJECT_ARCH_ARM:
bin.arch = Binary::ARCH_ARM;
bin.bits = 32;
break;
case OBJECT_ARCH_ARM64:
bin.arch = Binary::ARCH_AARCH64;
bin.bits = 64;
break;
case OBJECT_ARCH_X86:
bin.arch = Binary::ARCH_X86;
bin.bits = 64;
break;
case OBJECT_ARCH_MIPS:
bin.arch = Binary::ARCH_MIPS;
bin.bits = 64;
break;
case OBJECT_ARCH_PPC:
bin.arch = Binary::ARCH_PPC;
bin.bits = 64;
break;
}
return 0;
}
/* reconstruct the symbol table by using the Nucleus algorithm */
extern "C" int nucleus_reconstruct_symbols(backend_object *obj)
{
Binary bin;
std::list<DisasmSection> disasm;
CFG cfg;
options.verbosity = 0;
options.warnings = 1;
options.only_code_sections = 1;
options.allow_privileged = 0;
options.summarize_functions = 0;
options.binary.type = Binary::BIN_TYPE_AUTO;
options.binary.arch = Binary::ARCH_NONE;
options.binary.base_vma = 0;
options.strategy_function.score_function = NULL;
options.strategy_function.mutate_function = NULL;
options.strategy_function.select_function = NULL;
backend_object_to_Binary(bin, obj);
if (nucleus_disasm(&bin, &disasm) < 0)
return 1;
if (cfg.make_cfg(&bin, &disasm) < 0)
return 1;
cfg.print_functions(stdout);
return 0;
}