-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunc.cpp
More file actions
executable file
·112 lines (96 loc) · 2.9 KB
/
func.cpp
File metadata and controls
executable file
·112 lines (96 loc) · 2.9 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
104
105
106
107
108
109
110
111
112
#include "func.h"
#include "Utilities.h"
Function::Function(std::string n, addr_t a, size_t l, std::string m) {
name = n;
address = a;
size = l;
module = m;
cfg = new Cfg(this);
argumentsno = -1;
pending = false;
prog = NULL;
}
Function::Function(addr_t a) {
argumentsno = -1;
cfg = new Cfg(this);
address = a;
name = "unknown";
module = "unknown";
pending = false;
prog = NULL;
}
Function::~Function() {
delete cfg;
}
const char *Function::getName() const {
return name.c_str();
}
const char *Function::getModule() const {
return module.c_str();
}
addr_t Function::getAddress() const {
return address;
}
size_t Function::getSize() const {
return size;
}
Cfg *Function::getCfg() {
return cfg;
}
// Scan the instructions to detect the number of arguments (assume the
// framepointer is not used as a general purpose register,
// -fno-omit-frame-pointer)
void Function::guessArgumentsNo() {
cfg->decode();
for (Cfg::const_bb_iterator bbit = cfg->bb_begin();
bbit != cfg->bb_end(); bbit++) {
for (instructions_t::const_iterator iit = (*bbit)->inst_begin();
iit != (*bbit)->inst_end(); iit++) {
std::string tempebp;
for (statements_t::const_iterator sit = (*iit)->stmt_begin();
sit != (*iit)->stmt_end(); sit++) {
vine::Stmt *s = *sit;
if (s->stmt_type == vine::MOVE) {
vine::Exp *lhs = static_cast<vine::Move *>(s)->lhs, *rhs = static_cast<vine::Move *>(s)->rhs;
if (lhs->exp_type == vine::TEMP && rhs->exp_type == vine::TEMP) {
vine::Temp *t0 = static_cast<vine::Temp *>(lhs), *t1 = static_cast<vine::Temp *>(rhs);
// debug("%.8x %s\n", (*iit)->getAddress(), s->tostring().c_str());
if (t1->name == "R_EBP") {
tempebp = t0->name;
// debug("EBP copied into %s\n", tempebp.c_str());
}
} else if (lhs->exp_type == vine::TEMP && rhs->exp_type == vine::BINOP) {
vine::BinOp *op = static_cast<vine::BinOp *>(rhs);
if (op->binop_type == vine::PLUS && op->lhs->exp_type == vine::TEMP &&
op->rhs->exp_type == vine::CONSTANT) {
vine::Temp *base = static_cast<vine::Temp *>(op->lhs);
vine::Constant *offset = static_cast<vine::Constant *>(op->rhs);
if (base->name == tempebp) {
// debug("%.8x %s\n", (*iit)->getAddress(), s->tostring().c_str());
if (offset->val > 0 && offset->val < 0xFFFF) {
// debug("EBP is being used in an addition %.8x\n", (unsigned int) (offset->val & 0xFFFF));
argumentsno = utils::max(argumentsno, ((int)
(offset->val & 0xFFFF)) / 4);
}
}
}
}
}
}
}
}
if (argumentsno == -1)
argumentsno = 0;
else
argumentsno--;
}
int Function::getArgumentsNo() {
if (argumentsno == -1) {
guessArgumentsNo();
}
return argumentsno;
}
// Local Variables:
// c-basic-offset: 4
// compile-command: "dchroot -c typeinfer -d make"
// End: