diff options
| author | Ajax <commial@gmail.com> | 2018-02-09 15:30:26 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2018-02-14 12:14:07 +0100 |
| commit | 68bacc75b53a77296980a58d5051b696ffe1c219 (patch) | |
| tree | 1cb29b1c0f0148b7fe7aff6f70b6e711ecce73b9 | |
| parent | dcfadb31685d428618b88f19fcc96dd70cecfc8f (diff) | |
| download | miasm-68bacc75b53a77296980a58d5051b696ffe1c219.tar.gz miasm-68bacc75b53a77296980a58d5051b696ffe1c219.zip | |
Deprecate expr_cmps/expr_cmpu for a more verbose / understandable API
| -rw-r--r-- | miasm2/arch/x86/sem.py | 13 | ||||
| -rw-r--r-- | miasm2/expression/expression_helper.py | 10 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 33 |
3 files changed, 27 insertions, 29 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 93c4910a..9f438b71 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -21,7 +21,6 @@ import miasm2.expression.expression as m2_expr from miasm2.expression.simplifications import expr_simp from miasm2.arch.x86.regs import * from miasm2.arch.x86.arch import mn_x86, repeat_mn, replace_regs -from miasm2.expression.expression_helper import expr_cmps, expr_cmpu from miasm2.ir.ir import IntermediateRepresentation, IRBlock, AssignBlock from miasm2.core.sembuilder import SemBuilder from miasm2.jitter.csts import EXCEPT_DIV_BY_ZERO, EXCEPT_ILLEGAL_INSN, \ @@ -2741,11 +2740,11 @@ def daa(_, instr): e = [] r_al = mRAX[instr.mode][:8] - cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af + cond1 = m2_expr.expr_is_unsigned_greater(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) - cond2 = expr_cmpu(m2_expr.ExprInt(6, 8), r_al) - cond3 = expr_cmpu(r_al, m2_expr.ExprInt(0x99, 8)) | cf + cond2 = m2_expr.expr_is_unsigned_greater(m2_expr.ExprInt(6, 8), r_al) + cond3 = m2_expr.expr_is_unsigned_greater(r_al, m2_expr.ExprInt(0x99, 8)) | cf cf_c1 = m2_expr.ExprCond(cond1, cf | (cond2), @@ -2771,11 +2770,11 @@ def das(_, instr): e = [] r_al = mRAX[instr.mode][:8] - cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af + cond1 = m2_expr.expr_is_unsigned_greater(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) - cond2 = expr_cmpu(m2_expr.ExprInt(6, 8), r_al) - cond3 = expr_cmpu(r_al, m2_expr.ExprInt(0x99, 8)) | cf + cond2 = m2_expr.expr_is_unsigned_greater(m2_expr.ExprInt(6, 8), r_al) + cond3 = m2_expr.expr_is_unsigned_greater(r_al, m2_expr.ExprInt(0x99, 8)) | cf cf_c1 = m2_expr.ExprCond(cond1, cf | (cond2), diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py index 1e718faa..722d169d 100644 --- a/miasm2/expression/expression_helper.py +++ b/miasm2/expression/expression_helper.py @@ -21,6 +21,7 @@ import itertools import collections import random import string +import warnings import miasm2.expression.expression as m2_expr @@ -468,16 +469,14 @@ class ExprRandom(object): return got -def _expr_cmp_gen(arg1, arg2): - return (arg2 - arg1) ^ ((arg2 ^ arg1) & ((arg2 - arg1) ^ arg2)) - def expr_cmpu(arg1, arg2): """ Returns a one bit long Expression: * 1 if @arg1 is strictly greater than @arg2 (unsigned) * 0 otherwise. """ - return (_expr_cmp_gen(arg1, arg2) ^ arg2 ^ arg1).msb() + warnings.warn('DEPRECATION WARNING: use "expr_is_unsigned_greater" instead"') + return m2_expr.expr_is_unsigned_greater(arg1, arg2) def expr_cmps(arg1, arg2): """ @@ -485,7 +484,8 @@ def expr_cmps(arg1, arg2): * 1 if @arg1 is strictly greater than @arg2 (signed) * 0 otherwise. """ - return _expr_cmp_gen(arg1, arg2).msb() + warnings.warn('DEPRECATION WARNING: use "expr_is_signed_greater" instead"') + return m2_expr.expr_is_signed_greater(arg1, arg2) class CondConstraint(object): diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index e4c3f2e9..53283bef 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -3,7 +3,6 @@ # from pdb import pm from miasm2.expression.expression import * -from miasm2.expression.expression_helper import expr_cmpu, expr_cmps from miasm2.expression.simplifications import expr_simp, ExpressionSimplifier from miasm2.expression.simplifications_cond import ExprOp_inf_signed, ExprOp_inf_unsigned, ExprOp_equal @@ -268,37 +267,37 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), a[:16]), ((a << ExprInt(16, 32))[24:32], a[8:16]), - (expr_cmpu(ExprInt(0, 32), ExprInt(0, 32)), + (expr_is_unsigned_greater(ExprInt(0, 32), ExprInt(0, 32)), ExprInt(0, 1)), - (expr_cmpu(ExprInt(10, 32), ExprInt(0, 32)), + (expr_is_unsigned_greater(ExprInt(10, 32), ExprInt(0, 32)), ExprInt(1, 1)), - (expr_cmpu(ExprInt(10, 32), ExprInt(5, 32)), + (expr_is_unsigned_greater(ExprInt(10, 32), ExprInt(5, 32)), ExprInt(1, 1)), - (expr_cmpu(ExprInt(5, 32), ExprInt(10, 32)), + (expr_is_unsigned_greater(ExprInt(5, 32), ExprInt(10, 32)), ExprInt(0, 1)), - (expr_cmpu(ExprInt(-1, 32), ExprInt(0, 32)), + (expr_is_unsigned_greater(ExprInt(-1, 32), ExprInt(0, 32)), ExprInt(1, 1)), - (expr_cmpu(ExprInt(-1, 32), ExprInt(-1, 32)), + (expr_is_unsigned_greater(ExprInt(-1, 32), ExprInt(-1, 32)), ExprInt(0, 1)), - (expr_cmpu(ExprInt(0, 32), ExprInt(-1, 32)), + (expr_is_unsigned_greater(ExprInt(0, 32), ExprInt(-1, 32)), ExprInt(0, 1)), - (expr_cmps(ExprInt(0, 32), ExprInt(0, 32)), + (expr_is_signed_greater(ExprInt(0, 32), ExprInt(0, 32)), ExprInt(0, 1)), - (expr_cmps(ExprInt(10, 32), ExprInt(0, 32)), + (expr_is_signed_greater(ExprInt(10, 32), ExprInt(0, 32)), ExprInt(1, 1)), - (expr_cmps(ExprInt(10, 32), ExprInt(5, 32)), + (expr_is_signed_greater(ExprInt(10, 32), ExprInt(5, 32)), ExprInt(1, 1)), - (expr_cmps(ExprInt(5, 32), ExprInt(10, 32)), + (expr_is_signed_greater(ExprInt(5, 32), ExprInt(10, 32)), ExprInt(0, 1)), - (expr_cmps(ExprInt(-1, 32), ExprInt(0, 32)), + (expr_is_signed_greater(ExprInt(-1, 32), ExprInt(0, 32)), ExprInt(0, 1)), - (expr_cmps(ExprInt(-1, 32), ExprInt(-1, 32)), + (expr_is_signed_greater(ExprInt(-1, 32), ExprInt(-1, 32)), ExprInt(0, 1)), - (expr_cmps(ExprInt(0, 32), ExprInt(-1, 32)), + (expr_is_signed_greater(ExprInt(0, 32), ExprInt(-1, 32)), ExprInt(1, 1)), - (expr_cmps(ExprInt(-5, 32), ExprInt(-10, 32)), + (expr_is_signed_greater(ExprInt(-5, 32), ExprInt(-10, 32)), ExprInt(1, 1)), - (expr_cmps(ExprInt(-10, 32), ExprInt(-5, 32)), + (expr_is_signed_greater(ExprInt(-10, 32), ExprInt(-5, 32)), ExprInt(0, 1)), (ExprOp("idiv", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], |