about summary refs log tree commit diff stats
path: root/miasm/ir/ir.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm/ir/ir.py')
-rw-r--r--miasm/ir/ir.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/miasm/ir/ir.py b/miasm/ir/ir.py
index 613a4bce..3219b5fc 100644
--- a/miasm/ir/ir.py
+++ b/miasm/ir/ir.py
@@ -44,6 +44,26 @@ def _expr_loc_to_symb(expr, loc_db):
             name = sorted(names)[0]
     return m2_expr.ExprId(name, expr.size)
 
+def slice_rest(expr):
+    "Return the completion of the current slice"
+    size = expr.arg.size
+    if expr.start >= size or expr.stop > size:
+        raise ValueError('bad slice rest %s %s %s' %
+                         (size, expr.start, expr.stop))
+
+    if expr.start == expr.stop:
+        return [(0, size)]
+
+    rest = []
+    if expr.start != 0:
+        rest.append((0, expr.start))
+    if expr.stop < size:
+        rest.append((expr.stop, size))
+
+    return rest
+
+
+
 class AssignBlock(object):
     """Represent parallel IR assignment, such as:
     EAX = EBX
@@ -99,7 +119,7 @@ class AssignBlock(object):
             # Complete the source with missing slice parts
             new_dst = dst.arg
             rest = [(m2_expr.ExprSlice(dst.arg, r[0], r[1]), r[0], r[1])
-                    for r in dst.slice_rest()]
+                    for r in slice_rest(dst)]
             all_a = [(src, dst.start, dst.stop)] + rest
             all_a.sort(key=lambda x: x[1])
             args = [expr for (expr, _, _) in all_a]
@@ -752,7 +772,7 @@ class IntermediateRepresentation(object):
 
         if loc_key is None:
             offset = getattr(instr, "offset", None)
-            loc_key = self.loc_db.add_location(offset=offset)
+            loc_key = self.loc_db.get_or_create_offset_location(offset)
         block = AsmBlock(loc_key)
         block.lines = [instr]
         self.add_asmblock_to_ircfg(block, ircfg, gen_pc_updt)
@@ -865,7 +885,7 @@ class IntermediateRepresentation(object):
         return irblock
 
     def is_pc_written(self, block):
-        """Return the first Assignblk of the @blockin which PC is written
+        """Return the first Assignblk of the @block in which PC is written
         @block: IRBlock instance"""
         all_pc = viewvalues(self.arch.pc)
         for assignblk in block: