Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Functions | Variables
miasm2.expression.simplifications_cond Namespace Reference

Functions

def __ExprOp_cond
 
def ExprOp_inf_signed
 
def ExprOp_inf_unsigned
 
def ExprOp_equal
 
def __check_msb
 
def __MatchExprWrap
 
def expr_simp_inf_signed
 
def expr_simp_inf_unsigned_inversed
 
def expr_simp_inverse
 
def expr_simp_equal
 
def exec_inf_unsigned
 
def __comp_signed
 
def exec_inf_signed
 
def exec_equal
 

Variables

tuple jok1 = m2_expr.ExprId("jok1")
 
tuple jok2 = m2_expr.ExprId("jok2")
 
tuple jok3 = m2_expr.ExprId("jok3")
 
tuple jok_small = m2_expr.ExprId("jok_small", 1)
 

Function Documentation

def miasm2.expression.simplifications_cond.__check_msb (   e)
private
If @e stand for the most significant bit of its arg, return the arg;
False otherwise

Definition at line 52 of file simplifications_cond.py.

52 
53 def __check_msb(e):
54  """If @e stand for the most significant bit of its arg, return the arg;
55  False otherwise"""
56 
57  if not isinstance(e, m2_expr.ExprSlice):
58  return False
59 
60  arg = e.arg
61  if e.start != (arg.size - 1) or e.stop != arg.size:
62  return False
63 
64  return arg

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.__comp_signed (   arg1,
  arg2 
)
private
Return ExprInt1(1) if arg1 <s arg2 else ExprInt1(0)
@arg1, @arg2: ExprInt

Definition at line 196 of file simplifications_cond.py.

197 def __comp_signed(arg1, arg2):
198  """Return ExprInt1(1) if arg1 <s arg2 else ExprInt1(0)
199  @arg1, @arg2: ExprInt"""
200 
201  val1 = arg1.arg
202  if val1 >> (arg1.size - 1) == 1:
203  val1 = - (arg1.mask.arg ^ val1 + 1)
204 
205  val2 = arg2.arg
206  if val2 >> (arg2.size - 1) == 1:
207  val2 = - (arg2.mask.arg ^ val2 + 1)
208 
209  return m2_expr.ExprInt1(1) if (val1 < val2) else m2_expr.ExprInt1(0)

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.__ExprOp_cond (   op,
  arg1,
  arg2 
)
private

Definition at line 30 of file simplifications_cond.py.

30 
31 def __ExprOp_cond(op, arg1, arg2):
32  "Return an ExprOp standing for arg1 op arg2 with size to 1"
33  ec = m2_expr.ExprOp(op, arg1, arg2)
34  return ec
35 

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.__MatchExprWrap (   e,
  to_match,
  jok_list 
)
private

Definition at line 65 of file simplifications_cond.py.

65 
66 def __MatchExprWrap(e, to_match, jok_list):
67  "Wrapper around MatchExpr to canonize pattern"
68 
69  to_match = to_match.canonize()
70 
71  r = m2_expr.MatchExpr(e, to_match, jok_list)
72  if r is False:
73  return False
74 
75  if r == {}:
76  return False
77 
78  return r

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.exec_equal (   expr_simp,
  e 
)

Definition at line 223 of file simplifications_cond.py.

224 def exec_equal(expr_simp, e):
225  "Compute x == y"
226 
227  if e.op != m2_expr.TOK_EQUAL:
228  return e
229 
230  arg1, arg2 = e.args
231  if isinstance(arg1, m2_expr.ExprInt) and isinstance(arg2, m2_expr.ExprInt):
232  return m2_expr.ExprInt1(1) if (arg1.arg == arg2.arg) else m2_expr.ExprInt1(0)
233  else:
234  return e
def miasm2.expression.simplifications_cond.exec_inf_signed (   expr_simp,
  e 
)

Definition at line 210 of file simplifications_cond.py.

211 def exec_inf_signed(expr_simp, e):
212  "Compute x <s y"
213 
214  if e.op != m2_expr.TOK_INF_SIGNED:
215  return e
216 
217  arg1, arg2 = e.args
218 
219  if isinstance(arg1, m2_expr.ExprInt) and isinstance(arg2, m2_expr.ExprInt):
220  return __comp_signed(arg1, arg2)
221  else:
222  return e

+ Here is the call graph for this function:

def miasm2.expression.simplifications_cond.exec_inf_unsigned (   expr_simp,
  e 
)

Definition at line 183 of file simplifications_cond.py.

184 def exec_inf_unsigned(expr_simp, e):
185  "Compute x <u y"
186  if e.op != m2_expr.TOK_INF_UNSIGNED:
187  return e
188 
189  arg1, arg2 = e.args
190 
191  if isinstance(arg1, m2_expr.ExprInt) and isinstance(arg2, m2_expr.ExprInt):
192  return m2_expr.ExprInt1(1) if (arg1.arg < arg2.arg) else m2_expr.ExprInt1(0)
193  else:
194  return e
195 
def miasm2.expression.simplifications_cond.expr_simp_equal (   expr_simp,
  e 
)
(x - y)?(0:1) == (x == y)

Definition at line 169 of file simplifications_cond.py.

170 def expr_simp_equal(expr_simp, e):
171  """(x - y)?(0:1) == (x == y)"""
172 
173  to_match = m2_expr.ExprCond(jok1 + jok2, m2_expr.ExprInt1(0), m2_expr.ExprInt1(1))
174  r = __MatchExprWrap(e,
175  to_match,
176  [jok1, jok2])
177  if r is False:
178  return e
179 
180  return ExprOp_equal(r[jok1], expr_simp(-r[jok2]))
181 
182 # Compute conditions

+ Here is the call graph for this function:

