about summary refs log tree commit diff stats
path: root/example/jitter/mips32.py
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2015-01-18 18:24:13 +0100
committerCamille Mougey <camille.mougey@cea.fr>2015-01-23 17:24:43 +0100
commit488cb99d4d61a0b3b176f7e3c53431872fc234ef (patch)
tree8d443acb6c92669cdeaa50a40af3496917a9448f /example/jitter/mips32.py
parent829f8b98a658532b40382640223c0c3ea12ab15c (diff)
downloadmiasm-488cb99d4d61a0b3b176f7e3c53431872fc234ef.tar.gz
miasm-488cb99d4d61a0b3b176f7e3c53431872fc234ef.zip
Example: Move jitter's examples to a `jitter` directory
Diffstat (limited to 'example/jitter/mips32.py')
-rw-r--r--example/jitter/mips32.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/example/jitter/mips32.py b/example/jitter/mips32.py
new file mode 100644
index 00000000..e41096cc
--- /dev/null
+++ b/example/jitter/mips32.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+from argparse import ArgumentParser
+from miasm2.analysis import debugging, gdbserver
+from miasm2.jitter.csts import *
+from miasm2.analysis.machine import Machine
+
+from pdb import pm
+
+parser = ArgumentParser(
+    description="""Sandbox raw binary with mips32 engine
+(ex: jit_mips32.py example/mips32_sc_l.bin 0)""")
+parser.add_argument("-r", "--log-regs",
+                    help="Log registers value for each instruction",
+                    action="store_true")
+parser.add_argument("-m", "--log-mn",
+                    help="Log desassembly conversion for each instruction",
+                    action="store_true")
+parser.add_argument("-n", "--log-newbloc",
+                    help="Log basic blocks processed by the Jitter",
+                    action="store_true")
+parser.add_argument("-j", "--jitter",
+                    help="Jitter engine. Possible values are : tcc (default), llvm",
+                    default="tcc")
+parser.add_argument("-d", "--debugging",
+                    help="Attach a CLI debugguer to the sandboxed programm",
+                    action="store_true")
+parser.add_argument("binary",
+                    help="binary to run")
+parser.add_argument("addr",
+                    help="start exec on addr")
+
+machine = Machine("mips32l")
+
+def code_sentinelle(jitter):
+    jitter.run = False
+    jitter.pc = 0
+    return True
+
+def jit_mips32_binary(args):
+    filepath, entryp = args.binary, int(args.addr, 16)
+    myjit = machine.jitter(jit_type = args.jitter)
+    myjit.init_stack()
+
+    # Log level (if available with jitter engine)
+    myjit.jit.log_regs = args.log_regs
+    myjit.jit.log_mn = args.log_mn
+    myjit.jit.log_newbloc = args.log_newbloc
+
+    myjit.vm.add_memory_page(0, PAGE_READ | PAGE_WRITE, open(filepath).read())
+    myjit.add_breakpoint(0x1337BEEF, code_sentinelle)
+
+
+    # for stack
+    myjit.vm.add_memory_page(0xF000, PAGE_READ | PAGE_WRITE, "\x00"*0x1000)
+
+    myjit.cpu.SP = 0xF800
+
+    myjit.cpu.RA = 0x1337BEEF
+    myjit.init_run(entryp)
+
+
+
+    # Handle debugging
+    if args.debugging is True:
+        dbg = debugging.Debugguer(myjit)
+        cmd = debugging.DebugCmd(dbg)
+        cmd.cmdloop()
+
+    else:
+        print(myjit.continue_run())
+    return myjit
+if __name__ == '__main__':
+    from sys import stderr
+    args = parser.parse_args()
+    myjit = jit_mips32_binary(args)