-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.h
166 lines (137 loc) · 3.13 KB
/
colors.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifndef _COLORS_H_
#define _COLORS_H_
#include <assert.h>
#include <Instruction.h>
#include <string>
namespace graphlets {
class Color {
public:
Color() {}
virtual ~Color() {}
virtual unsigned short toint() const { return 0; }
virtual std::string tostr() const { return ""; }
virtual std::string compact() const { return "";}
virtual void merge(Color * /* o */) {}
};
class BranchColor : public Color {
public:
enum branch_color {
JB,
JB_JNAEJ,
JBE,
JCXZ,
JL,
JLE,
JMP,
JNB,
JMPE,
JNB_JAE,
JNBE,
JNL,
JNLE,
JNO,
JNP,
JNS,
JNZ,
JO,
JP,
JS,
JZ,
LOOP,
LOOPE,
LOOPN,
/* 0-22, fitting happily in a byte */
NOBRANCH
};
static branch_color lookup(Dyninst::InstructionAPI::Instruction insn);
BranchColor(unsigned short s)
: s_(s)
{ }
virtual unsigned short toint() const { return s_; }
virtual std::string tostr() const { return std::string("BC"); }
virtual std::string compact() const;
private:
unsigned short s_;
};
class InsnColor : public Color {
public:
enum insn_color {
ARITH,
BRANCH,
CALL,
CMP,
FLAGS,
FLOATING,
HALT,
JUMP,
LEA,
LOGIC,
MOV,
STACK,
STRING,
SYS,
TEST,
// 15 bits
NOCOLOR
};
static insn_color lookup(Dyninst::InstructionAPI::Instruction insn);
static std::map<unsigned short, InsnColor*> insnColorMap;
static InsnColor* ColorLookup(unsigned short);
InsnColor(unsigned short s)
: s_(s)
{ }
virtual unsigned short toint() const { return s_; }
virtual std::string tostr() const { return std::string("IC"); }
virtual void merge(Color * o) {
s_ |= ((InsnColor*)o)->s_;
}
virtual std::string compact() const;
private:
unsigned short s_;
};
#define LOCAL_CALL_NUM ((1<<16)-2)
#define UNKNOWN_LIB_NUM ((1<<16)-1)
class LibCallColor : public Color {
public:
LibCallColor(std::string & name)
: name_(name)
{ }
~LibCallColor() {}
virtual unsigned short toint() const {
assert(!"LibCallColor should not be used as an int");
}
virtual std::string tostr() const {
return name_;
}
virtual void merge(Color * O) {
assert(0);
}
virtual std::string compact() const {
return name_;
}
static std::map<std::string, LibCallColor*> libCallColorMap;
static LibCallColor* ColorLookup(std::string&);
private:
std::string name_;
};
class LocalCallColor : public Color {
public:
LocalCallColor() { }
~LocalCallColor() {}
virtual unsigned short toint() const {
return LOCAL_CALL_NUM;
}
virtual std::string tostr() const {
return "LOCAL";
}
virtual void merge(Color * O) {
assert(0);
}
virtual std::string compact() const {
return "LOCAL";
}
static LocalCallColor localCallColor;
static LocalCallColor* ColorLookup();
};
}
#endif