about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2015-04-24 10:23:06 +0200
committerAjax <commial@gmail.com>2015-04-24 10:23:06 +0200
commit9536200d7787797c34635dce16462164530f8eaa (patch)
treeb2002c9f79e31f1fbe7c3040e53181d2e16e1ffb
parent568dd3641a10e0887700a3a3433e2e20e8e37825 (diff)
downloadmiasm-9536200d7787797c34635dce16462164530f8eaa.tar.gz
miasm-9536200d7787797c34635dce16462164530f8eaa.zip
SemBuilder: Get back functions parsed for mnemo_func
-rw-r--r--miasm2/arch/mips32/sem.py110
-rw-r--r--miasm2/core/sembuilder.py16
2 files changed, 38 insertions, 88 deletions
diff --git a/miasm2/arch/mips32/sem.py b/miasm2/arch/mips32/sem.py
index ca368883..d634c208 100644
--- a/miasm2/arch/mips32/sem.py
+++ b/miasm2/arch/mips32/sem.py
@@ -408,89 +408,33 @@ def ei(a):
 def ehb(a):
     "NOP"
 
-mnemo_func = {
-    "addiu": addiu,
-    "addu": addiu,
-    "lw" : lw,
-    "sw" : sw,
-    "sh" : sh,
-    "sb" : sb,
-    "jalr" : jalr,
-    "jal" : jal,
-    "bal" : bal,
-    "b" : l_b,
-    "lbu" : lbu,
-    "lhu" : lhu,
-    "lb" : lb,
-    "beq" : beq,
-    "bgez" : bgez,
-    "bltz" : bltz,
-    "bgtz" : bgtz,
-    "bne" : bne,
-    "lui" : lui,
-    "nop" : nop,
-    "j" : j,
-    "jr" : j,
-    "ori" : l_or,
-    "or" : l_or,
-    "nor" : nor,
-    "and" : l_and,
-    "andi" : l_and,
-    "ext" : ext,
-    "mul" : mul,
-    "sltu" : sltu,
-    "slt" : slt,
-    "slti" : slt,
-    "sltiu" : sltu,
-    "subu" : l_sub,
-    "movn" : movn,
-    "movz" : movz,
-    "srl" : srl,
-    "sra" : sra,
-    "srav" : srav,
-    "sll" : sll,
-    "srlv" : srlv,
-    "sllv" : sllv,
-    "xori" : l_xor,
-    "xor" : l_xor,
-    "seb" : seb,
-    "seh" : seh,
-    "bltz" : bltz,
-    "blez" : blez,
-    "wsbh" : wsbh,
-    "rotr" : rotr,
-    # "mfc0" : mfc0,
-    # "mfc1" : mfc1,
-    # "mtc0" : mtc0,
-    # "mtc1" : mtc1,
-    "tlbwi" : tlbwi,
-    "tlbp" : tlbp,
-    "ins" : ins,
-
-    "add.d" : add_d,
-    "sub.d" : sub_d,
-    "div.d" : div_d,
-    "mul.d" : mul_d,
-    "mov.d" : mov_d,
-    "lwc1" : lwc1,
-    "swc1" : swc1,
-    "c.lt.d" : c_lt_d,
-    "c.eq.d" : c_eq_d,
-    "c.le.d" : c_le_d,
-    "bc1t" : bc1t,
-    "bc1f" : bc1f,
-    "cvt.d.w":cvt_d_w,
-    "mult" : mult,
-    "multu" : multu,
-
-    "mfhi" : mfhi,
-    "mflo" : mflo,
-
-    "di" : di,
-    "ei" : ei,
-    "ehb" : ehb,
-
-    }
+mnemo_func = sbuild.functions
+mnemo_func.update({
+        'add.d': add_d,
+        'addu': addiu,
+        'and': l_and,
+        'andi': l_and,
+        'b': l_b,
+        'c.eq.d': c_eq_d,
+        'c.le.d': c_le_d,
+        'c.lt.d': c_lt_d,
+        'cvt.d.w': cvt_d_w,
+        'div.d': div_d,
+        'ins': ins,
+        'jr': j,
+        'mov.d': mov_d,
+        'movn': movn,
+        'movz': movz,
+        'mul.d': mul_d,
+        'or': l_or,
+        'ori': l_or,
+        'slti': slt,
+        'sltiu': sltu,
+        'sub.d': sub_d,
+        'subu': l_sub,
+        'xor': l_xor,
+        'xori': l_xor,
+})
 
 def get_mnemo_expr(ir, instr, *args):
     instr, extra_ir = mnemo_func[instr.name.lower()](ir, instr, *args)
diff --git a/miasm2/core/sembuilder.py b/miasm2/core/sembuilder.py
index ddf1cb32..a62ecc38 100644
--- a/miasm2/core/sembuilder.py
+++ b/miasm2/core/sembuilder.py
@@ -104,12 +104,17 @@ class SemBuilder(object):
         """
         # Init
         self.transformer = MiasmTransformer()
-        self.ctx = dict(m2_expr.__dict__)
-        self.ctx["irbloc"] = irbloc
+        self._ctx = dict(m2_expr.__dict__)
+        self._ctx["irbloc"] = irbloc
+        self._functions = {}
 
         # Update context
-        self.ctx.update(ctx)
+        self._ctx.update(ctx)
 
+    @property
+    def functions(self):
+        """Return a dictionnary name -> func of parsed functions"""
+        return self._functions.copy()
 
     def parse(self, func):
         """Function decorator, returning a correct method from a pseudo-Python
@@ -131,7 +136,7 @@ class SemBuilder(object):
 
                 if (isinstance(dst, ast.Name) and
                     dst.id not in argument_names and
-                    dst.id not in self.ctx):
+                    dst.id not in self._ctx):
 
                     # Real variable declaration
                     statement.value = src
@@ -177,8 +182,9 @@ class SemBuilder(object):
         # Compile according to the context
         fixed = ast.fix_missing_locations(ret)
         codeobj = compile(fixed, '<string>', 'exec')
-        ctx = self.ctx.copy()
+        ctx = self._ctx.copy()
         eval(codeobj, ctx)
 
         # Get the function back
+        self._functions[fc_ast.name] = ctx[fc_ast.name]
         return ctx[fc_ast.name]