diff options
| author | Ajax <commial@gmail.com> | 2017-04-21 17:27:01 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2017-04-21 17:27:01 +0200 |
| commit | 18ee3f9f2628c4fd98c46898895fb61021e23e3a (patch) | |
| tree | 9df701aa2354fc2bc2ffa441b4456f8a8ddec9a7 | |
| parent | 7a9ba958c66c80b843bdd571f6989a8bb3e98dce (diff) | |
| download | miasm-18ee3f9f2628c4fd98c46898895fb61021e23e3a.tar.gz miasm-18ee3f9f2628c4fd98c46898895fb61021e23e3a.zip | |
Remove deprecated use of MatchExpr
| -rw-r--r-- | miasm2/analysis/disasm_cb.py | 4 | ||||
| -rw-r--r-- | miasm2/arch/sh4/arch.py | 14 | ||||
| -rw-r--r-- | miasm2/core/graph.py | 2 | ||||
| -rw-r--r-- | miasm2/expression/expression.py | 20 | ||||
| -rw-r--r-- | miasm2/expression/simplifications_cond.py | 21 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 34 |
6 files changed, 47 insertions, 48 deletions
diff --git a/miasm2/analysis/disasm_cb.py b/miasm2/analysis/disasm_cb.py index 284a2c99..f6385c9c 100644 --- a/miasm2/analysis/disasm_cb.py +++ b/miasm2/analysis/disasm_cb.py @@ -1,6 +1,6 @@ #-*- coding:utf-8 -*- -from miasm2.expression.expression import ExprInt, ExprId, ExprMem, MatchExpr +from miasm2.expression.expression import ExprInt, ExprId, ExprMem, match_expr from miasm2.expression.simplifications import expr_simp from miasm2.core.asmblock \ import AsmSymbolPool, AsmConstraintNext, AsmConstraintTo @@ -99,7 +99,7 @@ def arm_guess_jump_table( ad = pc_val.arg ad = expr_simp(ad) print ad - res = MatchExpr(ad, jra + jrb, set([jra, jrb])) + res = match_expr(ad, jra + jrb, set([jra, jrb])) if res is False: raise NotImplementedError('not fully functional') print res diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py index 3d0eee00..eeafd5f5 100644 --- a/miasm2/arch/sh4/arch.py +++ b/miasm2/arch/sh4/arch.py @@ -196,7 +196,7 @@ class sh4_dgpregpinc(m_arg): if not isinstance(e, ExprMem): return False e = e.arg - res = MatchExpr(e, ExprOp(self.op, jra), [jra]) + res = match_expr(e, ExprOp(self.op, jra), [jra]) if not res: return False r = res[jra] @@ -234,7 +234,7 @@ class sh4_dgpreg_imm(sh4_dgpreg): v = gpregs.expr.index(e.arg) p.disp.value = 0 elif isinstance(e.arg, ExprOp): - res = MatchExpr(e, ExprMem(jra + jrb, self.sz), [jra, jrb]) + res = match_expr(e, ExprMem(jra + jrb, self.sz), [jra, jrb]) if not res: return False if not isinstance(res[jra], ExprId): @@ -291,7 +291,7 @@ class sh4_dpc16imm(sh4_dgpreg): return v def encode(self): - res = MatchExpr(self.expr, ExprMem(PC + jra, 16), [jra]) + res = match_expr(self.expr, ExprMem(PC + jra, 16), [jra]) if not res: return False if not isinstance(res[jra], ExprInt): @@ -317,7 +317,7 @@ class sh4_dgbrimm8(sh4_dgpreg): if e == ExprMem(GBR): self.value = 0 return True - res = MatchExpr(self.expr, ExprMem(GBR + jra, s), [jra]) + res = match_expr(self.expr, ExprMem(GBR + jra, s), [jra]) if not res: return False if not isinstance(res[jra], ExprInt): @@ -341,7 +341,7 @@ class sh4_dpc32imm(sh4_dpc16imm): return v def encode(self): - res = MatchExpr( + res = match_expr( self.expr, ExprMem((PC & ExprInt(0xFFFFFFFC, 32)) + jra, 32), [jra]) if not res: return False @@ -362,7 +362,7 @@ class sh4_pc32imm(m_arg): return True def encode(self): - res = MatchExpr(self.expr, (PC & ExprInt(0xfffffffc, 32)) + jra, [jra]) + res = match_expr(self.expr, (PC & ExprInt(0xfffffffc, 32)) + jra, [jra]) if not res: return False if not isinstance(res[jra], ExprInt): @@ -551,7 +551,7 @@ class bs_dr0gp(sh4_dgpreg): return True def encode(self): - res = MatchExpr(self.expr, ExprMem(R0 + jra, self.sz), [jra]) + res = match_expr(self.expr, ExprMem(R0 + jra, self.sz), [jra]) if not res: return False r = res[jra] diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py index ec9eac36..c64c7b72 100644 --- a/miasm2/core/graph.py +++ b/miasm2/core/graph.py @@ -753,7 +753,7 @@ class MatchGraphJoker(object): class MatchGraph(DiGraph): - """MatchGraph intends to be the counterpart of MatchExpr, but for DiGraph + """MatchGraph intends to be the counterpart of match_expr, but for DiGraph This class provides API to match a given DiGraph pattern, with addidionnal restrictions. diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index bf27218b..8ea855b5 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -1400,7 +1400,7 @@ def match_expr(expr, pattern, tks, result=None): # We need to use a copy of result to not override it myresult = dict(result) for sub_expr, sub_pattern in zip(permut, pattern.args): - ret = MatchExpr(sub_expr, sub_pattern, tks, myresult) + ret = match_expr(sub_expr, sub_pattern, tks, myresult) # If the current permutation do not match EVERY terms if ret is False: good = False @@ -1420,23 +1420,23 @@ def match_expr(expr, pattern, tks, result=None): return False if expr.size != pattern.size: return False - return MatchExpr(expr.arg, pattern.arg, tks, result) + return match_expr(expr.arg, pattern.arg, tks, result) elif expr.is_slice(): if not pattern.is_slice(): return False if expr.start != pattern.start or expr.stop != pattern.stop: return False - return MatchExpr(expr.arg, pattern.arg, tks, result) + return match_expr(expr.arg, pattern.arg, tks, result) elif expr.is_cond(): if not pattern.is_cond(): return False - if MatchExpr(expr.cond, pattern.cond, tks, result) is False: + if match_expr(expr.cond, pattern.cond, tks, result) is False: return False - if MatchExpr(expr.src1, pattern.src1, tks, result) is False: + if match_expr(expr.src1, pattern.src1, tks, result) is False: return False - if MatchExpr(expr.src2, pattern.src2, tks, result) is False: + if match_expr(expr.src2, pattern.src2, tks, result) is False: return False return result @@ -1444,21 +1444,21 @@ def match_expr(expr, pattern, tks, result=None): if not pattern.is_compose(): return False for sub_expr, sub_pattern in zip(expr.args, pattern.args): - if MatchExpr(sub_expr, sub_pattern, tks, result) is False: + if match_expr(sub_expr, sub_pattern, tks, result) is False: return False return result elif expr.is_aff(): if not pattern.is_aff(): return False - if MatchExpr(expr.src, pattern.src, tks, result) is False: + if match_expr(expr.src, pattern.src, tks, result) is False: return False - if MatchExpr(expr.dst, pattern.dst, tks, result) is False: + if match_expr(expr.dst, pattern.dst, tks, result) is False: return False return result else: - raise NotImplementedError("MatchExpr: Unknown type: %s" % type(expr)) + raise NotImplementedError("match_expr: Unknown type: %s" % type(expr)) def MatchExpr(expr, pattern, tks, result=None): diff --git a/miasm2/expression/simplifications_cond.py b/miasm2/expression/simplifications_cond.py index 0d194d9a..3054d92b 100644 --- a/miasm2/expression/simplifications_cond.py +++ b/miasm2/expression/simplifications_cond.py @@ -62,12 +62,12 @@ def __check_msb(e): return arg -def __MatchExprWrap(e, to_match, jok_list): - "Wrapper around MatchExpr to canonize pattern" +def __match_expr_wrap(e, to_match, jok_list): + "Wrapper around match_expr to canonize pattern" to_match = to_match.canonize() - r = m2_expr.MatchExpr(e, to_match, jok_list) + r = m2_expr.match_expr(e, to_match, jok_list) if r is False: return False @@ -82,10 +82,9 @@ def expr_simp_inf_signed(expr_simp, e): arg = __check_msb(e) if arg is False: return e - # We want jok3 = jok1 - jok2 to_match = jok3 ^ ((jok1 ^ jok2) & (jok3 ^ jok1)) - r = __MatchExprWrap(arg, + r = __match_expr_wrap(arg, to_match, [jok1, jok2, jok3]) @@ -109,7 +108,7 @@ def expr_simp_inf_unsigned_inversed(expr_simp, e): # We want jok3 = jok1 - jok2 to_match = jok3 ^ ((jok1 ^ jok2) & (jok3 ^ jok1)) ^ jok1 ^ jok2 - r = __MatchExprWrap(arg, + r = __match_expr_wrap(arg, to_match, [jok1, jok2, jok3]) @@ -129,14 +128,14 @@ def expr_simp_inverse(expr_simp, e): (x <s y) ^ ((x ^ y) [31:32]) == x <u y""" to_match = (ExprOp_inf_unsigned(jok1, jok2) ^ jok_small) - r = __MatchExprWrap(e, + r = __match_expr_wrap(e, to_match, [jok1, jok2, jok_small]) # Check for 2 symetric cases if r is False: to_match = (ExprOp_inf_signed(jok1, jok2) ^ jok_small) - r = __MatchExprWrap(e, + r = __match_expr_wrap(e, to_match, [jok1, jok2, jok_small]) @@ -170,9 +169,9 @@ def expr_simp_equal(expr_simp, e): """(x - y)?(0:1) == (x == y)""" to_match = m2_expr.ExprCond(jok1 + jok2, m2_expr.ExprInt(0, 1), m2_expr.ExprInt(1, 1)) - r = __MatchExprWrap(e, - to_match, - [jok1, jok2]) + r = __match_expr_wrap(e, + to_match, + [jok1, jok2]) if r is False: return e diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index d4553495..60c328dc 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -387,28 +387,28 @@ e2 = ExprMem((a & ExprInt(0xFFFFFFFC, 32)) + b, 32) e3 = (a ^ b ^ ((a ^ b) & (b ^ (b - a))) ^ (b - a)).canonize() match_tests = [ - (MatchExpr(ExprInt(12, 32), a, [a]), {a: ExprInt(12, 32)}), - (MatchExpr(x, a, [a]), {a: x}), - (MatchExpr(x + y, a, [a]), {a: x + y}), - (MatchExpr(x + y, a + y, [a]), {a: x}), - (MatchExpr(x + y, x + a, [a]), {a: y}), - (MatchExpr(x + y, a + b, [a, b]), {a: x, b: y}), - (MatchExpr(x + ExprInt(12, 32), a + b, [a, b]), {a: x, b: ExprInt(12, 32)}), - (MatchExpr(ExprMem(x), a, [a]), {a: ExprMem(x)}), - (MatchExpr(ExprMem(x), ExprMem(a), [a]), {a: x}), - (MatchExpr(x[0:8], a, [a]), {a: x[0:8]}), - (MatchExpr(x[0:8], a[0:8], [a]), {a: x}), - (MatchExpr(ExprCond(x, y, z), a, [a]), {a: ExprCond(x, y, z)}), - (MatchExpr(ExprCond(x, y, z), + (match_expr(ExprInt(12, 32), a, [a]), {a: ExprInt(12, 32)}), + (match_expr(x, a, [a]), {a: x}), + (match_expr(x + y, a, [a]), {a: x + y}), + (match_expr(x + y, a + y, [a]), {a: x}), + (match_expr(x + y, x + a, [a]), {a: y}), + (match_expr(x + y, a + b, [a, b]), {a: x, b: y}), + (match_expr(x + ExprInt(12, 32), a + b, [a, b]), {a: x, b: ExprInt(12, 32)}), + (match_expr(ExprMem(x), a, [a]), {a: ExprMem(x)}), + (match_expr(ExprMem(x), ExprMem(a), [a]), {a: x}), + (match_expr(x[0:8], a, [a]), {a: x[0:8]}), + (match_expr(x[0:8], a[0:8], [a]), {a: x}), + (match_expr(ExprCond(x, y, z), a, [a]), {a: ExprCond(x, y, z)}), + (match_expr(ExprCond(x, y, z), ExprCond(a, b, c), [a, b, c]), {a: x, b: y, c: z}), - (MatchExpr(ExprCompose(x[:8], y[:8]), a, [a]), + (match_expr(ExprCompose(x[:8], y[:8]), a, [a]), {a: ExprCompose(x[:8], y[:8])}), - (MatchExpr(ExprCompose(x[:8], y[:8]), + (match_expr(ExprCompose(x[:8], y[:8]), ExprCompose(a[:8], b[:8]), [a, b]), {a: x, b: y}), - (MatchExpr(e1, e2, [b]), {b: ExprInt(0x10, 32)}), - (MatchExpr(e3, + (match_expr(e1, e2, [b]), {b: ExprInt(0x10, 32)}), + (match_expr(e3, (((jra ^ jrb) & (jrb ^ jrint1)) ^ jra ^ jrb ^ jrint1).canonize(), [jra, jrb, jrint1]), |