about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2016-04-26 17:47:38 +0200
committerAjax <commial@gmail.com>2016-04-26 17:47:38 +0200
commit33d7ab0350d44ae7916264bec54b8fac3f2a9ab2 (patch)
treef9cf9784ab1d5fb37ad667dded4a7d81b40a3b04
parent5d8ade642dc0cd888af50464cc1686e73d7382ef (diff)
downloadmiasm-33d7ab0350d44ae7916264bec54b8fac3f2a9ab2.tar.gz
miasm-33d7ab0350d44ae7916264bec54b8fac3f2a9ab2.zip
Python jitter: enable segmentation support
-rw-r--r--miasm2/jitter/emulatedsymbexec.py19
-rw-r--r--miasm2/jitter/jitcore_python.py1
2 files changed, 20 insertions, 0 deletions
diff --git a/miasm2/jitter/emulatedsymbexec.py b/miasm2/jitter/emulatedsymbexec.py
index a5e4d340..f7c48227 100644
--- a/miasm2/jitter/emulatedsymbexec.py
+++ b/miasm2/jitter/emulatedsymbexec.py
@@ -81,3 +81,22 @@ class EmulatedSymbExec(symbexec):
                     self.symbols.symbols_id[symbol] = value
             else:
                 raise NotImplementedError("Type not handled: %s" % symbol)
+
+    # CPU specific simplifications
+    def _simp_handle_segm(self, e_s, expr):
+        """Handle 'segm' operation"""
+        if expr.op != "segm":
+            return expr
+        segm_nb = int(expr.args[0].arg)
+        segmaddr = self.cpu.get_segm_base(segm_nb)
+        return e_s(m2_expr.ExprOp("+",
+                                  m2_expr.ExprInt(segmaddr, expr.size),
+                                  expr.args[1]))
+
+    def enable_emulated_simplifications(self):
+        """Enable simplifications needing a CPU instance on associated
+        ExpressionSimplifier
+        """
+        self.expr_simp.enable_passes({
+            m2_expr.ExprOp: [self._simp_handle_segm]
+        })
diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py
index eced9cd2..e1e62816 100644
--- a/miasm2/jitter/jitcore_python.py
+++ b/miasm2/jitter/jitcore_python.py
@@ -19,6 +19,7 @@ class JitCore_Python(jitcore.JitCore):
 
         # CPU (None for now) will be set by the "jitted" Python function
         self.symbexec = EmulatedSymbExec(None, self.ir_arch, {})
+        self.symbexec.enable_emulated_simplifications()
 
     def load(self):
         "Preload symbols according to current architecture"