diff options
Diffstat (limited to 'example/jitter')
| -rwxr-xr-x | example/jitter/arm.py | 4 | ||||
| -rwxr-xr-x | example/jitter/arm_sc.py | 4 | ||||
| -rwxr-xr-x | example/jitter/example_types.py | 5 | ||||
| -rwxr-xr-x | example/jitter/mips32.py | 5 | ||||
| -rwxr-xr-x | example/jitter/msp430.py | 4 | ||||
| -rw-r--r-- | example/jitter/run_with_linuxenv.py | 6 | ||||
| -rw-r--r-- | example/jitter/sandbox_call.py | 6 | ||||
| -rw-r--r-- | example/jitter/sandbox_elf_aarch64l.py | 4 | ||||
| -rw-r--r-- | example/jitter/sandbox_elf_ppc32.py | 4 | ||||
| -rw-r--r-- | example/jitter/sandbox_pe_x86_32.py | 5 | ||||
| -rw-r--r-- | example/jitter/sandbox_pe_x86_64.py | 4 | ||||
| -rw-r--r-- | example/jitter/test_x86_32_seh.py | 4 | ||||
| -rw-r--r-- | example/jitter/trace.py | 4 | ||||
| -rw-r--r-- | example/jitter/unpack_upx.py | 10 | ||||
| -rw-r--r-- | example/jitter/x86_32.py | 4 | ||||
| -rw-r--r-- | example/jitter/x86_64.py | 4 |
16 files changed, 56 insertions, 21 deletions
diff --git a/example/jitter/arm.py b/example/jitter/arm.py index daea2428..72fcbc49 100755 --- a/example/jitter/arm.py +++ b/example/jitter/arm.py @@ -5,6 +5,7 @@ import logging from pdb import pm from miasm.analysis.sandbox import Sandbox_Linux_arml +from miasm.core.locationdb import LocationDB # Get arguments parser = Sandbox_Linux_arml.parser(description="""Sandbox an elf binary with arm @@ -14,7 +15,8 @@ parser.add_argument('-v', "--verbose", help="verbose mode", action="store_true") options = parser.parse_args() # Prepare the sandbox -sb = Sandbox_Linux_arml(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Linux_arml(loc_db, options.filename, options, globals()) # Handle 'verbose' option if options.verbose is True: diff --git a/example/jitter/arm_sc.py b/example/jitter/arm_sc.py index 9ff770ff..20118429 100755 --- a/example/jitter/arm_sc.py +++ b/example/jitter/arm_sc.py @@ -4,6 +4,7 @@ from miasm.core.utils import int_to_byte from miasm.analysis.sandbox import Sandbox_Linux_armb_str from miasm.analysis.sandbox import Sandbox_Linux_arml_str from miasm.loader.strpatchwork import StrPatchwork +from miasm.core.locationdb import LocationDB from pdb import pm @@ -23,7 +24,8 @@ elif options.endianness == 'l': else: raise ValueError("Bad endianness!") -sb = sandbox(options.filename, options, globals()) +loc_db = LocationDB() +sb = sandbox(loc_db, options.filename, options, globals()) if options.address is None: raise ValueError('invalid address') diff --git a/example/jitter/example_types.py b/example/jitter/example_types.py index 653adaf9..af44c6d8 100755 --- a/example/jitter/example_types.py +++ b/example/jitter/example_types.py @@ -11,6 +11,9 @@ from miasm.analysis.machine import Machine from miasm.core.types import MemStruct, Self, Void, Str, Array, Ptr, \ Num, Array, set_allocator from miasm.os_dep.common import heap +from miasm.core.locationdb import LocationDB + +loc_db = LocationDB() # Instantiate a heap my_heap = heap() @@ -154,7 +157,7 @@ print() # A random jitter # You can also use miasm.jitter.VmMngr.Vm(), but it does not happen in real # life scripts, so here is the usual way: -jitter = Machine("x86_32").jitter("python") +jitter = Machine("x86_32").jitter(loc_db, "python") vm = jitter.vm # Auto-allocated by my_heap. If you allocate memory at `addr`, diff --git a/example/jitter/mips32.py b/example/jitter/mips32.py index 4aeb576f..b84dc4e5 100755 --- a/example/jitter/mips32.py +++ b/example/jitter/mips32.py @@ -5,6 +5,8 @@ from argparse import ArgumentParser from miasm.analysis import debugging from miasm.jitter.csts import * from miasm.analysis.machine import Machine +from miasm.core.locationdb import LocationDB + parser = ArgumentParser( description="""Sandbox raw binary with mips32 engine @@ -34,8 +36,9 @@ def code_sentinelle(jitter): return True def jit_mips32_binary(args): + loc_db = LocationDB() filepath, entryp = args.binary, int(args.addr, 0) - myjit = machine.jitter(jit_type = args.jitter) + myjit = machine.jitter(loc_db, jit_type = args.jitter) myjit.init_stack() # Log level (if available with jitter engine) diff --git a/example/jitter/msp430.py b/example/jitter/msp430.py index 927fb47b..887985ba 100755 --- a/example/jitter/msp430.py +++ b/example/jitter/msp430.py @@ -5,6 +5,7 @@ from argparse import ArgumentParser from miasm.analysis import debugging from miasm.jitter.csts import * from miasm.analysis.machine import Machine +from miasm.core.locationdb import LocationDB parser = ArgumentParser( description="""Sandbox raw binary with msp430 engine @@ -29,8 +30,9 @@ parser.add_argument("addr", machine = Machine("msp430") def jit_msp430_binary(args): + loc_db = LocationDB() filepath, entryp = args.binary, int(args.addr, 0) - myjit = machine.jitter(jit_type = args.jitter) + myjit = machine.jitter(loc_db, jit_type = args.jitter) # Log level (if available with jitter engine) myjit.set_trace_log( diff --git a/example/jitter/run_with_linuxenv.py b/example/jitter/run_with_linuxenv.py index 9b17b172..9290e6a8 100644 --- a/example/jitter/run_with_linuxenv.py +++ b/example/jitter/run_with_linuxenv.py @@ -7,6 +7,7 @@ from miasm.loader import elf as elf_csts from miasm.os_dep.linux import environment, syscall from miasm.analysis.machine import Machine from miasm.analysis.binary import Container +from miasm.core.locationdb import LocationDB parser = ArgumentParser("Run an ELF in a Linux-like environment") parser.add_argument("target", help="Target ELF") @@ -23,8 +24,9 @@ args = parser.parse_args() if args.verbose: syscall.log.setLevel(logging.DEBUG) +loc_db = LocationDB() # Get corresponding interpreter and reloc address -cont_target_tmp = Container.from_stream(open(args.target, 'rb')) +cont_target_tmp = Container.from_stream(open(args.target, 'rb'), loc_db) ld_path = bytes(cont_target_tmp.executable.getsectionbyname(".interp").content).strip(b"\x00") if cont_target_tmp.executable.Ehdr.type in [elf_csts.ET_REL, elf_csts.ET_DYN]: elf_base_addr = 0x40000000 @@ -35,7 +37,7 @@ else: # Instantiate a jitter machine = Machine(cont_target_tmp.arch) -jitter = machine.jitter(args.jitter) +jitter = machine.jitter(loc_db, args.jitter) jitter.init_stack() # Get elements for the target architecture diff --git a/example/jitter/sandbox_call.py b/example/jitter/sandbox_call.py index 7d400b7d..6d24777a 100644 --- a/example/jitter/sandbox_call.py +++ b/example/jitter/sandbox_call.py @@ -5,16 +5,18 @@ from miasm.analysis.sandbox import Sandbox_Linux_arml from miasm.analysis.binary import Container from miasm.os_dep.linux_stdlib import linobjs from miasm.core.utils import hexdump +from miasm.core.locationdb import LocationDB # Parse arguments parser = Sandbox_Linux_arml.parser(description="ELF sandboxer") parser.add_argument("filename", help="ELF Filename") options = parser.parse_args() -sb = Sandbox_Linux_arml(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Linux_arml(loc_db, options.filename, options, globals()) with open(options.filename, "rb") as fdesc: - cont = Container.from_stream(fdesc) + cont = Container.from_stream(fdesc, loc_db) loc_key = cont.loc_db.get_name_location("md5_starts") addr_to_call = cont.loc_db.get_location_offset(loc_key) diff --git a/example/jitter/sandbox_elf_aarch64l.py b/example/jitter/sandbox_elf_aarch64l.py index 472b2354..7ad91118 100644 --- a/example/jitter/sandbox_elf_aarch64l.py +++ b/example/jitter/sandbox_elf_aarch64l.py @@ -1,6 +1,7 @@ import logging from pdb import pm from miasm.analysis.sandbox import Sandbox_Linux_aarch64l +from miasm.core.locationdb import LocationDB from miasm.jitter.jitload import log_func # Insert here user defined methods @@ -11,7 +12,8 @@ parser.add_argument("filename", help="ELF Filename") options = parser.parse_args() # Create sandbox -sb = Sandbox_Linux_aarch64l(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Linux_aarch64l(loc_db, options.filename, options, globals()) log_func.setLevel(logging.ERROR) diff --git a/example/jitter/sandbox_elf_ppc32.py b/example/jitter/sandbox_elf_ppc32.py index 829381fc..d59181de 100644 --- a/example/jitter/sandbox_elf_ppc32.py +++ b/example/jitter/sandbox_elf_ppc32.py @@ -1,6 +1,7 @@ import os from pdb import pm from miasm.analysis.sandbox import Sandbox_Linux_ppc32b +from miasm.core.locationdb import LocationDB from miasm.jitter.csts import * from miasm.jitter.jitload import log_func import logging @@ -13,7 +14,8 @@ parser.add_argument("filename", help="ELF Filename") options = parser.parse_args() # Create sandbox -sb = Sandbox_Linux_ppc32b(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Linux_ppc32b(loc_db, options.filename, options, globals()) log_func.setLevel(logging.ERROR) sb.run() diff --git a/example/jitter/sandbox_pe_x86_32.py b/example/jitter/sandbox_pe_x86_32.py index 263fad94..de7af95d 100644 --- a/example/jitter/sandbox_pe_x86_32.py +++ b/example/jitter/sandbox_pe_x86_32.py @@ -1,6 +1,6 @@ from pdb import pm from miasm.analysis.sandbox import Sandbox_Win_x86_32 - +from miasm.core.locationdb import LocationDB # Insert here user defined methods # Parse arguments @@ -9,7 +9,8 @@ parser.add_argument("filename", help="PE Filename") options = parser.parse_args() # Create sandbox -sb = Sandbox_Win_x86_32(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Win_x86_32(loc_db, options.filename, options, globals()) # Run sb.run() diff --git a/example/jitter/sandbox_pe_x86_64.py b/example/jitter/sandbox_pe_x86_64.py index 4d8f00ce..a168c325 100644 --- a/example/jitter/sandbox_pe_x86_64.py +++ b/example/jitter/sandbox_pe_x86_64.py @@ -1,5 +1,6 @@ from pdb import pm from miasm.analysis.sandbox import Sandbox_Win_x86_64 +from miasm.core.locationdb import LocationDB # Insert here user defined methods @@ -9,7 +10,8 @@ parser.add_argument("filename", help="PE Filename") options = parser.parse_args() # Create sandbox -sb = Sandbox_Win_x86_64(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Win_x86_64(loc_db, options.filename, options, globals()) # Run sb.run() diff --git a/example/jitter/test_x86_32_seh.py b/example/jitter/test_x86_32_seh.py index d29d3a22..e2c354a0 100644 --- a/example/jitter/test_x86_32_seh.py +++ b/example/jitter/test_x86_32_seh.py @@ -1,6 +1,7 @@ import os from pdb import pm from miasm.analysis.sandbox import Sandbox_Win_x86_32 +from miasm.core.locationdb import LocationDB from miasm.os_dep import win_api_x86_32_seh from miasm.jitter.csts import * @@ -42,7 +43,8 @@ options.usesegm = True options.use_windows_structs = True # Create sandbox -sb = Sandbox_Win_x86_32(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Win_x86_32(loc_db, options.filename, options, globals()) # Install Windows SEH callbacks sb.jitter.add_exception_handler(EXCEPT_ACCESS_VIOL, deal_exception_access_violation) diff --git a/example/jitter/trace.py b/example/jitter/trace.py index 46b313c1..968626f4 100644 --- a/example/jitter/trace.py +++ b/example/jitter/trace.py @@ -14,6 +14,7 @@ from pdb import pm from miasm.analysis.sandbox import Sandbox_Linux_arml from miasm.jitter.emulatedsymbexec import EmulatedSymbExec from miasm.jitter.jitcore_python import JitCore_Python +from miasm.core.locationdb import LocationDB # Function called at each instruction instr_count = 0 @@ -45,7 +46,8 @@ JitCore_Python.SymbExecClass = ESETrackMemory # Create sandbox, forcing Python jitter options.jitter = "python" -sb = Sandbox_Linux_arml(options.filename, options, globals()) +loc_db = LocationDB() +sb = Sandbox_Linux_arml(loc_db, options.filename, options, globals()) # Force jit one instr per call, and register our callback sb.jitter.jit.set_options(jit_maxline=1, max_exec_per_call=1) diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py index 2527f0c4..59f7389a 100644 --- a/example/jitter/unpack_upx.py +++ b/example/jitter/unpack_upx.py @@ -3,6 +3,7 @@ import os import logging from miasm.analysis.sandbox import Sandbox_Win_x86_32 from miasm.jitter.loader.pe import vm2pe +from miasm.core.locationdb import LocationDB from miasm.os_dep.common import get_win_str_a @@ -41,8 +42,11 @@ parser.add_argument("--graph", options = parser.parse_args() options.load_hdr = True -sb = Sandbox_Win_x86_32(options.filename, options, globals(), - parse_reloc=False) +loc_db = LocationDB() +sb = Sandbox_Win_x86_32( + loc_db, options.filename, options, globals(), + parse_reloc=False +) if options.verbose is True: @@ -54,7 +58,7 @@ if options.verbose is True: print(sb.jitter.vm) # Ensure there is one and only one leave (for OEP discovering) -mdis = sb.machine.dis_engine(sb.jitter.bs) +mdis = sb.machine.dis_engine(sb.jitter.bs, loc_db=loc_db) mdis.dont_dis_nulstart_bloc = True asmcfg = mdis.dis_multiblock(sb.entry_point) diff --git a/example/jitter/x86_32.py b/example/jitter/x86_32.py index cee9241a..427cd021 100644 --- a/example/jitter/x86_32.py +++ b/example/jitter/x86_32.py @@ -1,6 +1,7 @@ from argparse import ArgumentParser from miasm.jitter.csts import PAGE_READ, PAGE_WRITE from miasm.analysis.machine import Machine +from miasm.core.locationdb import LocationDB from pdb import pm @@ -16,8 +17,9 @@ def code_sentinelle(jitter): jitter.pc = 0 return True +loc_db = LocationDB() -myjit = Machine("x86_32").jitter(args.jitter) +myjit = Machine("x86_32").jitter(loc_db, args.jitter) myjit.init_stack() data = open(args.filename, 'rb').read() diff --git a/example/jitter/x86_64.py b/example/jitter/x86_64.py index 78d88c18..943f5624 100644 --- a/example/jitter/x86_64.py +++ b/example/jitter/x86_64.py @@ -2,6 +2,7 @@ from argparse import ArgumentParser from pdb import pm from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_SYSCALL from miasm.analysis.machine import Machine +from miasm.core.locationdb import LocationDB # Some syscalls often used by shellcodes @@ -76,8 +77,9 @@ if __name__ == "__main__": parser.add_argument("--verbose", "-v", action="store_true", help="Verbose mode") args = parser.parse_args() + loc_db = LocationDB() - myjit = Machine("x86_64").jitter(args.jitter) + myjit = Machine("x86_64").jitter(loc_db, args.jitter) myjit.init_stack() with open(args.filename, 'rb') as f: |