def miasm2.expression.simplifications_cond.expr_simp_inf_signed (   expr_simp,
  e 
)

Definition at line 79 of file simplifications_cond.py.

79 
80 def expr_simp_inf_signed(expr_simp, e):
81  "((x - y) ^ ((x ^ y) & ((x - y) ^ x))) [31:32] == x <s y"
82 
83  arg = __check_msb(e)
84  if arg is False:
85  return e
86 
87  # We want jok3 = jok1 - jok2
88  to_match = jok3 ^ ((jok1 ^ jok2) & (jok3 ^ jok1))
89  r = __MatchExprWrap(arg,
90  to_match,
91  [jok1, jok2, jok3])
92 
93  if r is False:
94  return e
95 
96  new_j3 = expr_simp(r[jok3])
97  sub = expr_simp(r[jok1] - r[jok2])
98 
99  if new_j3 == sub:
100  return ExprOp_inf_signed(r[jok1], r[jok2])
101  else:
102  return e

+ Here is the call graph for this function:

def miasm2.expression.simplifications_cond.expr_simp_inf_unsigned_inversed (   expr_simp,
  e 
)

Definition at line 103 of file simplifications_cond.py.

104 def expr_simp_inf_unsigned_inversed(expr_simp, e):
105  "((x - y) ^ ((x ^ y) & ((x - y) ^ x))) ^ x ^ y [31:32] == x <u y"
106 
107  arg = __check_msb(e)
108  if arg is False:
109  return e
110 
111  # We want jok3 = jok1 - jok2
112  to_match = jok3 ^ ((jok1 ^ jok2) & (jok3 ^ jok1)) ^ jok1 ^ jok2
113  r = __MatchExprWrap(arg,
114  to_match,
115  [jok1, jok2, jok3])
116 
117  if r is False:
118  return e
119 
120  new_j3 = expr_simp(r[jok3])
121  sub = expr_simp(r[jok1] - r[jok2])
122 
123  if new_j3 == sub:
124  return ExprOp_inf_unsigned(r[jok1], r[jok2])
125  else:
126  return e

+ Here is the call graph for this function:

def miasm2.expression.simplifications_cond.expr_simp_inverse (   expr_simp,
  e 
)
(x <u y) ^ ((x ^ y) [31:32]) == x <s y,
(x <s y) ^ ((x ^ y) [31:32]) == x <u y

Definition at line 127 of file simplifications_cond.py.

128 def expr_simp_inverse(expr_simp, e):
129  """(x <u y) ^ ((x ^ y) [31:32]) == x <s y,
130  (x <s y) ^ ((x ^ y) [31:32]) == x <u y"""
131 
132  to_match = (ExprOp_inf_unsigned(jok1, jok2) ^ jok_small)
133  r = __MatchExprWrap(e,
134  to_match,
135  [jok1, jok2, jok_small])
136 
137  # Check for 2 symetric cases
138  if r is False:
139  to_match = (ExprOp_inf_signed(jok1, jok2) ^ jok_small)
140  r = __MatchExprWrap(e,
141  to_match,
142  [jok1, jok2, jok_small])
143 
144  if r is False:
145  return e
146  cur_sig = m2_expr.TOK_INF_SIGNED
147  else:
148  cur_sig = m2_expr.TOK_INF_UNSIGNED
149 
150 
151  arg = __check_msb(r[jok_small])
152  if arg is False:
153  return e
154 
155  if not isinstance(arg, m2_expr.ExprOp) or arg.op != "^":
156  return e
157 
158  op_args = arg.args
159  if len(op_args) != 2:
160  return e
161 
162  if r[jok1] not in op_args or r[jok2] not in op_args:
163  return e
164 
165  if cur_sig == m2_expr.TOK_INF_UNSIGNED:
166  return ExprOp_inf_signed(r[jok1], r[jok2])
167  else:
168  return ExprOp_inf_unsigned(r[jok1], r[jok2])

+ Here is the call graph for this function:

def miasm2.expression.simplifications_cond.ExprOp_equal (   arg1,
  arg2 
)

Definition at line 45 of file simplifications_cond.py.

45 
46 def ExprOp_equal(arg1, arg2):
47  "Return an ExprOp standing for arg1 == arg2"
48  return __ExprOp_cond(m2_expr.TOK_EQUAL, arg1, arg2)
49 
50 
51 # Catching conditions forms

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.ExprOp_inf_signed (   arg1,
  arg2 
)

Definition at line 36 of file simplifications_cond.py.

36 
37 def ExprOp_inf_signed(arg1, arg2):
38  "Return an ExprOp standing for arg1 <s arg2"
39  return __ExprOp_cond(m2_expr.TOK_INF_SIGNED, arg1, arg2)
40 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.expression.simplifications_cond.ExprOp_inf_unsigned (   arg1,
  arg2 
)

Definition at line 41 of file simplifications_cond.py.

41 
42 def ExprOp_inf_unsigned(arg1, arg2):
43  "Return an ExprOp standing for arg1 <s arg2"
44  return __ExprOp_cond(m2_expr.TOK_INF_UNSIGNED, arg1, arg2)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

tuple miasm2.expression.simplifications_cond.jok1 = m2_expr.ExprId("jok1")

Definition at line 22 of file simplifications_cond.py.

tuple miasm2.expression.simplifications_cond.jok2 = m2_expr.ExprId("jok2")

Definition at line 23 of file simplifications_cond.py.

tuple miasm2.expression.simplifications_cond.jok3 = m2_expr.ExprId("jok3")

Definition at line 24 of file simplifications_cond.py.

tuple miasm2.expression.simplifications_cond.jok_small = m2_expr.ExprId("jok_small", 1)

Definition at line 25 of file simplifications_cond.py.