Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
stp.py
Go to the documentation of this file.
2 
3 
4 """
5 Quick implementation of miasm traduction to stp langage
6 TODO XXX: finish
7 """
8 
9 
10 def ExprInt_strcst(self):
11  b = bin(int(self.arg))[2::][::-1]
12  b += "0" * self.size
13  b = b[:self.size][::-1]
14  return "0bin" + b
15 
16 
17 def ExprId_strcst(self):
18  return self.name
19 
20 
21 def genop(op, size, a, b):
22  return op + '(' + str(size) + ',' + a + ', ' + b + ')'
23 
24 
25 def genop_nosize(op, size, a, b):
26  return op + '(' + a + ', ' + b + ')'
27 
28 
29 def ExprOp_strcst(self):
30  op = self.op
31  op_dct = {"|": " | ",
32  "&": " & "}
33  if op in op_dct:
34  return '(' + op_dct[op].join([x.strcst() for x in self.args]) + ')'
35  op_dct = {"-": "BVUMINUS"}
36  if op in op_dct:
37  return op_dct[op] + '(' + self.args[0].strcst() + ')'
38  op_dct = {"^": ("BVXOR", genop_nosize),
39  "+": ("BVPLUS", genop)}
40  if not op in op_dct:
41  raise ValueError('implement op', op)
42  op, f = op_dct[op]
43  args = [x.strcst() for x in self.args][::-1]
44  a = args.pop()
45  b = args.pop()
46  size = self.args[0].size
47  out = f(op, size, a, b)
48  while args:
49  out = f(op, size, out, args.pop())
50  return out
51 
52 
53 def ExprSlice_strcst(self):
54  return '(' + self.arg.strcst() + ')[%d:%d]' % (self.stop - 1, self.start)
55 
56 
57 def ExprCond_strcst(self):
58  cond = self.cond.strcst()
59  src1 = self.src1.strcst()
60  src2 = self.src2.strcst()
61  return "(IF %s=(%s) THEN %s ELSE %s ENDIF)" % (
62  "0bin%s" % ('0' * self.cond.size), cond, src2, src1)
63 
64 ExprInt.strcst = ExprInt_strcst
65 ExprId.strcst = ExprId_strcst
66 ExprOp.strcst = ExprOp_strcst
67 ExprCond.strcst = ExprCond_strcst
68 ExprSlice.strcst = ExprSlice_strcst
def ExprInt_strcst
Definition: stp.py:10
def ExprSlice_strcst
Definition: stp.py:53
def ExprCond_strcst
Definition: stp.py:57