-
Notifications
You must be signed in to change notification settings - Fork 192
/
oomethod.cpp
137 lines (111 loc) · 2.57 KB
/
oomethod.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2017-2018 Carnegie Mellon University. See LICENSE file for terms.
#include "oomethod.hpp"
#include "descriptors.hpp"
namespace pharos {
OOMethod::OOMethod(const FunctionDescriptor* fd) {
function_ = fd;
import_ = nullptr;
address_ = fd->get_address();
name_ = "";
type_ = OOMethodType::UNKN;
is_virtual_ = false;
}
OOMethod::OOMethod(const ImportDescriptor* id) {
function_ = nullptr;
import_ = id;
address_ = id->get_address();
type_ = OOMethodType::UNKN;
is_virtual_ = false;
function_ = id->get_function_descriptor();
// ejs: If the import is an ordinal, we do want to note that. But all the naming functions
// (i.e., get_best_name) that handle ordinals also include the DLL name, which we do not
// normally want for non-ordinals.
if (id->is_name_valid())
set_name(id->get_name());
else if (id->get_ordinal() != 0)
set_name(id->get_best_name());
else {
GWARN << "Unsure how to name imported method " << address_ << " " << id->get_best_name() << LEND;
set_name(id->get_name());
}
}
void
OOMethod::generate_name() {
std::stringstream name_ss;
if (type_ == OOMethodType::CTOR) {
name_ss << "ctor_";
}
else {
name_ss << ((is_virtual_) ? "virt_" : "");
if (type_ == OOMethodType::DTOR) {
name_ss << "dtor_";
}
else if (type_ == OOMethodType::DELDTOR) {
name_ss << "deldtor_";
}
else {
name_ss << "meth_";
}
}
name_ss << "0x" << std::hex << address_ << std::dec;
std::string s = name_ss.str();
set_name(s);
}
void
OOMethod::set_name(std::string n) {
name_ = n;
}
std::string
OOMethod::get_name() {
if (name_ == "") generate_name();
return name_;
}
const FunctionDescriptor*
OOMethod::get_function_descriptor() {
return function_;
}
void
OOMethod::set_function_descriptor(const FunctionDescriptor* fd) {
function_ = fd;
}
const ImportDescriptor*
OOMethod::get_import_descriptor() {
return import_;
}
void
OOMethod::set_import_descriptor(const ImportDescriptor* id) {
import_ = id;
}
rose_addr_t
OOMethod::get_address() const {
return address_;
}
bool
OOMethod::is_import() const {
return (import_ != nullptr);
}
bool
OOMethod::is_constructor() const {
return (type_ == OOMethodType::CTOR);
}
bool
OOMethod::is_destructor() const {
return (type_ == OOMethodType::DTOR);
}
bool
OOMethod::is_deleting_destructor() const {
return (type_ == OOMethodType::DELDTOR);
}
void
OOMethod::set_type(OOMethodType new_type) {
type_ = new_type;
}
bool
OOMethod::is_virtual() const {
return is_virtual_;
}
void
OOMethod::set_virtual(bool v) {
is_virtual_ = v;
}
}