diff options
| author | ajax <devnull@localhost> | 2014-06-14 23:48:40 +0200 |
|---|---|---|
| committer | ajax <devnull@localhost> | 2014-06-14 23:48:40 +0200 |
| commit | 8f3899863c3eda822fd42f2d4310b9a076f47bff (patch) | |
| tree | 6a1a4ff6a62dabc8a3c334cd2487deb43ece2fa6 /miasm2/jitter/jitcore_python.py | |
| parent | b8cbb759b6b07704dccf72fe165a6ce33230cc12 (diff) | |
| download | focaccia-miasm-8f3899863c3eda822fd42f2d4310b9a076f47bff.tar.gz focaccia-miasm-8f3899863c3eda822fd42f2d4310b9a076f47bff.zip | |
Jitter: Add basic write handling in Python Jitter
Diffstat (limited to 'miasm2/jitter/jitcore_python.py')
| -rw-r--r-- | miasm2/jitter/jitcore_python.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index ec3a479d..afa9b0fe 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -18,7 +18,9 @@ class JitCore_Python(jitcore.JitCore): for i, r in enumerate(arch.regs.all_regs_ids): symbols_init[r] = arch.regs.all_regs_ids_init[i] - self.symbexec = symbexec(arch, symbols_init, func_read = self.func_read) + self.symbexec = symbexec(arch, symbols_init, + func_read = self.func_read, + func_write = self.func_write) def func_read(self, expr_mem): """Memory read wrapper for symbolic execution @@ -27,9 +29,33 @@ class JitCore_Python(jitcore.JitCore): addr = expr_mem.arg.arg.arg size = expr_mem.size / 8 value = self.vmmngr.vm_get_mem(addr, size) + return m2_expr.ExprInt_fromsize(expr_mem.size, int(value[::-1].encode("hex"), 16)) + def func_write(self, symb_exec, dest, data, mem_cache): + """Memory read wrapper for symbolic execution + @symb_exec: symbexec instance + @dest: ExprMem instance + @data: Expr instance + @mem_cache: dict""" + + # Get the content to write + data = expr_simp(data) + if not isinstance(data, m2_expr.ExprInt): + raise NotImplementedError("A simplification is missing: %s" % data) + to_write = data.arg.arg + + # Format information + addr = dest.arg.arg.arg + size = data.size / 8 + content = hex(to_write).replace("0x", "").replace("L", "") + content = "0" * (size * 2 - len(content)) + content + content = content.decode("hex")[::-1] + + # Write in VmMngr context + self.vmmngr.vm_set_mem(addr, content) + def jitirblocs(self, label, irblocs): """Create a python function corresponding to an irblocs' group. @label: the label of the irblocs @@ -74,6 +100,18 @@ class JitCore_Python(jitcore.JitCore): # Execute current ir bloc ad = expr_simp(exec_engine.emulbloc(irb)) + # Updates @cpu instance according to new CPU values + for symbol in exec_engine.symbols: + if isinstance(symbol, m2_expr.ExprId): + if hasattr(cpu, symbol.name): + value = exec_engine.symbols.symbols_id[symbol] + if not isinstance(value, m2_expr.ExprInt): + raise ValueError("A simplification is missing: %s" % value) + + setattr(cpu, symbol.name, value.arg.arg) + else: + raise NotImplementedError("Type not handled: %s" % symbol) + # Manage resulting address if isinstance(ad, m2_expr.ExprInt): return ad.arg.arg |