diff options
| author | ajax <devnull@localhost> | 2014-06-16 18:13:51 +0200 |
|---|---|---|
| committer | ajax <devnull@localhost> | 2014-06-16 18:13:51 +0200 |
| commit | 4d63f0d1a6280bd03e3061744e352cc81636f112 (patch) | |
| tree | a56fd37b7f465338dd9c787ce7c4fdb01e50d5ac /miasm2/jitter/jitcore_python.py | |
| parent | e21a663409b525fe4c720717a3681ba88795556e (diff) | |
| download | focaccia-miasm-4d63f0d1a6280bd03e3061744e352cc81636f112.tar.gz focaccia-miasm-4d63f0d1a6280bd03e3061744e352cc81636f112.zip | |
Jitter Python: Reorganize the Jit function builder
- Rewrite updates (engine and JitCpu) in subfunctions - Explode eval block in an eval_ir loop to gain more control
Diffstat (limited to 'miasm2/jitter/jitcore_python.py')
| -rw-r--r-- | miasm2/jitter/jitcore_python.py | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index e054efa5..31cf5258 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -4,6 +4,47 @@ from miasm2.expression.simplifications import expr_simp from miasm2.ir.symbexec import symbexec +################################################################################ +# Util methods for Python jitter # +################################################################################ + +def update_cpu_from_engine(cpu, exec_engine): + """Updates @cpu instance according to new CPU values + @cpu: JitCpu instance + @exec_engine: symbexec instance""" + + 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) + + +def update_engine_from_cpu(cpu, exec_engine): + """Updates CPU values according to @cpu instance + @cpu: JitCpu instance + @exec_engine: symbexec instance""" + + for symbol in exec_engine.symbols: + if isinstance(symbol, m2_expr.ExprId): + if hasattr(cpu, symbol.name): + value = m2_expr.ExprInt_fromsize(symbol.size, + getattr(cpu, symbol.name)) + exec_engine.symbols.symbols_id[symbol] = value + else: + raise NotImplementedError("Type not handled: %s" % symbol) + + +################################################################################ +# Python jitter Core # +################################################################################ + + class JitCore_Python(jitcore.JitCore): "JiT management, using Miasm2 Symbol Execution engine as backend" @@ -89,29 +130,17 @@ class JitCore_Python(jitcore.JitCore): assert(loop is not False) # Refresh CPU values according to @cpu instance - for symbol in exec_engine.symbols: - if isinstance(symbol, m2_expr.ExprId): - if hasattr(cpu, symbol.name): - value = m2_expr.ExprInt_fromsize(symbol.size, - getattr(cpu, symbol.name)) - exec_engine.symbols.symbols_id[symbol] = value - else: - raise NotImplementedError("Type not handled: %s" % symbol) + update_engine_from_cpu(cpu, exec_engine) # Execute current ir bloc - ad = expr_simp(exec_engine.emulbloc(irb)) + for ir, line in zip(irb.irs, irb.lines): + exec_engine.eval_ir(ir) + + # Get next bloc address + ad = expr_simp(exec_engine.eval_expr(irb.dst)) # 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) + update_cpu_from_engine(cpu, exec_engine) # Manage resulting address if isinstance(ad, m2_expr.ExprInt): |