-
Notifications
You must be signed in to change notification settings - Fork 47
/
ins_movsx_op.cpp
244 lines (210 loc) · 7.3 KB
/
ins_movsx_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
#include "ins_movsx_op.h"
#include "ins_helper.h"
#include "ins_xfer_op.h"
/* threads context */
extern thread_ctx_t *threads_ctx;
/*
* tag propagation (analysis function)
*
* propagate and extend tag between a 16-bit
* register and an 8-bit register as t[dst] = t[upper(src)]
*
* NOTE: special case for MOVSX instruction
*
* @thread_ctx: the thread context
* @dst: destination register index (VCPU)
* @src: source register index (VCPU)
*/
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opwb_u(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][1];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
rtag_dst[0] = src_tag;
rtag_dst[1] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opwb_l(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][0];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
rtag_dst[0] = src_tag;
rtag_dst[1] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_oplb_u(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][1];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 4; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_oplb_l(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][0];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 4; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opqb_u(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][1];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opqb_l(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag value */
tag_t src_tag = RTAG[src][0];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_oplw(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag values */
tag_t *rtag_src = RTAG[src];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 4; i++)
rtag_dst[i] = rtag_src[i % 2];
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opqw(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag values */
tag_t *rtag_src = RTAG[src];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = rtag_src[i % 2];
}
static void PIN_FAST_ANALYSIS_CALL _movsx_r2r_opql(THREADID tid, uint32_t dst,
uint32_t src) {
/* temporary tag values */
tag_t *rtag_src = RTAG[src];
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = rtag_src[i % 4];
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_opwb(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tag = MTAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
rtag_dst[0] = src_tag;
rtag_dst[1] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_oplb(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tag = MTAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 4; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_opqb(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tag = MTAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = src_tag;
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_oplw(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tags[] = M16TAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 4; i++)
rtag_dst[i] = src_tags[i % 2];
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_opqw(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tags[] = M16TAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = src_tags[i % 2];
}
static void PIN_FAST_ANALYSIS_CALL _movsx_m2r_opql(THREADID tid, uint32_t dst,
ADDRINT src) {
/* temporary tag value */
tag_t src_tags[] = M32TAG(src);
tag_t *rtag_dst = RTAG[dst];
/* update the destination (xfer) */
for (size_t i = 0; i < 8; i++)
rtag_dst[i] = src_tags[i % 4];
}
void ins_movsx_op(INS ins) {
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_gr16(reg_dst)) {
if (REG_is_Upper8(reg_src))
R2R_CALL(_movsx_r2r_opwb_u, reg_dst, reg_src);
else
R2R_CALL(_movsx_r2r_opwb_l, reg_dst, reg_src);
} else if (REG_is_gr16(reg_src)) {
if (REG_is_gr64(reg_dst))
R2R_CALL(_movsx_r2r_opqw, reg_dst, reg_src);
else if (REG_is_gr32(reg_dst))
R2R_CALL(_movsx_r2r_oplw, reg_dst, reg_src);
} else if (REG_is_Upper8(reg_src)) {
if (REG_is_gr64(reg_dst))
R2R_CALL(_movsx_r2r_opqb_u, reg_dst, reg_src);
else if (REG_is_gr32(reg_dst))
R2R_CALL(_movsx_r2r_oplb_u, reg_dst, reg_src);
} else { // lower8
if (REG_is_gr64(reg_dst))
R2R_CALL(_movsx_r2r_opqb_l, reg_dst, reg_src);
else if (REG_is_gr32(reg_dst))
R2R_CALL(_movsx_r2r_oplb_l, reg_dst, reg_src);
}
} else {
reg_dst = INS_OperandReg(ins, OP_0);
if (REG_is_gr16(reg_dst)) {
M2R_CALL(_movsx_m2r_opwb, reg_dst);
} else if (INS_MemoryWriteSize(ins) == BIT2BYTE(MEM_WORD_LEN)) {
if (REG_is_gr64(reg_dst)) {
M2R_CALL(_movsx_m2r_opqw, reg_dst);
} else if (REG_is_gr32(reg_dst)) {
M2R_CALL(_movsx_m2r_oplw, reg_dst);
}
} else {
if (REG_is_gr64(reg_dst)) {
M2R_CALL(_movsx_m2r_opqb, reg_dst);
} else if (REG_is_gr32(reg_dst)) {
M2R_CALL(_movsx_m2r_oplb, reg_dst);
}
}
}
}
void ins_movsxd_op(INS ins) {
REG reg_dst, reg_src;
reg_dst = INS_OperandReg(ins, OP_0);
if (!REG_is_gr64(reg_dst)) {
ins_xfer_op(ins);
}
if (INS_MemoryOperandCount(ins) == 0) {
reg_src = INS_OperandReg(ins, OP_1);
R2R_CALL(_movsx_r2r_opql, reg_dst, reg_src);
} else {
M2R_CALL(_movsx_m2r_opql, reg_dst);
}
}