pyvex 3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRConst/__init__.py +154 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRConst/__init__.pyc +0 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRExpr/__init__.py +281 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRExpr/__init__.pyc +0 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRStmt/__init__.py +265 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/IRStmt/__init__.pyc +0 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/__init__.py +228 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/__init__.pyc +0 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/vex_ffi.py +1356 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex/vex_ffi.pyc +0 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex-3.0-py2.7.egg-info/PKG-INFO +10 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex-3.0-py2.7.egg-info/SOURCES.txt +11 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex-3.0-py2.7.egg-info/dependency_links.txt +1 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex-3.0-py2.7.egg-info/requires.txt +2 -0
- home/yans/.virtualenvs/t1/lib/python2.7/site-packages/pyvex-3.0-py2.7.egg-info/top_level.txt +1 -0
- home/yans/.virtualenvs/t1/lib/pyvex_static.so +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from .. import VEXObject
|
|
2
|
+
|
|
3
|
+
# IRConst heirarchy
|
|
4
|
+
class IRConst(VEXObject):
|
|
5
|
+
type = None
|
|
6
|
+
|
|
7
|
+
def __init__(self, c_expr):
|
|
8
|
+
VEXObject.__init__(self)
|
|
9
|
+
self.tag = ints_to_enums[c_expr.tag]
|
|
10
|
+
|
|
11
|
+
def pp(self):
|
|
12
|
+
print self.__str__()
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def size(self):
|
|
16
|
+
return type_sizes[self.type]
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def _translate(c_expr):
|
|
20
|
+
if c_expr[0] == ffi.NULL:
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
tag = c_expr.tag
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
return tag_to_class[tag](c_expr)
|
|
27
|
+
except KeyError:
|
|
28
|
+
raise PyVEXError('Unknown/unsupported IRExprTag %s\n' % ints_to_enums[tag])
|
|
29
|
+
|
|
30
|
+
class U1(IRConst):
|
|
31
|
+
type = 'Ity_I1'
|
|
32
|
+
|
|
33
|
+
def __init__(self, c_expr):
|
|
34
|
+
IRConst.__init__(self, c_expr)
|
|
35
|
+
self.value = c_expr.Ico.U1
|
|
36
|
+
|
|
37
|
+
def __str__(self):
|
|
38
|
+
return "%d" % self.value
|
|
39
|
+
|
|
40
|
+
class U8(IRConst):
|
|
41
|
+
type = 'Ity_I8'
|
|
42
|
+
|
|
43
|
+
def __init__(self, c_expr):
|
|
44
|
+
IRConst.__init__(self, c_expr)
|
|
45
|
+
self.value = c_expr.Ico.U8
|
|
46
|
+
|
|
47
|
+
def __str__(self):
|
|
48
|
+
return "0x%02x" % self.value
|
|
49
|
+
|
|
50
|
+
class U16(IRConst):
|
|
51
|
+
type = 'Ity_I16'
|
|
52
|
+
|
|
53
|
+
def __init__(self, c_expr):
|
|
54
|
+
IRConst.__init__(self, c_expr)
|
|
55
|
+
self.value = c_expr.Ico.U16
|
|
56
|
+
|
|
57
|
+
def __str__(self):
|
|
58
|
+
return "0x%04x" % self.value
|
|
59
|
+
|
|
60
|
+
class U32(IRConst):
|
|
61
|
+
type = 'Ity_I32'
|
|
62
|
+
|
|
63
|
+
def __init__(self, c_expr):
|
|
64
|
+
IRConst.__init__(self, c_expr)
|
|
65
|
+
self.value = c_expr.Ico.U32
|
|
66
|
+
|
|
67
|
+
def __str__(self):
|
|
68
|
+
return "0x%08x" % self.value
|
|
69
|
+
|
|
70
|
+
class U64(IRConst):
|
|
71
|
+
type = 'Ity_I64'
|
|
72
|
+
|
|
73
|
+
def __init__(self, c_expr):
|
|
74
|
+
IRConst.__init__(self, c_expr)
|
|
75
|
+
self.value = c_expr.Ico.U64
|
|
76
|
+
|
|
77
|
+
def __str__(self):
|
|
78
|
+
return "0x%016x" % self.value
|
|
79
|
+
|
|
80
|
+
class F32(IRConst):
|
|
81
|
+
type = 'Ity_F32'
|
|
82
|
+
|
|
83
|
+
def __init__(self, c_expr):
|
|
84
|
+
IRConst.__init__(self, c_expr)
|
|
85
|
+
self.value = c_expr.Ico.F32
|
|
86
|
+
|
|
87
|
+
def __str__(self):
|
|
88
|
+
return "%f" % self.value
|
|
89
|
+
|
|
90
|
+
class F32i(IRConst):
|
|
91
|
+
type = 'Ity_F32'
|
|
92
|
+
|
|
93
|
+
def __init__(self, c_expr):
|
|
94
|
+
IRConst.__init__(self, c_expr)
|
|
95
|
+
self.value = c_expr.Ico.F32i
|
|
96
|
+
|
|
97
|
+
def __str__(self):
|
|
98
|
+
return "%f" % self.value
|
|
99
|
+
|
|
100
|
+
class F64(IRConst):
|
|
101
|
+
type = 'Ity_F64'
|
|
102
|
+
|
|
103
|
+
def __init__(self, c_expr):
|
|
104
|
+
IRConst.__init__(self, c_expr)
|
|
105
|
+
self.value = c_expr.Ico.F64
|
|
106
|
+
|
|
107
|
+
def __str__(self):
|
|
108
|
+
return "%f" % self.value
|
|
109
|
+
|
|
110
|
+
class F64i(IRConst):
|
|
111
|
+
type = 'Ity_F64'
|
|
112
|
+
|
|
113
|
+
def __init__(self, c_expr):
|
|
114
|
+
IRConst.__init__(self, c_expr)
|
|
115
|
+
self.value = c_expr.Ico.F64i
|
|
116
|
+
|
|
117
|
+
def __str__(self):
|
|
118
|
+
return "%f" % self.value
|
|
119
|
+
|
|
120
|
+
class V128(IRConst):
|
|
121
|
+
type = 'Ity_V128'
|
|
122
|
+
|
|
123
|
+
def __init__(self, c_expr):
|
|
124
|
+
IRConst.__init__(self, c_expr)
|
|
125
|
+
self.value = c_expr.Ico.V128
|
|
126
|
+
|
|
127
|
+
def __str__(self):
|
|
128
|
+
return "%x" % self.value
|
|
129
|
+
|
|
130
|
+
class V256(IRConst):
|
|
131
|
+
type = 'Ity_V256'
|
|
132
|
+
|
|
133
|
+
def __init__(self, c_expr):
|
|
134
|
+
IRConst.__init__(self, c_expr)
|
|
135
|
+
self.value = c_expr.Ico.V256
|
|
136
|
+
|
|
137
|
+
def __str__(self):
|
|
138
|
+
return "%x" % self.value
|
|
139
|
+
|
|
140
|
+
from .. import ints_to_enums, enums_to_ints, PyVEXError, ffi, type_sizes
|
|
141
|
+
|
|
142
|
+
tag_to_class = {
|
|
143
|
+
enums_to_ints['Ico_U1']: U1,
|
|
144
|
+
enums_to_ints['Ico_U8']: U8,
|
|
145
|
+
enums_to_ints['Ico_U16']: U16,
|
|
146
|
+
enums_to_ints['Ico_U32']: U32,
|
|
147
|
+
enums_to_ints['Ico_U64']: U64,
|
|
148
|
+
enums_to_ints['Ico_F32']: F32,
|
|
149
|
+
enums_to_ints['Ico_F32i']: F32i,
|
|
150
|
+
enums_to_ints['Ico_F64']: F64,
|
|
151
|
+
enums_to_ints['Ico_F64i']: F64i,
|
|
152
|
+
enums_to_ints['Ico_V128']: V128,
|
|
153
|
+
enums_to_ints['Ico_V256']: V256,
|
|
154
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
from .. import VEXObject
|
|
2
|
+
|
|
3
|
+
# IRExpr heirarchy
|
|
4
|
+
class IRExpr(VEXObject):
|
|
5
|
+
def __init__(self, c_expr, irsb):
|
|
6
|
+
VEXObject.__init__(self)
|
|
7
|
+
self.tag = ints_to_enums[c_expr.tag]
|
|
8
|
+
#self.c_expr = c_expr
|
|
9
|
+
self.arch = irsb.arch
|
|
10
|
+
|
|
11
|
+
if isinstance(self, (VECRET, Binder, BBPTR)):
|
|
12
|
+
self.result_type = 'Ity_INVALID'
|
|
13
|
+
else:
|
|
14
|
+
self.result_type = ints_to_enums[pvc.typeOfIRExpr(irsb.c_irsb.tyenv, c_expr)]
|
|
15
|
+
self.result_size = type_sizes[self.result_type]
|
|
16
|
+
|
|
17
|
+
def pp(self):
|
|
18
|
+
print self.__str__()
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def child_expressions(self):
|
|
22
|
+
'''
|
|
23
|
+
A list of all of the expressions that this expression ends up evaluating.
|
|
24
|
+
'''
|
|
25
|
+
expressions = [ ]
|
|
26
|
+
for _,v in self.__dict__.iteritems():
|
|
27
|
+
if isinstance(v, IRExpr):
|
|
28
|
+
expressions.append(v)
|
|
29
|
+
expressions.extend(v.child_expressions)
|
|
30
|
+
return expressions
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def constants(self):
|
|
34
|
+
'''
|
|
35
|
+
A list of all of the constants that this expression ends up using.
|
|
36
|
+
'''
|
|
37
|
+
constants = [ ]
|
|
38
|
+
for _,v in self.__dict__.iteritems():
|
|
39
|
+
if isinstance(v, IRExpr):
|
|
40
|
+
constants.extend(v.constants)
|
|
41
|
+
elif isinstance(v, IRConst):
|
|
42
|
+
constants.append(v)
|
|
43
|
+
return constants
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def _translate(c_expr, irsb):
|
|
47
|
+
if c_expr[0] == ffi.NULL:
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
tag = c_expr.tag
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
expr_class = tag_to_class[tag]
|
|
54
|
+
except KeyError:
|
|
55
|
+
raise PyVEXError('Unknown/unsupported IRExprTag %s\n' % ints_to_enums[tag])
|
|
56
|
+
return expr_class(c_expr, irsb)
|
|
57
|
+
|
|
58
|
+
class Binder(IRExpr):
|
|
59
|
+
def __init__(self, c_expr, irsb):
|
|
60
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
61
|
+
self.binder = c_expr.iex.Binder.binder
|
|
62
|
+
|
|
63
|
+
def __str__(self):
|
|
64
|
+
return "Binder"
|
|
65
|
+
|
|
66
|
+
class VECRET(IRExpr):
|
|
67
|
+
def __init__(self, c_expr, irsb):
|
|
68
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
69
|
+
|
|
70
|
+
def __str__(self):
|
|
71
|
+
return "VECRET"
|
|
72
|
+
|
|
73
|
+
class BBPTR(IRExpr):
|
|
74
|
+
def __init__(self, c_expr, irsb):
|
|
75
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
76
|
+
self.result_type = 'Ity_INVALID'
|
|
77
|
+
self.result_size = 0
|
|
78
|
+
|
|
79
|
+
def __str__(self):
|
|
80
|
+
return "BBPTR"
|
|
81
|
+
|
|
82
|
+
class GetI(IRExpr):
|
|
83
|
+
def __init__(self, c_expr, irsb):
|
|
84
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
85
|
+
self.descr = IRRegArray(c_expr.Iex.GetI.descr)
|
|
86
|
+
self.ix = IRExpr._translate(c_expr.Iex.GetI.ix, irsb)
|
|
87
|
+
self.bias = c_expr.Iex.GetI.bias
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def description(self):
|
|
91
|
+
return self.descr
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def index(self):
|
|
95
|
+
return self.ix
|
|
96
|
+
|
|
97
|
+
def __str__(self):
|
|
98
|
+
return "GetI(%s)[%s,%s]" % (self.descr, self.ix, self.bias)
|
|
99
|
+
|
|
100
|
+
class RdTmp(IRExpr):
|
|
101
|
+
def __init__(self, c_expr, irsb):
|
|
102
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
103
|
+
self.tmp = c_expr.Iex.RdTmp.tmp
|
|
104
|
+
|
|
105
|
+
def __str__(self):
|
|
106
|
+
return "t%d" % self.tmp
|
|
107
|
+
|
|
108
|
+
class Get(IRExpr):
|
|
109
|
+
def __init__(self, c_expr, irsb):
|
|
110
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
111
|
+
self.offset = c_expr.Iex.Get.offset
|
|
112
|
+
self.ty = ints_to_enums[c_expr.Iex.Get.ty]
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def type(self):
|
|
116
|
+
return self.ty
|
|
117
|
+
|
|
118
|
+
def __str__(self):
|
|
119
|
+
return "GET:%s(%s)" % (self.ty[4:], self.arch.translate_register_name(self.offset))
|
|
120
|
+
|
|
121
|
+
class Qop(IRExpr):
|
|
122
|
+
def __init__(self, c_expr, irsb):
|
|
123
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
124
|
+
self.op = ints_to_enums[c_expr.Iex.Qop.details.op]
|
|
125
|
+
self.args = (
|
|
126
|
+
IRExpr._translate(c_expr.Iex.Qop.details.arg1, irsb),
|
|
127
|
+
IRExpr._translate(c_expr.Iex.Qop.details.arg2, irsb),
|
|
128
|
+
IRExpr._translate(c_expr.Iex.Qop.details.arg3, irsb),
|
|
129
|
+
IRExpr._translate(c_expr.Iex.Qop.details.arg4, irsb),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def __str__(self):
|
|
133
|
+
return "%s(%s)" % (self.op[4:], ','.join(str(a) for a in self.args))
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def child_expressions(self):
|
|
137
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
138
|
+
expressions.extend(self.args)
|
|
139
|
+
return expressions
|
|
140
|
+
|
|
141
|
+
class Triop(IRExpr):
|
|
142
|
+
def __init__(self, c_expr, irsb):
|
|
143
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
144
|
+
self.op = ints_to_enums[c_expr.Iex.Triop.details.op]
|
|
145
|
+
self.args = (
|
|
146
|
+
IRExpr._translate(c_expr.Iex.Triop.details.arg1, irsb),
|
|
147
|
+
IRExpr._translate(c_expr.Iex.Triop.details.arg2, irsb),
|
|
148
|
+
IRExpr._translate(c_expr.Iex.Triop.details.arg3, irsb),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def __str__(self):
|
|
152
|
+
return "%s(%s)" % (self.op[4:], ','.join(str(a) for a in self.args))
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def child_expressions(self):
|
|
156
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
157
|
+
expressions.extend(self.args)
|
|
158
|
+
return expressions
|
|
159
|
+
|
|
160
|
+
class Binop(IRExpr):
|
|
161
|
+
def __init__(self, c_expr, irsb):
|
|
162
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
163
|
+
self.op = ints_to_enums[c_expr.Iex.Binop.op]
|
|
164
|
+
self.args = (
|
|
165
|
+
IRExpr._translate(c_expr.Iex.Binop.arg1, irsb),
|
|
166
|
+
IRExpr._translate(c_expr.Iex.Binop.arg2, irsb),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
def __str__(self):
|
|
170
|
+
return "%s(%s)" % (self.op[4:], ','.join(str(a) for a in self.args))
|
|
171
|
+
|
|
172
|
+
@property
|
|
173
|
+
def child_expressions(self):
|
|
174
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
175
|
+
expressions.extend(self.args)
|
|
176
|
+
return expressions
|
|
177
|
+
|
|
178
|
+
class Unop(IRExpr):
|
|
179
|
+
def __init__(self, c_expr, irsb):
|
|
180
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
181
|
+
self.op = ints_to_enums[c_expr.Iex.Unop.op]
|
|
182
|
+
self.args = (
|
|
183
|
+
IRExpr._translate(c_expr.Iex.Unop.arg, irsb),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def __str__(self):
|
|
187
|
+
return "%s(%s)" % (self.op[4:], ','.join(str(a) for a in self.args))
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def child_expressions(self):
|
|
191
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
192
|
+
expressions.extend(self.args)
|
|
193
|
+
return expressions
|
|
194
|
+
|
|
195
|
+
class Load(IRExpr):
|
|
196
|
+
def __init__(self, c_expr, irsb):
|
|
197
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
198
|
+
self.end = ints_to_enums[c_expr.Iex.Load.end]
|
|
199
|
+
self.ty = ints_to_enums[c_expr.Iex.Load.ty]
|
|
200
|
+
self.addr = IRExpr._translate(c_expr.Iex.Load.addr, irsb)
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def endness(self):
|
|
204
|
+
return self.end
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def type(self):
|
|
208
|
+
return self.ty
|
|
209
|
+
|
|
210
|
+
def __str__(self):
|
|
211
|
+
return "LD%s:%s(%s)" % (self.end[-2:].lower(), self.ty[4:], self.addr)
|
|
212
|
+
|
|
213
|
+
class Const(IRExpr):
|
|
214
|
+
def __init__(self, c_expr, irsb):
|
|
215
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
216
|
+
self.con = IRConst._translate(c_expr.Iex.Const.con)
|
|
217
|
+
|
|
218
|
+
def __str__(self):
|
|
219
|
+
return str(self.con)
|
|
220
|
+
|
|
221
|
+
class ITE(IRExpr):
|
|
222
|
+
def __init__(self, c_expr, irsb):
|
|
223
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
224
|
+
self.cond = IRExpr._translate(c_expr.Iex.ITE.cond, irsb)
|
|
225
|
+
self.iffalse = IRExpr._translate(c_expr.Iex.ITE.iffalse, irsb)
|
|
226
|
+
self.iftrue = IRExpr._translate(c_expr.Iex.ITE.iftrue, irsb)
|
|
227
|
+
|
|
228
|
+
def __str__(self):
|
|
229
|
+
return "ITE(%s,%s,%s)" % (self.cond, self.iftrue, self.iffalse)
|
|
230
|
+
|
|
231
|
+
class CCall(IRExpr):
|
|
232
|
+
def __init__(self, c_expr, irsb):
|
|
233
|
+
IRExpr.__init__(self, c_expr, irsb)
|
|
234
|
+
self.retty = ints_to_enums[c_expr.Iex.CCall.retty]
|
|
235
|
+
self.cee = IRCallee(c_expr.Iex.CCall.cee)
|
|
236
|
+
|
|
237
|
+
self.args = [ ]
|
|
238
|
+
for i in range(20):
|
|
239
|
+
a = c_expr.Iex.CCall.args[i]
|
|
240
|
+
if a == ffi.NULL:
|
|
241
|
+
break
|
|
242
|
+
|
|
243
|
+
self.args.append(IRExpr._translate(a, irsb))
|
|
244
|
+
self.args = tuple(self.args)
|
|
245
|
+
|
|
246
|
+
@property
|
|
247
|
+
def ret_type(self):
|
|
248
|
+
return self.retty
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def callee(self):
|
|
252
|
+
return self.cee
|
|
253
|
+
|
|
254
|
+
def __str__(self):
|
|
255
|
+
return "%s(%s):%s" % (self.cee, ','.join(str(a) for a in self.args), self.retty)
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def child_expressions(self):
|
|
259
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
260
|
+
expressions.extend(self.args)
|
|
261
|
+
return expressions
|
|
262
|
+
|
|
263
|
+
from ..IRConst import IRConst
|
|
264
|
+
from .. import IRCallee, IRRegArray, enums_to_ints, ints_to_enums, PyVEXError, ffi, pvc, type_sizes
|
|
265
|
+
|
|
266
|
+
tag_to_class = {
|
|
267
|
+
enums_to_ints['Iex_Binder']: Binder,
|
|
268
|
+
enums_to_ints['Iex_Get']: Get,
|
|
269
|
+
enums_to_ints['Iex_GetI']: GetI,
|
|
270
|
+
enums_to_ints['Iex_RdTmp']: RdTmp,
|
|
271
|
+
enums_to_ints['Iex_Qop']: Qop,
|
|
272
|
+
enums_to_ints['Iex_Triop']: Triop,
|
|
273
|
+
enums_to_ints['Iex_Binop']: Binop,
|
|
274
|
+
enums_to_ints['Iex_Unop']: Unop,
|
|
275
|
+
enums_to_ints['Iex_Load']: Load,
|
|
276
|
+
enums_to_ints['Iex_Const']: Const,
|
|
277
|
+
enums_to_ints['Iex_ITE']: ITE,
|
|
278
|
+
enums_to_ints['Iex_CCall']: CCall,
|
|
279
|
+
enums_to_ints['Iex_BBPTR']: BBPTR,
|
|
280
|
+
enums_to_ints['Iex_VECRET']: VECRET,
|
|
281
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
from .. import VEXObject
|
|
2
|
+
|
|
3
|
+
# IRStmt heirarchy
|
|
4
|
+
class IRStmt(VEXObject):
|
|
5
|
+
def __init__(self, c_stmt, irsb):
|
|
6
|
+
VEXObject.__init__(self)
|
|
7
|
+
self.arch = irsb.arch
|
|
8
|
+
#self.c_stmt = c_stmt
|
|
9
|
+
self.tag = ints_to_enums[c_stmt.tag]
|
|
10
|
+
|
|
11
|
+
def pp(self):
|
|
12
|
+
print self.__str__()
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def expressions(self):
|
|
16
|
+
expressions = [ ]
|
|
17
|
+
for _,v in self.__dict__.iteritems():
|
|
18
|
+
if isinstance(v, IRExpr):
|
|
19
|
+
expressions.append(v)
|
|
20
|
+
expressions.extend(v.child_expressions)
|
|
21
|
+
return expressions
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def constants(self):
|
|
25
|
+
return sum((e.constants for e in self.expressions), [ ])
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _translate(c_stmt, irsb):
|
|
29
|
+
if c_stmt[0] == ffi.NULL:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
tag = c_stmt.tag
|
|
33
|
+
try:
|
|
34
|
+
stmt_class = _tag_to_class[tag]
|
|
35
|
+
except KeyError:
|
|
36
|
+
raise PyVEXError('Unknown/unsupported IRStmtTag %s\n' % ints_to_enums[tag])
|
|
37
|
+
return stmt_class(c_stmt, irsb)
|
|
38
|
+
|
|
39
|
+
class NoOp(IRStmt):
|
|
40
|
+
def __init__(self, c_stmt, irsb): #pylint:disable=unused-argument
|
|
41
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
42
|
+
|
|
43
|
+
def __str__(self):
|
|
44
|
+
return "IR-NoOp"
|
|
45
|
+
|
|
46
|
+
class IMark(IRStmt):
|
|
47
|
+
def __init__(self, c_stmt, irsb):
|
|
48
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
49
|
+
self.addr = c_stmt.Ist.IMark.addr
|
|
50
|
+
self.len = c_stmt.Ist.IMark.len
|
|
51
|
+
self.delta = c_stmt.Ist.IMark.delta
|
|
52
|
+
|
|
53
|
+
def __str__(self):
|
|
54
|
+
return "------ IMark(0x%x, %d, %d) ------" % (self.addr, self.len, self.delta)
|
|
55
|
+
|
|
56
|
+
class AbiHint(IRStmt):
|
|
57
|
+
def __init__(self, c_stmt, irsb):
|
|
58
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
59
|
+
self.base = IRExpr._translate(c_stmt.Ist.AbiHint.base, irsb)
|
|
60
|
+
self.len = c_stmt.Ist.AbiHint.len
|
|
61
|
+
self.nia = IRExpr._translate(c_stmt.Ist.AbiHint.nia, irsb)
|
|
62
|
+
|
|
63
|
+
def __str__(self):
|
|
64
|
+
return "====== AbiHint(0x%s, %d, %s) ======" % (self.base, self.len, self.nia)
|
|
65
|
+
|
|
66
|
+
class Put(IRStmt):
|
|
67
|
+
def __init__(self, c_stmt, irsb):
|
|
68
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
69
|
+
self.data = IRExpr._translate(c_stmt.Ist.Put.data, irsb)
|
|
70
|
+
self.offset = c_stmt.Ist.Put.offset
|
|
71
|
+
|
|
72
|
+
def __str__(self):
|
|
73
|
+
return "PUT(%s) = %s" % (self.arch.translate_register_name(self.offset), self.data)
|
|
74
|
+
|
|
75
|
+
class PutI(IRStmt):
|
|
76
|
+
def __init__(self, c_stmt, irsb):
|
|
77
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
78
|
+
self.descr = IRRegArray(c_stmt.Ist.PutI.details.descr)
|
|
79
|
+
self.ix = IRExpr._translate(c_stmt.Ist.PutI.details.ix, irsb)
|
|
80
|
+
self.data = IRExpr._translate(c_stmt.Ist.PutI.details.data, irsb)
|
|
81
|
+
self.bias = c_stmt.Ist.PutI.details.bias
|
|
82
|
+
|
|
83
|
+
def __str__(self):
|
|
84
|
+
return "PutI(%s)[%s,%d] = %s" % (self.descr, self.ix, self.bias, self.data)
|
|
85
|
+
|
|
86
|
+
class WrTmp(IRStmt):
|
|
87
|
+
def __init__(self, c_stmt, irsb):
|
|
88
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
89
|
+
|
|
90
|
+
self.data = IRExpr._translate(c_stmt.Ist.WrTmp.data, irsb)
|
|
91
|
+
self.tmp = c_stmt.Ist.WrTmp.tmp
|
|
92
|
+
|
|
93
|
+
def __str__(self):
|
|
94
|
+
return "t%d = %s" % (self.tmp, self.data)
|
|
95
|
+
|
|
96
|
+
class Store(IRStmt):
|
|
97
|
+
def __init__(self, c_stmt, irsb):
|
|
98
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
99
|
+
|
|
100
|
+
self.addr = IRExpr._translate(c_stmt.Ist.Store.addr, irsb)
|
|
101
|
+
self.data = IRExpr._translate(c_stmt.Ist.Store.data, irsb)
|
|
102
|
+
self.end = ints_to_enums[c_stmt.Ist.Store.end]
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def endness(self):
|
|
106
|
+
return self.end
|
|
107
|
+
|
|
108
|
+
def __str__(self):
|
|
109
|
+
return "ST%s(%s) = %s" % (self.endness[-2:].lower(), self.addr, self.data)
|
|
110
|
+
|
|
111
|
+
class CAS(IRStmt):
|
|
112
|
+
def __init__(self, c_stmt, irsb):
|
|
113
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
114
|
+
|
|
115
|
+
self.addr = IRExpr._translate(c_stmt.Ist.CAS.details.addr, irsb)
|
|
116
|
+
self.dataLo = IRExpr._translate(c_stmt.Ist.CAS.details.dataLo, irsb)
|
|
117
|
+
self.dataHi = IRExpr._translate(c_stmt.Ist.CAS.details.dataHi, irsb)
|
|
118
|
+
self.expdLo = IRExpr._translate(c_stmt.Ist.CAS.details.expdLo, irsb)
|
|
119
|
+
self.expdHi = IRExpr._translate(c_stmt.Ist.CAS.details.expdHi, irsb)
|
|
120
|
+
self.oldLo = c_stmt.Ist.CAS.details.oldLo
|
|
121
|
+
self.oldHi = c_stmt.Ist.CAS.details.oldHi
|
|
122
|
+
self.end = ints_to_enums[c_stmt.Ist.CAS.details.end]
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def endness(self):
|
|
126
|
+
return self.end
|
|
127
|
+
|
|
128
|
+
def __str__(self):
|
|
129
|
+
return "t(%s,%s) = CAS%s(%s :: (%s,%s)->(%s,%s))" % (self.oldLo, self.oldHi, self.end[-2:].lower(), self.addr, self.expdLo, self.expdHi, self.dataLo, self.dataHi)
|
|
130
|
+
|
|
131
|
+
class LLSC(IRStmt):
|
|
132
|
+
def __init__(self, c_stmt, irsb):
|
|
133
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
134
|
+
|
|
135
|
+
self.addr = IRExpr._translate(c_stmt.Ist.LLSC.addr, irsb)
|
|
136
|
+
self.storedata = IRExpr._translate(c_stmt.Ist.LLSC.storedata, irsb)
|
|
137
|
+
self.result = c_stmt.Ist.LLSC.result
|
|
138
|
+
self.end = ints_to_enums[c_stmt.Ist.LLSC.end]
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def endness(self):
|
|
142
|
+
return self.end
|
|
143
|
+
|
|
144
|
+
def __str__(self):
|
|
145
|
+
if self.storedata is None:
|
|
146
|
+
return "result = LD%s-Linked(%s)" % (self.end[-2:].lower(), self.addr)
|
|
147
|
+
else:
|
|
148
|
+
return "result = ( ST%s-Cond(%s) = %s )" % (self.end[-2:].lower(), self.addr, self.storedata)
|
|
149
|
+
|
|
150
|
+
class MBE(IRStmt):
|
|
151
|
+
def __init__(self, c_stmt, irsb):
|
|
152
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
153
|
+
self.event = ints_to_enums[c_stmt.Ist.MBE.event]
|
|
154
|
+
|
|
155
|
+
def __str__(self):
|
|
156
|
+
return "MBusEvent-" + self.event
|
|
157
|
+
|
|
158
|
+
class Dirty(IRStmt):
|
|
159
|
+
def __init__(self, c_stmt, irsb):
|
|
160
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
161
|
+
self.cee = IRCallee(c_stmt.Ist.Dirty.details.cee)
|
|
162
|
+
self.guard = IRExpr._translate(c_stmt.Ist.Dirty.details.guard, irsb)
|
|
163
|
+
self.tmp = c_stmt.Ist.Dirty.details.tmp
|
|
164
|
+
self.mFx = ints_to_enums[c_stmt.Ist.Dirty.details.mFx]
|
|
165
|
+
self.mAddr = IRExpr._translate(c_stmt.Ist.Dirty.details.mAddr, irsb)
|
|
166
|
+
self.mSize = c_stmt.Ist.Dirty.details.mSize
|
|
167
|
+
self.nFxState = c_stmt.Ist.Dirty.details.nFxState
|
|
168
|
+
|
|
169
|
+
self.args = [ ]
|
|
170
|
+
for i in range(20):
|
|
171
|
+
a = c_stmt.Ist.Dirty.details.args[i]
|
|
172
|
+
if a == ffi.NULL:
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
self.args.append(IRExpr._translate(a, irsb))
|
|
176
|
+
self.args = tuple(self.args)
|
|
177
|
+
|
|
178
|
+
def __str__(self):
|
|
179
|
+
return "t%s = DIRTY %s %s ::: %s(%s)" % (self.tmp, self.guard, "TODO(effects)", self.cee, ','.join(str(a) for a in self.args))
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def child_expressions(self):
|
|
183
|
+
expressions = sum((a.child_expressions for a in self.args), [ ])
|
|
184
|
+
expressions.extend(self.args)
|
|
185
|
+
expressions.append(self.guard)
|
|
186
|
+
expressions.extend(self.guard.child_expressions)
|
|
187
|
+
return expressions
|
|
188
|
+
|
|
189
|
+
class Exit(IRStmt):
|
|
190
|
+
def __init__(self, c_stmt, irsb):
|
|
191
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
192
|
+
self.guard = IRExpr._translate(c_stmt.Ist.Exit.guard, irsb)
|
|
193
|
+
self.dst = IRConst._translate(c_stmt.Ist.Exit.dst)
|
|
194
|
+
self.offsIP = c_stmt.Ist.Exit.offsIP
|
|
195
|
+
self.jk = ints_to_enums[c_stmt.Ist.Exit.jk]
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def jumpkind(self):
|
|
199
|
+
return self.jk
|
|
200
|
+
|
|
201
|
+
def __str__(self):
|
|
202
|
+
return "if (%s) { PUT(%d) = %s; %s }" % (self.guard, self.offsIP, hex(self.dst.value), self.jumpkind)
|
|
203
|
+
|
|
204
|
+
class LoadG(IRStmt):
|
|
205
|
+
def __init__(self, c_stmt, irsb):
|
|
206
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
207
|
+
|
|
208
|
+
self.addr = IRExpr._translate(c_stmt.Ist.LoadG.details.addr, irsb)
|
|
209
|
+
self.alt = IRExpr._translate(c_stmt.Ist.LoadG.details.alt, irsb)
|
|
210
|
+
self.guard = IRExpr._translate(c_stmt.Ist.LoadG.details.guard, irsb)
|
|
211
|
+
self.dst = c_stmt.Ist.LoadG.details.dst
|
|
212
|
+
self.cvt = ints_to_enums[c_stmt.Ist.LoadG.details.cvt]
|
|
213
|
+
|
|
214
|
+
self.end = ints_to_enums[c_stmt.Ist.LoadG.details.end]
|
|
215
|
+
|
|
216
|
+
type_in = ffi.new('IRType *')
|
|
217
|
+
type_out = ffi.new('IRType *')
|
|
218
|
+
pvc.typeOfIRLoadGOp(c_stmt.Ist.LoadG.details.cvt, type_in, type_out)
|
|
219
|
+
type_in = ffi.cast('int *', type_in)[0]
|
|
220
|
+
type_out = ffi.cast('int *', type_out)[0]
|
|
221
|
+
self.cvt_types = (ints_to_enums[type_in], ints_to_enums[type_out])
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def endness(self):
|
|
225
|
+
return self.end
|
|
226
|
+
|
|
227
|
+
def __str__(self):
|
|
228
|
+
return "t%d = if (%s) %s(LD%s(%s)) else %s" % (self.dst, self.guard, self.cvt, self.end[-2:].lower(), self.addr, self.alt)
|
|
229
|
+
|
|
230
|
+
class StoreG(IRStmt):
|
|
231
|
+
def __init__(self, c_stmt, irsb):
|
|
232
|
+
IRStmt.__init__(self, c_stmt, irsb)
|
|
233
|
+
|
|
234
|
+
self.addr = IRExpr._translate(c_stmt.Ist.StoreG.details.addr, irsb)
|
|
235
|
+
self.data = IRExpr._translate(c_stmt.Ist.StoreG.details.data, irsb)
|
|
236
|
+
self.guard = IRExpr._translate(c_stmt.Ist.StoreG.details.guard, irsb)
|
|
237
|
+
self.end = ints_to_enums[c_stmt.Ist.StoreG.details.end]
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def endness(self):
|
|
241
|
+
return self.end
|
|
242
|
+
|
|
243
|
+
def __str__(self):
|
|
244
|
+
return "if (%s) ST%s(%s) = %s" % (self.guard, self.end[-2:].lower(), self.addr, self.data)
|
|
245
|
+
|
|
246
|
+
from ..IRExpr import IRExpr
|
|
247
|
+
from ..IRConst import IRConst
|
|
248
|
+
from .. import IRRegArray, ints_to_enums, enums_to_ints, IRCallee, ffi, pvc, PyVEXError
|
|
249
|
+
|
|
250
|
+
_tag_to_class = {
|
|
251
|
+
enums_to_ints['Ist_NoOp']: NoOp,
|
|
252
|
+
enums_to_ints['Ist_IMark']: IMark,
|
|
253
|
+
enums_to_ints['Ist_AbiHint']: AbiHint,
|
|
254
|
+
enums_to_ints['Ist_Put']: Put,
|
|
255
|
+
enums_to_ints['Ist_PutI']: PutI,
|
|
256
|
+
enums_to_ints['Ist_WrTmp']: WrTmp,
|
|
257
|
+
enums_to_ints['Ist_Store']: Store,
|
|
258
|
+
enums_to_ints['Ist_LoadG']: LoadG,
|
|
259
|
+
enums_to_ints['Ist_StoreG']: StoreG,
|
|
260
|
+
enums_to_ints['Ist_CAS']: CAS,
|
|
261
|
+
enums_to_ints['Ist_LLSC']: LLSC,
|
|
262
|
+
enums_to_ints['Ist_Dirty']: Dirty,
|
|
263
|
+
enums_to_ints['Ist_MBE']: MBE,
|
|
264
|
+
enums_to_ints['Ist_Exit']: Exit,
|
|
265
|
+
}
|