about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--example/symbol_exec/single_instr.py5
-rw-r--r--miasm2/ir/ir.py12
-rw-r--r--miasm2/ir/symbexec.py7
-rwxr-xr-xtest/ir/symbexec.py4
-rwxr-xr-xtest/test_all.py33
6 files changed, 44 insertions, 19 deletions
diff --git a/.travis.yml b/.travis.yml
index 3583e4ba..81e571c3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -49,4 +49,4 @@ before_script:
 - "cd miasm;"
 - "python setup.py build build_ext -I$(pwd)/../virtualenv/include -L$(pwd)/../virtualenv/tinycc"
 - "python setup.py install"
-script: "python -c 'import z3; x = z3.BitVec(chr(0x41), 32)' && cd test && python test_all.py"
+script: "python -c 'import z3; x = z3.BitVec(chr(0x41), 32)' && cd test && python test_all.py && git ls-files -o --exclude-standard"
diff --git a/example/symbol_exec/single_instr.py b/example/symbol_exec/single_instr.py
index 3e418e5a..c31de738 100644
--- a/example/symbol_exec/single_instr.py
+++ b/example/symbol_exec/single_instr.py
@@ -37,5 +37,6 @@ symb.dump_mem()
 
 # Check final status
 eax, ebx = ira.arch.regs.EAX, ira.arch.regs.EBX
-assert symb.symbols[eax] == symbols_init[ebx]
-assert eax in symb.modified()
+final_state = symb.as_assignblock()
+assert final_state[eax] == symbols_init[ebx]
+assert eax in final_state
diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py
index e5f0c8db..8154d4da 100644
--- a/miasm2/ir/ir.py
+++ b/miasm2/ir/ir.py
@@ -33,7 +33,13 @@ class AssignBlock(object):
     EAX = EBX
     EBX = EAX
 
-    Also provides common manipulation on this assignments
+    -> Exchange between EBX and EAX
+
+    AssignBlock can be seen as a dictionnary where keys are the destinations
+    (ExprId or ExprMem), and values their corresponding sources.
+
+    Also provides common manipulation on this assignments.
+
     """
     __slots__ = ["_assigns", "_instr"]
 
@@ -124,6 +130,10 @@ class AssignBlock(object):
             args = [expr for (expr, _, _) in args]
             new_src = m2_expr.ExprCompose(*args)
 
+        # Sanity check
+        if not isinstance(new_dst, (m2_expr.ExprId, m2_expr.ExprMem)):
+            raise TypeError("Destination cannot be a %s" % type(new_dst))
+
         self._assigns[new_dst] = new_src
 
     def __setitem__(self, dst, src):
diff --git a/miasm2/ir/symbexec.py b/miasm2/ir/symbexec.py
index 33d0f8bd..f9444424 100644
--- a/miasm2/ir/symbexec.py
+++ b/miasm2/ir/symbexec.py
@@ -504,6 +504,13 @@ class SymbolicExecutionEngine(object):
 
         return ret
 
+    def as_assignblock(self):
+        """Return the current state as an AssignBlock"""
+        return AssignBlock({
+            dst: self.symbols[dst] for dst in self.modified()
+        })
+
+
 class symbexec(SymbolicExecutionEngine):
     """
     DEPRECATED object
diff --git a/test/ir/symbexec.py b/test/ir/symbexec.py
index e2bd411f..f8d8c7bf 100755
--- a/test/ir/symbexec.py
+++ b/test/ir/symbexec.py
@@ -75,6 +75,10 @@ class TestSymbExec(unittest.TestCase):
         self.assertEqual(e.apply_expr(assignblk.dst2ExprAff(id_x)), addr0)
         self.assertEqual(e.apply_expr(id_x), addr0)
 
+        # state
+        self.assertEqual(e.as_assignblock().get_r(), set([id_x, id_y]))
+
+
 if __name__ == '__main__':
     testsuite = unittest.TestLoader().loadTestsFromTestCase(TestSymbExec)
     report = unittest.TextTestRunner(verbosity=2).run(testsuite)
diff --git a/test/test_all.py b/test/test_all.py
index 1176545e..41954ff1 100755
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -275,8 +275,10 @@ testset += RegressionTest(["depgraph.py"], base_dir="analysis",
                           ["graph_test_%02d_%02d.dot" % (test_nb, res_nb)
                            for (test_nb, res_nb) in ((3, 1), (5, 1), (8, 1),
                                                      (9, 1), (10, 1),
-                                                     (12, 1), (13, 1),
-                                                     (14, 1), (15, 1))
+                                                     (12, 1), (12, 2),
+                                                     (13, 1), (13, 2),
+                                                     (14, 1), (14, 2),
+                                                     (15, 1))
                            ])
 testset += RegressionTest(["modularintervals.py"], base_dir="analysis")
 for jitter in ArchUnitTest.jitter_engines:
@@ -303,10 +305,11 @@ class TestDepgraph(RegressionTest):
 
 
     def __init__(self, test_nb, implicit, base_addr, target_addr, elements,
-                 *args, **kwargs):
+                 nb_sol, *args, **kwargs):
         super(TestDepgraph, self).__init__([self.launcher],
                                            *args, **kwargs)
         self.base_dir = os.path.join(self.base_dir, "analysis")
+        self.products = ["sol_%d.dot" % i for i in xrange(nb_sol)]
         if implicit:
             expected_fname = "dg_test_%.2d_implicit_expected.json"
             self.tags.append(TAGS["z3"])
@@ -326,18 +329,18 @@ class TestDepgraph(RegressionTest):
             self.command_line.append("-i")
 
 # Depgraph emulation regression test
-test_args = [(0x401000, 0x40100d, ["EAX"]),
-             (0x401000, 0x401011, ["EAX"]),
-             (0x401000, 0x401018, ["EAX"]),
-             (0x401000, 0x401011, ["EAX"]),
-             (0x401000, 0x401011, ["EAX"]),
-             (0x401000, 0x401016, ["EAX"]),
-             (0x401000, 0x401017, ["EAX"]),
-             (0x401000, 0x401012, ["EAX", "ECX"]),
-             (0x401000, 0x401012, ["ECX"]),
-             (0x401000, 0x40101f, ["EAX", "EBX"]),
-             (0x401000, 0x401025, ["EAX", "EBX"]),
-             (0x401000, 0x401007, ["EBX"]),
+test_args = [(0x401000, 0x40100d, ["EAX"], 1),
+             (0x401000, 0x401011, ["EAX"], 1),
+             (0x401000, 0x401018, ["EAX"], 2),
+             (0x401000, 0x401011, ["EAX"], 2),
+             (0x401000, 0x401011, ["EAX"], 1),
+             (0x401000, 0x401016, ["EAX"], 1),
+             (0x401000, 0x401017, ["EAX"], 2),
+             (0x401000, 0x401012, ["EAX", "ECX"], 1),
+             (0x401000, 0x401012, ["ECX"], 1),
+             (0x401000, 0x40101f, ["EAX", "EBX"], 2),
+             (0x401000, 0x401025, ["EAX", "EBX"], 4),
+             (0x401000, 0x401007, ["EBX"], 3),
 ]
 for i, test_args in enumerate(test_args):
     test_dg = SemanticTestAsm("x86_32", "PE", ["dg_test_%.2d" % i])