diff options
Diffstat (limited to '')
| -rw-r--r-- | test/expression/expr_cmp.py | 4 | ||||
| -rw-r--r-- | test/expression/expr_pickle.py | 17 | ||||
| -rw-r--r-- | test/expression/expression.py | 19 | ||||
| -rwxr-xr-x | test/expression/expression_helper.py | 19 | ||||
| -rw-r--r-- | test/expression/modint.py | 34 | ||||
| -rw-r--r-- | test/expression/parser.py | 7 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 65 | ||||
| -rwxr-xr-x | test/expression/stp.py | 13 |
8 files changed, 94 insertions, 84 deletions
diff --git a/test/expression/expr_cmp.py b/test/expression/expr_cmp.py index b238151d..671085f1 100644 --- a/test/expression/expr_cmp.py +++ b/test/expression/expr_cmp.py @@ -2,12 +2,12 @@ # Expression comparison regression tests # # from pdb import pm -from miasm2.expression.expression import ExprInt, expr_is_unsigned_greater,\ +from miasm.expression.expression import ExprInt, expr_is_unsigned_greater,\ expr_is_unsigned_greater_or_equal, expr_is_unsigned_lower,\ expr_is_unsigned_lower_or_equal, expr_is_signed_greater,\ expr_is_signed_greater_or_equal, expr_is_signed_lower, \ expr_is_signed_lower_or_equal, expr_is_equal, expr_is_not_equal -from miasm2.expression.simplifications import expr_simp +from miasm.expression.simplifications import expr_simp int_0 = ExprInt(0, 32) int_1 = ExprInt(1, 32) diff --git a/test/expression/expr_pickle.py b/test/expression/expr_pickle.py index 870f761a..70778d38 100644 --- a/test/expression/expr_pickle.py +++ b/test/expression/expr_pickle.py @@ -1,5 +1,6 @@ +from __future__ import print_function import pickle -from miasm2.expression.expression import ExprInt, ExprAssign, ExprId, \ +from miasm.expression.expression import ExprInt, ExprAssign, ExprId, \ Expr, ExprCompose, ExprMem @@ -12,15 +13,15 @@ f = a[:8] aff = ExprAssign(a, b) -print 'Pickling' +print('Pickling') out = pickle.dumps((a, b, c, d, e, f, aff)) -print 'Unpickling' +print('Unpickling') new_a, new_b, new_c, new_d, new_e, new_f, new_aff = pickle.loads(out) -print 'Result' -print a, b, c, aff -print id(a), id(b), id(c), id(d), id(e), id(f), id(aff) -print new_a, new_b, new_c, new_d, new_e, new_f, new_aff -print id(new_a), id(new_b), id(new_c), id(new_d), id(new_e), id(new_f), id(new_aff) +print('Result') +print(a, b, c, aff) +print(id(a), id(b), id(c), id(d), id(e), id(f), id(aff)) +print(new_a, new_b, new_c, new_d, new_e, new_f, new_aff) +print(id(new_a), id(new_b), id(new_c), id(new_d), id(new_e), id(new_f), id(new_aff)) assert a == new_a assert b == new_b diff --git a/test/expression/expression.py b/test/expression/expression.py index 1b39ab9f..3597eae8 100644 --- a/test/expression/expression.py +++ b/test/expression/expression.py @@ -1,9 +1,10 @@ +from __future__ import print_function # # Expression regression tests # # from pdb import pm -from miasm2.expression.expression import * -from miasm2.expression.expression_helper import * +from miasm.expression.expression import * +from miasm.expression.expression_helper import * # Expression comparison assert(ExprInt(-1, 64) != ExprInt(-2, 64)) @@ -42,15 +43,15 @@ for expr in [ ExprCond(cond2, cst3, cst4)), ExprCond(ExprCond(cond1, cst1, cst2), cst3, cst4), ]: - print "*" * 80 - print expr + print("*" * 80) + print(expr) sol = possible_values(expr) - print sol - print "Resulting constraints:" + print(sol) + print("Resulting constraints:") for consval in sol: - print "For value %s" % consval.value + print("For value %s" % consval.value) for constraint in consval.constraints: - print "\t%s" % constraint.to_constraint() + print("\t%s" % constraint.to_constraint()) # Repr for expr in [ @@ -63,7 +64,7 @@ for expr in [ A.msb(), ExprAssign(A, cst1), ]: - print repr(expr) + print(repr(expr)) assert expr == eval(repr(expr)) diff --git a/test/expression/expression_helper.py b/test/expression/expression_helper.py index 35873ca4..c188215e 100755 --- a/test/expression/expression_helper.py +++ b/test/expression/expression_helper.py @@ -1,14 +1,17 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from __future__ import print_function + +from future.utils import viewitems import unittest class TestExpressionExpressionHelper(unittest.TestCase): def test_Variables_Identifier(self): - import miasm2.expression.expression as m2_expr - from miasm2.expression.expression_helper import Variables_Identifier + import miasm.expression.expression as m2_expr + from miasm.expression.expression_helper import Variables_Identifier # Build a complex expression cst = m2_expr.ExprInt(0x100, 16) @@ -25,13 +28,13 @@ class TestExpressionExpressionHelper(unittest.TestCase): vi = Variables_Identifier(exprf) # Use __str__ - print vi + print(vi) # Test the result new_expr = vi.equation ## Force replace in the variable dependency order - for var_id, var_value in reversed(vi.vars.items()): + for var_id, var_value in reversed(list(viewitems(vi.vars))): new_expr = new_expr.replace_expr({var_id: var_value}) self.assertEqual(exprf, new_expr) @@ -39,12 +42,12 @@ class TestExpressionExpressionHelper(unittest.TestCase): vi = Variables_Identifier(exprf, var_prefix="prefix_v") ## Use __str__ - print vi + print(vi) ## Test the result new_expr = vi.equation ### Force replace in the variable dependency order - for var_id, var_value in reversed(vi.vars.items()): + for var_id, var_value in reversed(list(viewitems(vi.vars))): new_expr = new_expr.replace_expr({var_id: var_value}) self.assertEqual(exprf, new_expr) @@ -55,7 +58,7 @@ class TestExpressionExpressionHelper(unittest.TestCase): ## Test the result new_expr = vi2.equation ### Force replace in the variable dependency order - for var_id, var_value in reversed(vi2.vars.items()): + for var_id, var_value in reversed(list(viewitems(vi2.vars))): new_expr = new_expr.replace_expr({var_id: var_value}) self.assertEqual(vi.equation, new_expr) @@ -72,7 +75,7 @@ class TestExpressionExpressionHelper(unittest.TestCase): ## Test the result new_expr = vi2.equation ### Force replace in the variable dependency order - for var_id, var_value in reversed(vi2.vars.items()): + for var_id, var_value in reversed(list(viewitems(vi2.vars))): new_expr = new_expr.replace_expr({var_id: var_value}) self.assertEqual(vi.equation, new_expr) diff --git a/test/expression/modint.py b/test/expression/modint.py index 17c12907..af80b284 100644 --- a/test/expression/modint.py +++ b/test/expression/modint.py @@ -1,4 +1,6 @@ -from miasm2.expression.modint import * +from __future__ import print_function + +from miasm.expression.modint import * a = uint8(0x42) b = uint8(0xFF) @@ -10,12 +12,12 @@ e = uint1(1) f = uint8(0x1) g = int8(-3) -print a, b, c -print a + b, a + c, b + c -print a == a, a == b, a == 0x42, a == 0x78 -print a != b, a != a -print d, e -print d + e, d + d, e + e, e + e + e, e + 0x11 +print(a, b, c) +print(a + b, a + c, b + c) +print(a == a, a == b, a == 0x42, a == 0x78) +print(a != b, a != a) +print(d, e) +print(d + e, d + d, e + e, e + e + e, e + 0x11) assert(f == 1) assert(f + 1 == 2) @@ -24,10 +26,10 @@ assert(f + 0xff == 0) assert(f & 0 == 0) assert(f & 0xff == f) assert(0xff & f == f) -assert(f / 1 == f) -assert(1 / f == f) +assert(f // 1 == f) +assert(1 // f == f) +assert(int(f) == 1) assert(int(f) == 1) -assert(long(f) == 1) assert(~f == 0xfe) assert(f << 1 == 2) assert(f << 8 == 0) @@ -53,20 +55,20 @@ assert(f ^ f == 0) assert(f ^ 0 == f) assert(0 ^ f == f) assert(1 ^ f == 0) -assert(c / g == -1) -assert(c / -3 == -1) +assert(c // g == -1) +assert(c // -3 == -1) assert(c % g == 1) assert(c % -3 == 1) -print e + c, c + e, c - e, e - c -print 1000 * a -print hex(a) +print(e + c, c + e, c - e, e - c) +print(1000 * a) +print(hex(a)) define_int(128) define_uint(128) h = uint128(0x11223344556677889900AABBCCDDEEFF) i = int128(-0x9900AABBCCDDEEFF1122334455667788) -assert(i / h == 6) +assert(i //h == 6) assert(i % h == 0x3221aa32bb43cd58d9cc54dd65ee7e) diff --git a/test/expression/parser.py b/test/expression/parser.py index ccae49b0..48c63753 100644 --- a/test/expression/parser.py +++ b/test/expression/parser.py @@ -1,5 +1,6 @@ -from miasm2.expression.parser import str_to_expr -from miasm2.expression.expression import ExprInt, ExprId, ExprSlice, ExprMem, \ +from __future__ import print_function +from miasm.expression.parser import str_to_expr +from miasm.expression.expression import ExprInt, ExprId, ExprSlice, ExprMem, \ ExprCond, ExprCompose, ExprOp, ExprAssign, ExprLoc, LocKey for expr_test in [ExprInt(0x12, 32), @@ -13,5 +14,5 @@ for expr_test in [ExprInt(0x12, 32), ExprAssign(ExprId('EAX', 32), ExprInt(0x12, 32)), ]: - print 'Test: %s' % expr_test + print('Test: %s' % expr_test) assert str_to_expr(repr(expr_test)) == expr_test diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index cc33fc54..1a22c43d 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # Expression simplification regression tests # # @@ -5,11 +6,11 @@ from pdb import pm from argparse import ArgumentParser import logging -from miasm2.expression.expression import * -from miasm2.expression.simplifications import expr_simp, expr_simp_explicit, \ +from miasm.expression.expression import * +from miasm.expression.simplifications import expr_simp, expr_simp_explicit, \ ExpressionSimplifier, log_exprsimp -from miasm2.expression.simplifications_cond import ExprOp_inf_signed, ExprOp_inf_unsigned, ExprOp_equal +from miasm.expression.simplifications_cond import ExprOp_inf_signed, ExprOp_inf_unsigned, ExprOp_equal parser = ArgumentParser("Expression simplification regression tests") parser.add_argument("--z3", action="store_true", help="Enable check against z3") @@ -23,23 +24,23 @@ if args.verbose: # Additional imports and definitions if args.z3: import z3 - from miasm2.ir.translators import Translator + from miasm.ir.translators import Translator trans = Translator.to_language("z3") def check(expr_in, expr_out): """Check that expr_in is always equals to expr_out""" - print "Ensure %s = %s" % (expr_in, expr_out) + print("Ensure %s = %s" % (expr_in, expr_out)) solver = z3.Solver() solver.add(trans.from_expr(expr_in) != trans.from_expr(expr_out)) result = solver.check() if result != z3.unsat: - print "ERROR: a counter-example has been founded:" + print("ERROR: a counter-example has been founded:") model = solver.model() - print model + print(model) - print "Reinjecting in the simplifier:" + print("Reinjecting in the simplifier:") to_rep = {} expressions = expr_in.get_r().union(expr_out.get_r()) for expr in expressions: @@ -54,10 +55,10 @@ if args.z3: new_expr_in = expr_in.replace_expr(to_rep) new_expr_out = expr_out.replace_expr(to_rep) - print "Check %s = %s" % (new_expr_in, new_expr_out) + print("Check %s = %s" % (new_expr_in, new_expr_out)) simp_in = expr_simp_explicit(new_expr_in) simp_out = expr_simp_explicit(new_expr_out) - print "[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out) + print("[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out)) # Either the simplification does not stand, either the test is wrong raise RuntimeError("Bad simplification") @@ -313,7 +314,7 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (ExprCompose(a, ExprInt(0, 32)) * ExprInt(0x123, 64))[32:64]), (ExprInt(0x12, 32), - ExprInt(0x12L, 32)), + ExprInt(0x12, 32)), (ExprCompose(a, b, c)[:16], @@ -335,32 +336,32 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (ExprCompose(a, b, c)[48:80], ExprCompose(b[16:], c[:16])), - (ExprCompose(a[0:8], b[8:16], ExprInt(0x0L, 48))[12:32], + (ExprCompose(a[0:8], b[8:16], ExprInt(0x0, 48))[12:32], ExprCompose(b[12:16], ExprInt(0, 16)) ), - (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[8:32] + (ExprCompose(ExprCompose(a[:8], ExprInt(0x0, 56))[8:32] & - ExprInt(0x1L, 24), - ExprInt(0x0L, 40)), + ExprInt(0x1, 24), + ExprInt(0x0, 40)), ExprInt(0, 64)), - (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[:8] + (ExprCompose(ExprCompose(a[:8], ExprInt(0x0, 56))[:8] & - ExprInt(0x1L, 8), - (ExprInt(0x0L, 56))), + ExprInt(0x1, 8), + (ExprInt(0x0, 56))), ExprCompose(a[:8]&ExprInt(1, 8), ExprInt(0, 56))), (ExprCompose(ExprCompose(a[:8], - ExprInt(0x0L, 56))[:32] + ExprInt(0x0, 56))[:32] & - ExprInt(0x1L, 32), - ExprInt(0x0L, 32)), + ExprInt(0x1, 32), + ExprInt(0x0, 32)), ExprCompose(ExprCompose(ExprSlice(a, 0, 8), - ExprInt(0x0L, 24)) + ExprInt(0x0, 24)) & - ExprInt(0x1L, 32), - ExprInt(0x0L, 32)) + ExprInt(0x1, 32), + ExprInt(0x0, 32)) ), (ExprCompose(a[:16], b[:16])[8:32], ExprCompose(a[8:16], b[:16])), @@ -472,9 +473,9 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), ] for e_input, e_check in to_test: - print "#" * 80 + print("#" * 80) e_new = expr_simp_explicit(e_input) - print "original: ", str(e_input), "new: ", str(e_new) + print("original: ", str(e_input), "new: ", str(e_new)) rez = e_new == e_check if not rez: raise ValueError( @@ -741,10 +742,10 @@ to_test = [ ] for e_input, e_check in to_test: - print "#" * 80 + print("#" * 80) e_check = expr_simp(e_check) e_new = expr_simp(e_input) - print "original: ", str(e_input), "new: ", str(e_new) + print("original: ", str(e_input), "new: ", str(e_new)) rez = e_new == e_check if not rez: raise ValueError( @@ -780,10 +781,10 @@ expr_simp.enable_passes(ExpressionSimplifier.PASS_COND) for e_input, e_check in to_test: - print "#" * 80 + print("#" * 80) e_check = expr_simp(e_check) e_new = expr_simp(e_input) - print "original: ", str(e_input), "new: ", str(e_new) + print("original: ", str(e_input), "new: ", str(e_new)) rez = e_new == e_check if not rez: raise ValueError( @@ -902,6 +903,6 @@ for x, y in to_test: assert(x == y) assert(str(x) == str(y)) - print x + print(x) -print 'all tests ok' +print('all tests ok') diff --git a/test/expression/stp.py b/test/expression/stp.py index 38bbf9c8..b97b0754 100755 --- a/test/expression/stp.py +++ b/test/expression/stp.py @@ -1,17 +1,18 @@ #! /usr/bin/env python2 #-*- coding:utf-8 -*- +from builtins import range import unittest class TestIrIr2STP(unittest.TestCase): def test_ExprOp_strcst(self): - from miasm2.expression.expression import ExprInt, ExprOp - from miasm2.ir.translators.translator import Translator + from miasm.expression.expression import ExprInt, ExprOp + from miasm.ir.translators.translator import Translator translator_smt2 = Translator.to_language("smt2") - args = [ExprInt(i, 32) for i in xrange(9)] + args = [ExprInt(i, 32) for i in range(9)] self.assertEqual( translator_smt2.from_expr(ExprOp('|', *args[:2])), r'(bvor (_ bv0 32) (_ bv1 32))') @@ -22,11 +23,11 @@ class TestIrIr2STP(unittest.TestCase): self.assertRaises(NotImplementedError, translator_smt2.from_expr, ExprOp('X', *args[:1])) def test_ExprSlice_strcst(self): - from miasm2.expression.expression import ExprInt, ExprOp - from miasm2.ir.translators.translator import Translator + from miasm.expression.expression import ExprInt, ExprOp + from miasm.ir.translators.translator import Translator translator_smt2 = Translator.to_language("smt2") - args = [ExprInt(i, 32) for i in xrange(9)] + args = [ExprInt(i, 32) for i in range(9)] self.assertEqual( translator_smt2.from_expr(args[0][1:2]), r'((_ extract 1 1) (_ bv0 32))') |