-
Notifications
You must be signed in to change notification settings - Fork 47
/
ins_binary_op.cpp
252 lines (218 loc) · 8.83 KB
/
ins_binary_op.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include "ins_binary_op.h"
#include "ins_helper.h"
/* threads context */
extern thread_ctx_t *threads_ctx;
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opb_ul(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t src_tag = RTAG[src][0];
tag_t dst_tag = RTAG[dst][1];
RTAG[dst][1] = tag_combine(dst_tag, src_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opb_lu(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t src_tag = RTAG[src][1];
tag_t dst_tag = RTAG[dst][0];
RTAG[dst][0] = tag_combine(dst_tag, src_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opb_u(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t src_tag = RTAG[src][1];
tag_t dst_tag = RTAG[dst][1];
RTAG[dst][1] = tag_combine(dst_tag, src_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opb_l(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t src_tag = RTAG[src][0];
tag_t dst_tag = RTAG[dst][0];
RTAG[dst][0] = tag_combine(dst_tag, src_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opw(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 2; i++)
dst_tags[i] = tag_combine(dst_tags[i], src_tags[i]);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opl(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 4; i++)
dst_tags[i] = tag_combine(dst_tags[i], src_tags[i]);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opq(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 8; i++)
dst_tags[i] = tag_combine(dst_tags[i], src_tags[i]);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opx(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 16; i++)
dst_tags[i] = tag_combine(dst_tags[i], src_tags[i]);
}
static void PIN_FAST_ANALYSIS_CALL r2r_binary_opy(THREADID tid, uint32_t dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 32; i++)
dst_tags[i] = tag_combine(dst_tags[i], src_tags[i]);
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opb_u(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t src_tag = MTAG(src);
tag_t dst_tag = RTAG[dst][1];
RTAG[dst][1] = tag_combine(src_tag, dst_tag);
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opb_l(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t src_tag = MTAG(src);
tag_t dst_tag = RTAG[dst][0];
RTAG[dst][0] = tag_combine(src_tag, dst_tag);
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opw(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 2; i++)
dst_tags[i] = tag_combine(dst_tags[i], MTAG(src + i));
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opl(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 4; i++)
dst_tags[i] = tag_combine(dst_tags[i], MTAG(src + i));
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opq(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 8; i++)
dst_tags[i] = tag_combine(dst_tags[i], MTAG(src + i));
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opx(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 16; i++)
dst_tags[i] = tag_combine(dst_tags[i], MTAG(src + i));
}
static void PIN_FAST_ANALYSIS_CALL m2r_binary_opy(THREADID tid, uint32_t dst,
ADDRINT src) {
tag_t *dst_tags = RTAG[dst];
for (size_t i = 0; i < 32; i++)
dst_tags[i] = tag_combine(dst_tags[i], MTAG(src + i));
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opb_u(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t src_tag = RTAG[src][1];
tag_t dst_tag = MTAG(dst);
tag_t res_tag = tag_combine(dst_tag, src_tag);
tagmap_setb(dst, res_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opb_l(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t src_tag = RTAG[src][0];
tag_t dst_tag = MTAG(dst);
tag_t res_tag = tag_combine(dst_tag, src_tag);
tagmap_setb(dst, res_tag);
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opw(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
for (size_t i = 0; i < 2; i++)
tagmap_setb(dst + i, tag_combine(MTAG(dst + i), src_tags[i]));
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opl(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
for (size_t i = 0; i < 4; i++)
tagmap_setb(dst + i, tag_combine(MTAG(dst + i), src_tags[i]));
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opq(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
for (size_t i = 0; i < 8; i++)
tagmap_setb(dst + i, tag_combine(MTAG(dst + i), src_tags[i]));
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opx(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
for (size_t i = 0; i < 16; i++)
tagmap_setb(dst + i, tag_combine(MTAG(dst + i), src_tags[i]));
}
static void PIN_FAST_ANALYSIS_CALL r2m_binary_opy(THREADID tid, ADDRINT dst,
uint32_t src) {
tag_t *src_tags = RTAG[src];
for (size_t i = 0; i < 32; i++)
tagmap_setb(dst + i, tag_combine(MTAG(dst + i), src_tags[i]));
}
void ins_binary_op(INS ins) {
if (INS_OperandIsImmediate(ins, OP_1))
return;
REG reg_dst, reg_src;
if (INS_MemoryOperandCount(ins) == 0) {
reg_dst = INS_OperandReg(ins, OP_0);
reg_src = INS_OperandReg(ins, OP_1);
if (REG_is_gr64(reg_dst)) {
R2R_CALL(r2r_binary_opq, reg_dst, reg_src);
} else if (REG_is_gr32(reg_dst)) {
R2R_CALL(r2r_binary_opl, reg_dst, reg_src);
} else if (REG_is_gr16(reg_dst)) {
R2R_CALL(r2r_binary_opw, reg_dst, reg_src);
} else if (REG_is_xmm(reg_dst)) {
R2R_CALL(r2r_binary_opx, reg_dst, reg_src);
} else if (REG_is_ymm(reg_dst)) {
R2R_CALL(r2r_binary_opy, reg_dst, reg_src);
} else if (REG_is_mm(reg_dst)) {
R2R_CALL(r2r_binary_opq, reg_dst, reg_src);
} else {
if (REG_is_Lower8(reg_dst) && REG_is_Lower8(reg_src))
R2R_CALL(r2r_binary_opb_l, reg_dst, reg_src);
else if (REG_is_Upper8(reg_dst) && REG_is_Upper8(reg_src))
R2R_CALL(r2r_binary_opb_u, reg_dst, reg_src);
else if (REG_is_Lower8(reg_dst))
R2R_CALL(r2r_binary_opb_lu, reg_dst, reg_src);
else
R2R_CALL(r2r_binary_opb_ul, reg_dst, reg_src);
}
} else if (INS_OperandIsMemory(ins, OP_1)) {
reg_dst = INS_OperandReg(ins, OP_0);
if (REG_is_gr64(reg_dst)) {
M2R_CALL(m2r_binary_opq, reg_dst);
} else if (REG_is_gr32(reg_dst)) {
M2R_CALL(m2r_binary_opl, reg_dst);
} else if (REG_is_gr16(reg_dst)) {
M2R_CALL(m2r_binary_opw, reg_dst);
} else if (REG_is_xmm(reg_dst)) {
M2R_CALL(m2r_binary_opx, reg_dst);
} else if (REG_is_ymm(reg_dst)) {
M2R_CALL(m2r_binary_opy, reg_dst);
} else if (REG_is_mm(reg_dst)) {
M2R_CALL(m2r_binary_opq, reg_dst);
} else if (REG_is_Upper8(reg_dst)) {
M2R_CALL(m2r_binary_opb_u, reg_dst);
} else {
M2R_CALL(m2r_binary_opb_l, reg_dst);
}
} else {
reg_src = INS_OperandReg(ins, OP_1);
if (REG_is_gr64(reg_src)) {
R2M_CALL(r2m_binary_opq, reg_src);
} else if (REG_is_gr32(reg_src)) {
R2M_CALL(r2m_binary_opl, reg_src);
} else if (REG_is_gr16(reg_src)) {
R2M_CALL(r2m_binary_opw, reg_src);
} else if (REG_is_xmm(reg_src)) {
R2M_CALL(r2m_binary_opx, reg_src);
} else if (REG_is_ymm(reg_src)) {
R2M_CALL(r2m_binary_opy, reg_src);
} else if (REG_is_mm(reg_src)) {
R2M_CALL(r2m_binary_opq, reg_src);
} else if (REG_is_Upper8(reg_src)) {
R2M_CALL(r2m_binary_opb_u, reg_src);
} else {
R2M_CALL(r2m_binary_opb_l, reg_src);
}
}
}