about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--example/expression/solve_condition_stp.py17
-rw-r--r--example/ida/ctype_propagation.py15
-rw-r--r--miasm2/ir/ir.py14
-rw-r--r--miasm2/ir/symbexec.py12
4 files changed, 22 insertions, 36 deletions
diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py
index c9d4c7af..438188ab 100644
--- a/example/expression/solve_condition_stp.py
+++ b/example/expression/solve_condition_stp.py
@@ -11,7 +11,7 @@ from miasm2.core.bin_stream import bin_stream_str
 from miasm2.core import asmblock
 from miasm2.expression.expression import get_rw
 from miasm2.expression.modint import uint32
-from miasm2.ir.symbexec import SymbolicExecutionEngine
+from miasm2.ir.symbexec import SymbolicExecutionEngine, get_block
 from miasm2.expression.simplifications import expr_simp
 from miasm2.expression import stp
 from miasm2.core import parse_asm
@@ -30,21 +30,6 @@ if not args:
     sys.exit(0)
 
 
-def get_block(ir_arch, mdis, ad):
-    if isinstance(ad, asmblock.AsmLabel):
-        l = ad
-    else:
-        l = mdis.symbol_pool.getby_offset_create(ad)
-    if not l in ir_arch.blocks:
-        ad = l.offset
-        b = mdis.dis_block(ad)
-        ir_arch.add_block(b)
-    b = ir_arch.get_block(l)
-    if b is None:
-        raise LookupError('no block found at that address: %s' % l)
-    return b
-
-
 def emul_symb(ir_arch, mdis, states_todo, states_done):
     while states_todo:
         ad, symbols, conds = states_todo.pop()
diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py
index bedaa525..7eb209cd 100644
--- a/example/ida/ctype_propagation.py
+++ b/example/ida/ctype_propagation.py
@@ -53,18 +53,6 @@ Dependency Graph Settings
         form.rUnaliasStack.checked = True
 
 
-def get_block(ir_arch, mdis, addr):
-    """Get IRBlock at address @addr"""
-    lbl = ir_arch.get_label(addr)
-    if not lbl in ir_arch.blocks:
-        block = mdis.dis_block(lbl.offset)
-        ir_arch.add_block(block)
-    irblock = ir_arch.get_block(lbl)
-    if irblock is None:
-        raise LookupError('No block found at that address: %s' % lbl)
-    return irblock
-
-
 def get_types_mngr(headerFile, arch):
     text = open(headerFile).read()
     if arch == "AMD64_unk":
@@ -265,8 +253,7 @@ def analyse_function():
         done.add((lbl, state))
         symbexec_engine = TypePropagationEngine(ir_arch, types_mngr, state)
 
-        get_block(ir_arch, mdis, lbl)
-
+        assert lbl in ir_arch.blocks
         addr = symbexec_engine.emul_ir_block(lbl)
         symbexec_engine.del_mem_above_stack(ir_arch.sp)
 
diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py
index 603d3fd0..afb6b382 100644
--- a/miasm2/ir/ir.py
+++ b/miasm2/ir/ir.py
@@ -469,13 +469,15 @@ class IntermediateRepresentation(object):
         if (isinstance(addr, m2_expr.ExprId) and
                 isinstance(addr.name, AsmLabel)):
             addr = addr.name
-        if isinstance(addr, m2_expr.ExprInt):
+        if isinstance(addr, AsmLabel):
+            return addr
+
+        try:
             addr = int(addr)
-        if isinstance(addr, (int, long)):
-            addr = self.symbol_pool.getby_offset_create(addr)
-        elif isinstance(addr, AsmLabel):
-            addr = self.symbol_pool.getby_name_create(addr.name)
-        return addr
+        except (ValueError, TypeError):
+            return None
+
+        return self.symbol_pool.getby_offset_create(addr)
 
     def get_block(self, addr):
         """Returns the irbloc associated to an ExprId/ExprInt/label/int
diff --git a/miasm2/ir/symbexec.py b/miasm2/ir/symbexec.py
index 6d6ba630..593ab49a 100644
--- a/miasm2/ir/symbexec.py
+++ b/miasm2/ir/symbexec.py
@@ -16,6 +16,18 @@ log.addHandler(console_handler)
 log.setLevel(logging.INFO)
 
 
+def get_block(ir_arch, mdis, addr):
+    """Get IRBlock at address @addr"""
+    lbl = ir_arch.get_label(addr)
+    if not lbl in ir_arch.blocks:
+        block = mdis.dis_block(lbl.offset)
+        ir_arch.add_block(block)
+    irblock = ir_arch.get_block(lbl)
+    if irblock is None:
+        raise LookupError('No block found at that address: %s' % lbl)
+    return irblock
+
+
 class SymbolMngr(object):
     """
     Store registers and memory symbolic values