mirror of
https://github.com/cea-sec/miasm
synced 2026-08-17 10:26:03 -04:00
Avoid generate default locationdb
This commit is contained in:
parent
5d8beb271d
commit
80e40a3d2c
77 changed files with 426 additions and 321 deletions
|
|
@ -172,7 +172,7 @@ Import the shellcode thanks to the `Container` abstraction:
|
|||
|
||||
```pycon
|
||||
>>> from miasm.analysis.binary import Container
|
||||
>>> c = Container.from_string(s)
|
||||
>>> c = Container.from_string(s, loc_db)
|
||||
>>> c
|
||||
<miasm.analysis.binary.ContainerUnknown object at 0x7f34cefe6090>
|
||||
```
|
||||
|
|
@ -182,7 +182,7 @@ Disassembling the shellcode at address `0`:
|
|||
```pycon
|
||||
>>> from miasm.analysis.machine import Machine
|
||||
>>> machine = Machine('x86_32')
|
||||
>>> mdis = machine.dis_engine(c.bin_stream)
|
||||
>>> mdis = machine.dis_engine(c.bin_stream, loc_db=loc_db)
|
||||
>>> asmcfg = mdis.dis_multiblock(0)
|
||||
>>> for block in asmcfg.blocks:
|
||||
... print(block.to_string(asmcfg.loc_db))
|
||||
|
|
@ -208,7 +208,7 @@ RET
|
|||
Initializing the Jit engine with a stack:
|
||||
|
||||
```pycon
|
||||
>>> jitter = machine.jitter(jit_type='python')
|
||||
>>> jitter = machine.jitter(loc_db, jit_type='python')
|
||||
>>> jitter.init_stack()
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ with open(args.source) as fstream:
|
|||
|
||||
loc_db = LocationDB()
|
||||
|
||||
asmcfg, loc_db = parse_asm.parse_txt(machine.mn, attrib, source, loc_db)
|
||||
asmcfg = parse_asm.parse_txt(machine.mn, attrib, source, loc_db)
|
||||
|
||||
# Fix shellcode addrs
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), addr_main)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ from pprint import pprint
|
|||
|
||||
from miasm.arch.x86.arch import mn_x86
|
||||
from miasm.core import parse_asm, asmblock
|
||||
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Assemble code
|
||||
asmcfg, loc_db = parse_asm.parse_txt(mn_x86, 32, '''
|
||||
loc_db = LocationDB()
|
||||
asmcfg = parse_asm.parse_txt(
|
||||
mn_x86, 32, '''
|
||||
main:
|
||||
MOV EAX, 1
|
||||
MOV EBX, 2
|
||||
|
|
@ -20,7 +22,9 @@ loop:
|
|||
ADD EAX, ECX
|
||||
JZ loop
|
||||
RET
|
||||
''')
|
||||
''',
|
||||
loc_db
|
||||
)
|
||||
|
||||
# Set 'main' loc_key's offset
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from __future__ import print_function
|
|||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.asmblock import AsmConstraint
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
def cb_x86_callpop(mdis, cur_bloc, offset_to_dis):
|
||||
|
|
@ -50,8 +51,9 @@ shellcode = (
|
|||
|
||||
# Instantiate a x86 32 bit architecture
|
||||
machine = Machine("x86_32")
|
||||
cont = Container.from_string(shellcode)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
loc_db = LocationDB()
|
||||
cont = Container.from_string(shellcode, loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
|
||||
print("Without callback:\n")
|
||||
asmcfg = mdis.dis_multiblock(0)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ from __future__ import print_function
|
|||
import sys
|
||||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
fdesc = open(sys.argv[1], 'rb')
|
||||
loc_db = LocationDB()
|
||||
|
||||
# The Container will provide a *bin_stream*, bytes source for the disasm engine
|
||||
# It will prodive a view from a PE or an ELF.
|
||||
cont = Container.from_stream(fdesc)
|
||||
cont = Container.from_stream(fdesc, loc_db)
|
||||
|
||||
# The Machine, instantiated with the detected architecture, will provide tools
|
||||
# (disassembler, etc.) to work with this architecture
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@ import sys
|
|||
from future.utils import viewvalues
|
||||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
#####################################
|
||||
# Common section from dis_binary.py #
|
||||
#####################################
|
||||
|
||||
fdesc = open(sys.argv[1], 'rb')
|
||||
loc_db = LocationDB()
|
||||
|
||||
cont = Container.from_stream(fdesc)
|
||||
cont = Container.from_stream(fdesc, loc_db)
|
||||
|
||||
machine = Machine(cont.arch)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@ import sys
|
|||
from future.utils import viewvalues
|
||||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
#####################################
|
||||
# Common section from dis_binary.py #
|
||||
#####################################
|
||||
|
||||
fdesc = open(sys.argv[1], 'rb')
|
||||
loc_db = LocationDB()
|
||||
|
||||
cont = Container.from_stream(fdesc)
|
||||
cont = Container.from_stream(fdesc, loc_db)
|
||||
|
||||
machine = Machine(cont.arch)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
from __future__ import print_function
|
||||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# The Container will provide a *bin_stream*, bytes source for the disasm engine
|
||||
cont = Container.from_string(b"\x83\xf8\x10\x74\x07\x89\xc6\x0f\x47\xc3\xeb\x08\x89\xc8\xe8\x31\x33\x22\x11\x40\xc3")
|
||||
loc_db = LocationDB()
|
||||
cont = Container.from_string(
|
||||
b"\x83\xf8\x10\x74\x07\x89\xc6\x0f\x47\xc3\xeb\x08\x89\xc8\xe8\x31\x33\x22\x11\x40\xc3",
|
||||
loc_db
|
||||
)
|
||||
|
||||
# Instantiate a x86 32 bit architecture
|
||||
machine = Machine("x86_32")
|
||||
|
||||
# Instantiate a disassembler engine, using the previous bin_stream and its
|
||||
# associated location DB.
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
|
||||
# Run a recursive traversal disassembling from address 0
|
||||
asmcfg = mdis.dis_multiblock(0)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from miasm.expression.simplifications import expr_simp
|
|||
from miasm.analysis.ssa import SSADiGraph
|
||||
from miasm.ir.ir import AssignBlock, IRBlock
|
||||
from miasm.analysis.simplifier import IRCFGSimplifierCommon, IRCFGSimplifierSSA
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
log = logging.getLogger("dis")
|
||||
console_handler = logging.StreamHandler()
|
||||
|
|
@ -75,13 +76,20 @@ args = parser.parse_args()
|
|||
if args.verbose:
|
||||
log_asmblock.setLevel(logging.DEBUG)
|
||||
|
||||
loc_db = LocationDB()
|
||||
log.info('Load binary')
|
||||
if args.rawbinary:
|
||||
cont = Container.fallback_container(open(args.filename, "rb").read(),
|
||||
vm=None, addr=args.base_address)
|
||||
cont = Container.fallback_container(
|
||||
open(args.filename, "rb").read(),
|
||||
vm=None, addr=args.base_address,
|
||||
loc_db=loc_db,
|
||||
)
|
||||
else:
|
||||
with open(args.filename, "rb") as fdesc:
|
||||
cont = Container.from_stream(fdesc, addr=args.base_address)
|
||||
cont = Container.from_stream(
|
||||
fdesc, addr=args.base_address,
|
||||
loc_db=loc_db,
|
||||
)
|
||||
|
||||
default_addr = cont.entry_point
|
||||
bs = cont.bin_stream
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ from miasm.arch.x86.ctype import CTypeAMD64_unk
|
|||
from miasm.core.objc import ExprToAccessC, CHandler
|
||||
from miasm.core.objc import CTypesManagerNotPacked
|
||||
from miasm.core.ctypesmngr import CAstTypes, CTypePtr, CTypeStruct
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
def find_call(ircfg):
|
||||
"""Returns (irb, index) which call"""
|
||||
|
|
@ -116,6 +118,7 @@ class MyCHandler(CHandler):
|
|||
|
||||
|
||||
|
||||
loc_db = LocationDB()
|
||||
data = open(sys.argv[1], 'rb').read()
|
||||
# Digest C information
|
||||
text = """
|
||||
|
|
@ -143,12 +146,12 @@ cont = Container.fallback_container(data, None, addr=0)
|
|||
machine = Machine("x86_64")
|
||||
dis_engine, ira = machine.dis_engine, machine.ira
|
||||
|
||||
mdis = dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
mdis = dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
addr_head = 0
|
||||
asmcfg = mdis.dis_multiblock(addr_head)
|
||||
lbl_head = mdis.loc_db.get_offset_location(addr_head)
|
||||
lbl_head = loc_db.get_offset_location(addr_head)
|
||||
|
||||
ir_arch_a = ira(mdis.loc_db)
|
||||
ir_arch_a = ira(loc_db)
|
||||
ircfg = ir_arch_a.new_ircfg_from_asmcfg(asmcfg)
|
||||
|
||||
open('graph_irflow.dot', 'w').write(ircfg.dot())
|
||||
|
|
|
|||
|
|
@ -9,10 +9,13 @@ from miasm.expression.expression import *
|
|||
from miasm.core import asmblock
|
||||
from miasm.arch.x86.ira import ir_a_x86_32
|
||||
from miasm.analysis.data_flow import DeadRemoval
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
# First, asm code
|
||||
asmcfg, loc_db = parse_asm.parse_txt(mn_x86, 32, '''
|
||||
loc_db = LocationDB()
|
||||
asmcfg = parse_asm.parse_txt(
|
||||
mn_x86, 32, '''
|
||||
main:
|
||||
MOV EAX, 1
|
||||
MOV EBX, 2
|
||||
|
|
@ -25,7 +28,9 @@ loop:
|
|||
ADD EAX, ECX
|
||||
JZ loop
|
||||
RET
|
||||
''')
|
||||
''',
|
||||
loc_db
|
||||
)
|
||||
|
||||
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ from miasm.analysis.cst_propag import propagate_cst_expr
|
|||
from miasm.analysis.data_flow import DeadRemoval, \
|
||||
merge_blocks, remove_empty_assignblks
|
||||
from miasm.expression.simplifications import expr_simp
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
|
||||
parser = ArgumentParser("Constant expression propagation")
|
||||
|
|
@ -25,8 +27,9 @@ args = parser.parse_args()
|
|||
|
||||
machine = Machine("x86_32")
|
||||
|
||||
cont = Container.from_stream(open(args.filename, 'rb'))
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
loc_db = LocationDB()
|
||||
cont = Container.from_stream(open(args.filename, 'rb'), loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
ir_arch = machine.ira(mdis.loc_db)
|
||||
addr = int(args.address, 0)
|
||||
deadrm = DeadRemoval(ir_arch)
|
||||
|
|
|
|||
|
|
@ -6,18 +6,19 @@ from miasm.analysis.machine import Machine
|
|||
from miasm.jitter.llvmconvert import LLVMType, LLVMContext_IRCompilation, LLVMFunction_IRCompilation
|
||||
from llvmlite import ir as llvm_ir
|
||||
from miasm.expression.simplifications import expr_simp_high_to_explicit
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
parser = ArgumentParser("LLVM export example")
|
||||
parser.add_argument("target", help="Target binary")
|
||||
parser.add_argument("addr", help="Target address")
|
||||
parser.add_argument("--architecture", "-a", help="Force architecture")
|
||||
args = parser.parse_args()
|
||||
|
||||
loc_db = LocationDB()
|
||||
# This part focus on obtaining an IRCFG to transform #
|
||||
cont = Container.from_stream(open(args.target, 'rb'))
|
||||
cont = Container.from_stream(open(args.target, 'rb'), loc_db)
|
||||
machine = Machine(args.architecture if args.architecture else cont.arch)
|
||||
ir = machine.ir(cont.loc_db)
|
||||
dis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
ir = machine.ir(loc_db)
|
||||
dis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
asmcfg = dis.dis_multiblock(int(args.addr, 0))
|
||||
ircfg = ir.new_ircfg_from_asmcfg(asmcfg)
|
||||
ircfg.simplify(expr_simp_high_to_explicit)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from miasm.analysis.data_analysis import intra_block_flow_raw, inter_block_flow
|
|||
from miasm.core.graph import DiGraph
|
||||
from miasm.ir.symbexec import SymbolicExecutionEngine
|
||||
from miasm.analysis.data_flow import DeadRemoval
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
parser = ArgumentParser("Simple expression use for generating dataflow graph")
|
||||
|
|
@ -126,19 +127,19 @@ def gen_block_data_flow_graph(ir_arch, ircfg, ad, block_flow_cb):
|
|||
|
||||
|
||||
ad = int(args.addr, 16)
|
||||
|
||||
loc_db = LocationDB()
|
||||
print('disasm...')
|
||||
cont = Container.from_stream(open(args.filename, 'rb'))
|
||||
cont = Container.from_stream(open(args.filename, 'rb'), loc_db)
|
||||
machine = Machine("x86_32")
|
||||
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
mdis.follow_call = True
|
||||
asmcfg = mdis.dis_multiblock(ad)
|
||||
print('ok')
|
||||
|
||||
|
||||
print('generating dataflow graph for:')
|
||||
ir_arch_analysis = machine.ira(mdis.loc_db)
|
||||
ir_arch_analysis = machine.ira(loc_db)
|
||||
ircfg = ir_arch_analysis.new_ircfg_from_asmcfg(asmcfg)
|
||||
deadrm = DeadRemoval(ir_arch_analysis)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from miasm.ir.symbexec import SymbolicExecutionEngine, get_block
|
|||
from miasm.expression.simplifications import expr_simp
|
||||
from miasm.core import parse_asm
|
||||
from miasm.ir.translators.translator import Translator
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
machine = Machine("x86_32")
|
||||
|
||||
|
|
@ -79,24 +80,26 @@ def emul_symb(ir_arch, ircfg, mdis, states_todo, states_done):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
loc_db = LocationDB()
|
||||
translator_smt2 = Translator.to_language("smt2")
|
||||
|
||||
addr = int(options.address, 16)
|
||||
|
||||
cont = Container.from_stream(open(args[0], 'rb'))
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
cont = Container.from_stream(open(args[0], 'rb'), loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
ir_arch = machine.ir(mdis.loc_db)
|
||||
ircfg = ir_arch.new_ircfg()
|
||||
symbexec = SymbolicExecutionEngine(ir_arch)
|
||||
|
||||
asmcfg, loc_db = parse_asm.parse_txt(machine.mn, 32, '''
|
||||
asmcfg = parse_asm.parse_txt(
|
||||
machine.mn, 32, '''
|
||||
init:
|
||||
PUSH argv
|
||||
PUSH argc
|
||||
PUSH ret_addr
|
||||
''',
|
||||
loc_db=mdis.loc_db)
|
||||
loc_db
|
||||
)
|
||||
|
||||
|
||||
argc_lbl = loc_db.get_name_location('argc')
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from miasm.analysis.machine import Machine
|
|||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.depgraph import DependencyGraph
|
||||
from miasm.expression.expression import ExprMem, ExprId, ExprInt
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
parser = ArgumentParser("Dependency grapher")
|
||||
parser.add_argument("filename", help="Binary to analyse")
|
||||
|
|
@ -33,10 +34,10 @@ parser.add_argument("--json",
|
|||
help="Output solution in JSON",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
loc_db = LocationDB()
|
||||
# Get architecture
|
||||
with open(args.filename, "rb") as fstream:
|
||||
cont = Container.from_stream(fstream)
|
||||
cont = Container.from_stream(fstream, loc_db)
|
||||
|
||||
arch = args.architecture if args.architecture else cont.arch
|
||||
machine = Machine(arch)
|
||||
|
|
@ -50,8 +51,8 @@ for element in args.element:
|
|||
except KeyError:
|
||||
raise ValueError("Unknown element '%s'" % element)
|
||||
|
||||
mdis = machine.dis_engine(cont.bin_stream, dont_dis_nulstart_bloc=True)
|
||||
ir_arch = machine.ira(mdis.loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, dont_dis_nulstart_bloc=True, loc_db=loc_db)
|
||||
ir_arch = machine.ira(loc_db)
|
||||
|
||||
# Common argument forms
|
||||
init_ctx = {}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
|||
from miasm.analysis.sandbox import Sandbox_Linux_x86_64
|
||||
from miasm.expression.expression import *
|
||||
from miasm.os_dep.win_api_x86_32 import get_win_str_a
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
is_win = platform.system() == "Windows"
|
||||
|
||||
|
|
@ -75,7 +76,8 @@ parser.add_argument("--strategy",
|
|||
options = parser.parse_args()
|
||||
options.mimic_env = True
|
||||
options.command_line = ["%s" % TEMP_FILE.name]
|
||||
sb = Sandbox_Linux_x86_64(options.filename, options, globals())
|
||||
loc_db = LocationDB()
|
||||
sb = Sandbox_Linux_x86_64(loc_db, options.filename, options, globals())
|
||||
|
||||
# Init segment
|
||||
sb.jitter.ir_arch.do_stk_segm = True
|
||||
|
|
@ -238,7 +240,7 @@ strategy = {
|
|||
"branch-cov": DSEPathConstraint.PRODUCE_SOLUTION_BRANCH_COV,
|
||||
"path-cov": DSEPathConstraint.PRODUCE_SOLUTION_PATH_COV,
|
||||
}[options.strategy]
|
||||
dse = DSEPathConstraint(machine, produce_solution=strategy)
|
||||
dse = DSEPathConstraint(machine, loc_db, produce_solution=strategy)
|
||||
|
||||
# Attach to the jitter
|
||||
dse.attach(sb.jitter)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ from miasm.analysis.machine import Machine
|
|||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.analysis.dse import DSEPathConstraint
|
||||
from miasm.expression.expression import ExprMem, ExprId, ExprInt, ExprAssign
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Argument handling
|
||||
parser = ArgumentParser("DSE Example")
|
||||
|
|
@ -41,10 +42,12 @@ strategy = {
|
|||
"path-cov": DSEPathConstraint.PRODUCE_SOLUTION_PATH_COV,
|
||||
}[args.strategy]
|
||||
|
||||
loc_db = LocationDB()
|
||||
|
||||
# Map the shellcode
|
||||
run_addr = 0x40000
|
||||
machine = Machine("x86_32")
|
||||
jitter = machine.jitter("python")
|
||||
jitter = machine.jitter(loc_db, "python")
|
||||
with open(args.filename, "rb") as fdesc:
|
||||
jitter.vm.add_memory_page(
|
||||
run_addr,
|
||||
|
|
@ -72,7 +75,7 @@ jitter.push_uint32_t(ret_addr)
|
|||
jitter.init_run(run_addr)
|
||||
|
||||
# Init a DSE instance with a given strategy
|
||||
dse = DSEPathConstraint(machine, produce_solution=strategy)
|
||||
dse = DSEPathConstraint(machine, loc_db, produce_solution=strategy)
|
||||
dse.attach(jitter)
|
||||
# Concretize everything except the argument
|
||||
dse.update_state_from_concrete()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import warnings
|
|||
|
||||
from miasm.core.bin_stream import bin_stream_str, bin_stream_elf, bin_stream_pe
|
||||
from miasm.jitter.csts import PAGE_READ
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
log = logging.getLogger("binary")
|
||||
|
|
@ -35,15 +34,16 @@ class Container(object):
|
|||
fallback_container = None # Fallback container format
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, data, *args, **kwargs):
|
||||
def from_string(cls, data, loc_db, *args, **kwargs):
|
||||
"""Instantiate a container and parse the binary
|
||||
@data: str containing the binary
|
||||
@loc_db: LocationDB instance
|
||||
"""
|
||||
log.info('Load binary')
|
||||
# Try each available format
|
||||
for container_type in cls.available_container:
|
||||
try:
|
||||
return container_type(data, *args, **kwargs)
|
||||
return container_type(data, loc_db, *args, **kwargs)
|
||||
except ContainerSignatureException:
|
||||
continue
|
||||
except ContainerParsingException as error:
|
||||
|
|
@ -51,7 +51,7 @@ class Container(object):
|
|||
|
||||
# Fallback mode
|
||||
log.warning('Fallback to string input')
|
||||
return cls.fallback_container(data, *args, **kwargs)
|
||||
return cls.fallback_container(data, loc_db, *args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def register_container(cls, container):
|
||||
|
|
@ -79,17 +79,14 @@ class Container(object):
|
|||
"""
|
||||
raise NotImplementedError("Abstract method")
|
||||
|
||||
def __init__(self, data, loc_db=None, **kwargs):
|
||||
def __init__(self, data, loc_db, **kwargs):
|
||||
"Alias for 'parse'"
|
||||
# Init attributes
|
||||
self._executable = None
|
||||
self._bin_stream = None
|
||||
self._entry_point = None
|
||||
self._arch = None
|
||||
if loc_db is None:
|
||||
self._loc_db = LocationDB()
|
||||
else:
|
||||
self._loc_db = loc_db
|
||||
self._loc_db = loc_db
|
||||
|
||||
# Launch parsing
|
||||
self.parse(data, **kwargs)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from future.utils import viewitems
|
|||
from miasm.expression.expression import ExprInt, ExprLoc, ExprAssign, \
|
||||
ExprWalk, canonize_to_exprloc
|
||||
from miasm.core.graph import DiGraph
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.expression.simplifications import expr_simp_explicit
|
||||
from miasm.ir.symbexec import SymbolicExecutionEngine
|
||||
from miasm.ir.ir import IRBlock, AssignBlock
|
||||
|
|
@ -309,7 +308,7 @@ class DependencyResult(DependencyState):
|
|||
line_nb).assignblks
|
||||
|
||||
# Eval the block
|
||||
loc_db = LocationDB()
|
||||
loc_db = ir_arch.loc_db
|
||||
temp_loc = loc_db.get_or_create_name_location("Temp")
|
||||
symb_exec = SymbolicExecutionEngine(ir_arch, ctx_init)
|
||||
symb_exec.eval_updt_irblock(IRBlock(temp_loc, assignblks), step=step)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ from miasm.core.locationdb import LocationDB
|
|||
from miasm.core.utils import upck32
|
||||
|
||||
|
||||
def get_ira(mnemo, attrib):
|
||||
arch = mnemo.name, attrib
|
||||
def get_ira(arch, attrib):
|
||||
arch = arch.name, attrib
|
||||
if arch == ("arm", "arm"):
|
||||
from miasm.arch.arm.ira import ir_a_arm_base as ira
|
||||
elif arch == ("x86", 32):
|
||||
|
|
@ -20,20 +20,20 @@ def get_ira(mnemo, attrib):
|
|||
elif arch == ("x86", 64):
|
||||
from miasm.arch.x86.ira import ir_a_x86_64 as ira
|
||||
else:
|
||||
raise ValueError('unknown architecture: %s' % mnemo.name)
|
||||
raise ValueError('unknown architecture: %s' % arch.name)
|
||||
return ira
|
||||
|
||||
|
||||
def arm_guess_subcall(
|
||||
mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, loc_db):
|
||||
ira = get_ira(mnemo, attrib)
|
||||
def arm_guess_subcall(dis_engine, cur_block, offsets_to_dis):
|
||||
arch = dis_engine.arch
|
||||
loc_db = dis_engine.loc_db
|
||||
ira = get_ira(arch, dis_engine.attrib)
|
||||
|
||||
sp = LocationDB()
|
||||
ir_arch = ira(sp)
|
||||
ir_arch = ira(loc_db)
|
||||
ircfg = ira.new_ircfg()
|
||||
print('###')
|
||||
print(cur_bloc)
|
||||
ir_arch.add_asmblock_to_ircfg(cur_bloc, ircfg)
|
||||
print(cur_block)
|
||||
ir_arch.add_asmblock_to_ircfg(cur_block, ircfg)
|
||||
|
||||
to_add = set()
|
||||
for irblock in viewvalues(ircfg.blocks):
|
||||
|
|
@ -43,14 +43,14 @@ def arm_guess_subcall(
|
|||
for e in exprs:
|
||||
if e.dst == ir_arch.pc:
|
||||
pc_val = e.src
|
||||
if e.dst == mnemo.regs.LR:
|
||||
if e.dst == arch.regs.LR:
|
||||
lr_val = e.src
|
||||
if pc_val is None or lr_val is None:
|
||||
continue
|
||||
if not isinstance(lr_val, ExprInt):
|
||||
continue
|
||||
|
||||
l = cur_bloc.lines[-1]
|
||||
l = cur_block.lines[-1]
|
||||
if lr_val.arg != l.offset + l.l:
|
||||
continue
|
||||
l = loc_db.get_or_create_offset_location(int(lr_val))
|
||||
|
|
@ -60,20 +60,20 @@ def arm_guess_subcall(
|
|||
offsets_to_dis.add(int(lr_val))
|
||||
|
||||
for c in to_add:
|
||||
cur_bloc.addto(c)
|
||||
cur_block.addto(c)
|
||||
|
||||
|
||||
def arm_guess_jump_table(
|
||||
mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, loc_db):
|
||||
ira = get_ira(mnemo, attrib)
|
||||
def arm_guess_jump_table(dis_engine, cur_block, offsets_to_dis):
|
||||
arch = dis_engine.arch
|
||||
loc_db = dis_engine.loc_db
|
||||
ira = get_ira(arch, dis_engine.attrib)
|
||||
|
||||
jra = ExprId('jra')
|
||||
jrb = ExprId('jrb')
|
||||
|
||||
sp = LocationDB()
|
||||
ir_arch = ira(sp)
|
||||
ir_arch = ira(loc_db)
|
||||
ircfg = ira.new_ircfg()
|
||||
ir_arch.add_asmblock_to_ircfg(cur_bloc, ircfg)
|
||||
ir_arch.add_asmblock_to_ircfg(cur_block, ircfg)
|
||||
|
||||
for irblock in viewvalues(ircfg.blocks):
|
||||
pc_val = None
|
||||
|
|
@ -105,7 +105,7 @@ def arm_guess_jump_table(
|
|||
while i < max_table_entry:
|
||||
i += 1
|
||||
try:
|
||||
ad = upck32(pool_bin.getbytes(base_ad + 4 * i, 4))
|
||||
ad = upck32(dis_engine.bin_stream.getbytes(base_ad + 4 * i, 4))
|
||||
except:
|
||||
break
|
||||
if abs(ad - base_ad) > max_diff_addr:
|
||||
|
|
@ -117,12 +117,11 @@ def arm_guess_jump_table(
|
|||
offsets_to_dis.add(ad)
|
||||
l = loc_db.get_or_create_offset_location(ad)
|
||||
c = AsmConstraintTo(l)
|
||||
cur_bloc.addto(c)
|
||||
cur_block.addto(c)
|
||||
|
||||
guess_funcs = []
|
||||
|
||||
|
||||
def guess_multi_cb(
|
||||
mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, loc_db):
|
||||
def guess_multi_cb(dis_engine, cur_block, offsets_to_dis):
|
||||
for f in guess_funcs:
|
||||
f(mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, loc_db)
|
||||
f(dis_engine, cur_block, offsets_to_dis)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ from miasm.expression.expression_helper import possible_values
|
|||
from miasm.ir.translators import Translator
|
||||
from miasm.analysis.expression_range import expr_range
|
||||
from miasm.analysis.modularintervals import ModularIntervals
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
DriftInfo = namedtuple("DriftInfo", ["symbol", "computed", "expected"])
|
||||
|
||||
|
|
@ -162,9 +161,9 @@ class DSEEngine(object):
|
|||
"""
|
||||
SYMB_ENGINE = ESETrackModif
|
||||
|
||||
def __init__(self, machine):
|
||||
def __init__(self, machine, loc_db):
|
||||
self.machine = machine
|
||||
self.loc_db = LocationDB()
|
||||
self.loc_db = loc_db
|
||||
self.handler = {} # addr -> callback(DSEEngine instance)
|
||||
self.instrumentation = {} # addr -> callback(DSEEngine instance)
|
||||
self.addr_to_cacheblocks = {} # addr -> {label -> IRBlock}
|
||||
|
|
@ -527,13 +526,13 @@ class DSEPathConstraint(DSEEngine):
|
|||
PRODUCE_SOLUTION_BRANCH_COV = 2
|
||||
PRODUCE_SOLUTION_PATH_COV = 3
|
||||
|
||||
def __init__(self, machine, produce_solution=PRODUCE_SOLUTION_CODE_COV,
|
||||
def __init__(self, machine, loc_db, produce_solution=PRODUCE_SOLUTION_CODE_COV,
|
||||
known_solutions=None,
|
||||
**kwargs):
|
||||
"""Init a DSEPathConstraint
|
||||
@machine: Machine of the targeted architecture instance
|
||||
@produce_solution: (optional) if set, new solutions will be computed"""
|
||||
super(DSEPathConstraint, self).__init__(machine, **kwargs)
|
||||
super(DSEPathConstraint, self).__init__(machine, loc_db, **kwargs)
|
||||
|
||||
# Dependency check
|
||||
assert z3 is not None
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Sandbox(object):
|
|||
|
||||
classes = property(lambda x: x.__class__._classes_())
|
||||
|
||||
def __init__(self, fname, options, custom_methods=None, **kwargs):
|
||||
def __init__(self, loc_db, fname, options, custom_methods=None, **kwargs):
|
||||
"""
|
||||
Initialize a sandbox
|
||||
@fname: str file name
|
||||
|
|
@ -54,8 +54,10 @@ class Sandbox(object):
|
|||
assert isinstance(fname, basestring)
|
||||
self.fname = fname
|
||||
self.options = options
|
||||
self.loc_db = loc_db
|
||||
if custom_methods is None:
|
||||
custom_methods = {}
|
||||
kwargs["loc_db"] = loc_db
|
||||
for cls in self.classes:
|
||||
if cls == Sandbox:
|
||||
continue
|
||||
|
|
@ -171,9 +173,9 @@ class Arch(object):
|
|||
# Architecture name
|
||||
_ARCH_ = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
self.machine = Machine(self._ARCH_)
|
||||
self.jitter = self.machine.jitter(self.options.jitter)
|
||||
self.jitter = self.machine.jitter(loc_db, self.options.jitter)
|
||||
|
||||
@classmethod
|
||||
def update_parser(cls, parser):
|
||||
|
|
@ -384,8 +386,8 @@ class Arch_x86(Arch):
|
|||
STACK_SIZE = 0x10000
|
||||
STACK_BASE = 0x130000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_x86, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_x86, self).__init__(loc_db, **kwargs)
|
||||
|
||||
if self.options.usesegm:
|
||||
self.jitter.ir_arch.do_stk_segm = True
|
||||
|
|
@ -417,8 +419,8 @@ class Arch_arml(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_arml, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_arml, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -431,8 +433,8 @@ class Arch_armb(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_armb, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_armb, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -445,8 +447,8 @@ class Arch_armtl(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_armtl, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_armtl, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -459,8 +461,8 @@ class Arch_mips32b(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_mips32b, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_mips32b, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -473,8 +475,8 @@ class Arch_aarch64l(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_aarch64l, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_aarch64l, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -487,8 +489,8 @@ class Arch_aarch64b(Arch):
|
|||
STACK_SIZE = 0x100000
|
||||
STACK_BASE = 0x100000
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Arch_aarch64b, self).__init__(**kwargs)
|
||||
def __init__(self, loc_db, **kwargs):
|
||||
super(Arch_aarch64b, self).__init__(loc_db, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
@ -506,8 +508,8 @@ class Arch_ppc32b(Arch_ppc32):
|
|||
|
||||
class Sandbox_Win_x86_32(Sandbox, Arch_x86_32, OS_Win):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
self.jitter.push_uint32_t(2)
|
||||
|
|
@ -538,8 +540,8 @@ class Sandbox_Win_x86_32(Sandbox, Arch_x86_32, OS_Win):
|
|||
|
||||
class Sandbox_Win_x86_64(Sandbox, Arch_x86_64, OS_Win):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# reserve stack for local reg
|
||||
for _ in range(0x4):
|
||||
|
|
@ -574,8 +576,8 @@ class Sandbox_Win_x86_64(Sandbox, Arch_x86_64, OS_Win):
|
|||
|
||||
class Sandbox_Linux_x86_32(Sandbox, Arch_x86_32, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -634,8 +636,8 @@ class Sandbox_Linux_x86_32(Sandbox, Arch_x86_32, OS_Linux):
|
|||
|
||||
class Sandbox_Linux_x86_64(Sandbox, Arch_x86_64, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -693,8 +695,8 @@ class Sandbox_Linux_x86_64(Sandbox, Arch_x86_64, OS_Linux):
|
|||
|
||||
class Sandbox_Linux_arml(Sandbox, Arch_arml, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -751,8 +753,8 @@ class Sandbox_Linux_arml(Sandbox, Arch_arml, OS_Linux):
|
|||
|
||||
class Sandbox_Linux_armtl(Sandbox, Arch_armtl, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -810,8 +812,8 @@ class Sandbox_Linux_armtl(Sandbox, Arch_armtl, OS_Linux):
|
|||
|
||||
class Sandbox_Linux_mips32b(Sandbox, Arch_mips32b, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -865,8 +867,8 @@ class Sandbox_Linux_mips32b(Sandbox, Arch_mips32b, OS_Linux):
|
|||
|
||||
class Sandbox_Linux_armb_str(Sandbox, Arch_armb, OS_Linux_str):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
self.jitter.cpu.LR = self.CALL_FINISH_ADDR
|
||||
|
||||
|
|
@ -881,8 +883,8 @@ class Sandbox_Linux_armb_str(Sandbox, Arch_armb, OS_Linux_str):
|
|||
|
||||
class Sandbox_Linux_arml_str(Sandbox, Arch_arml, OS_Linux_str):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
self.jitter.cpu.LR = self.CALL_FINISH_ADDR
|
||||
|
||||
|
|
@ -897,8 +899,8 @@ class Sandbox_Linux_arml_str(Sandbox, Arch_arml, OS_Linux_str):
|
|||
|
||||
class Sandbox_Linux_aarch64l(Sandbox, Arch_aarch64l, OS_Linux):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Sandbox.__init__(self, *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Sandbox.__init__(self, loc_db, *args, **kwargs)
|
||||
|
||||
# Pre-stack some arguments
|
||||
if self.options.mimic_env:
|
||||
|
|
@ -957,8 +959,8 @@ class Sandbox_Linux_ppc32b(Sandbox, Arch_ppc32b, OS_Linux):
|
|||
# The glue between the kernel and the ELF ABI on Linux/PowerPC is
|
||||
# implemented in glibc/sysdeps/powerpc/powerpc32/dl-start.S, so we
|
||||
# have to play the role of ld.so here.
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Sandbox_Linux_ppc32b, self).__init__(*args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
super(Sandbox_Linux_ppc32b, self).__init__(loc_db, *args, **kwargs)
|
||||
|
||||
# Init stack
|
||||
self.jitter.stack_size = self.STACK_SIZE
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ from builtins import range
|
|||
import logging
|
||||
|
||||
from miasm.jitter.jitload import Jitter, named_arguments
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.core.utils import pck64, upck64
|
||||
from miasm.arch.aarch64.sem import ir_aarch64b, ir_aarch64l
|
||||
|
||||
|
|
@ -15,8 +14,8 @@ log.setLevel(logging.CRITICAL)
|
|||
class jitter_aarch64l(Jitter):
|
||||
max_reg_arg = 8
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_aarch64l(LocationDB()), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_aarch64l(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
|
||||
def push_uint64_t(self, value):
|
||||
|
|
@ -75,6 +74,6 @@ class jitter_aarch64l(Jitter):
|
|||
|
||||
class jitter_aarch64b(jitter_aarch64l):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_aarch64b(LocationDB()), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_aarch64b(loc_db), *args, **kwargs)
|
||||
self.vm.set_big_endian()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ from builtins import range
|
|||
import logging
|
||||
|
||||
from miasm.jitter.jitload import Jitter, named_arguments
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.core.utils import pck32, upck32
|
||||
from miasm.arch.arm.sem import ir_armb, ir_arml, ir_armtl, ir_armtb, cond_dct_inv, tab_cond
|
||||
from miasm.jitter.codegen import CGen
|
||||
|
|
@ -65,9 +64,8 @@ class arm_CGen(CGen):
|
|||
class jitter_arml(Jitter):
|
||||
C_Gen = arm_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_arml(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_arml(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
|
||||
def push_uint32_t(self, value):
|
||||
|
|
@ -133,16 +131,14 @@ class jitter_arml(Jitter):
|
|||
class jitter_armb(jitter_arml):
|
||||
C_Gen = arm_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_armb(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_armb(loc_db), *args, **kwargs)
|
||||
self.vm.set_big_endian()
|
||||
|
||||
|
||||
class jitter_armtl(jitter_arml):
|
||||
C_Gen = arm_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_armtl(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_armtl(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
# Note: inspiration from msp430/jit.py
|
||||
|
||||
from miasm.jitter.jitload import Jitter
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.core.utils import *
|
||||
from miasm.jitter.codegen import CGen
|
||||
from miasm.ir.translators.C import TranslatorC
|
||||
|
|
@ -77,9 +76,8 @@ class jitter_mepl(Jitter):
|
|||
|
||||
C_Gen = mep_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_mepl(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_mepl(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
|
||||
|
||||
|
|
@ -108,8 +106,7 @@ class jitter_mepl(Jitter):
|
|||
|
||||
class jitter_mepb(jitter_mepl):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_mepb(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_mepb(loc_db), *args, **kwargs)
|
||||
self.vm.set_big_endian()
|
||||
self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
|
||||
|
|
|
|||
|
|
@ -85,9 +85,8 @@ class jitter_mips32l(Jitter):
|
|||
|
||||
C_Gen = mipsCGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_mips32l(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_mips32l(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
|
||||
def push_uint32_t(self, value):
|
||||
|
|
@ -145,7 +144,6 @@ class jitter_mips32l(Jitter):
|
|||
|
||||
class jitter_mips32b(jitter_mips32l):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_mips32b(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_mips32b(loc_db), *args, **kwargs)
|
||||
self.vm.set_big_endian()
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ log.setLevel(logging.CRITICAL)
|
|||
|
||||
class jitter_msp430(Jitter):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_msp430(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_msp430(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
|
||||
def push_uint16_t(self, value):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from builtins import range
|
||||
from miasm.jitter.jitload import Jitter, named_arguments
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.arch.ppc.sem import ir_ppc32b
|
||||
import struct
|
||||
|
||||
|
|
@ -15,8 +14,8 @@ log.setLevel(logging.CRITICAL)
|
|||
class jitter_ppc32b(Jitter):
|
||||
max_reg_arg = 8
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(jitter_ppc32b, self).__init__(ir_ppc32b(LocationDB()),
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
super(jitter_ppc32b, self).__init__(ir_ppc32b(loc_db),
|
||||
*args, **kwargs)
|
||||
self.vm.set_big_endian()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import logging
|
|||
from miasm.jitter.jitload import Jitter, named_arguments
|
||||
from miasm.arch.x86.sem import ir_x86_16, ir_x86_32, ir_x86_64
|
||||
from miasm.jitter.codegen import CGen
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.ir.translators.C import TranslatorC
|
||||
|
||||
log = logging.getLogger('jit_x86')
|
||||
|
|
@ -42,9 +41,8 @@ class jitter_x86_16(Jitter):
|
|||
|
||||
C_Gen = x86_32_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_x86_16(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_x86_16(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
self.ir_arch.do_stk_segm = False
|
||||
self.orig_irbloc_fix_regs_for_mode = self.ir_arch.irbloc_fix_regs_for_mode
|
||||
|
|
@ -74,9 +72,8 @@ class jitter_x86_32(Jitter):
|
|||
|
||||
C_Gen = x86_32_CGen
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_x86_32(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_x86_32(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
self.ir_arch.do_stk_segm = False
|
||||
|
||||
|
|
@ -201,9 +198,8 @@ class jitter_x86_64(Jitter):
|
|||
args_regs_systemv = ['RDI', 'RSI', 'RDX', 'RCX', 'R8', 'R9']
|
||||
args_regs_stdcall = ['RCX', 'RDX', 'R8', 'R9']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sp = LocationDB()
|
||||
Jitter.__init__(self, ir_x86_64(sp), *args, **kwargs)
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
Jitter.__init__(self, ir_x86_64(loc_db), *args, **kwargs)
|
||||
self.vm.set_little_endian()
|
||||
self.ir_arch.do_stk_segm = False
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ from miasm.expression.simplifications import expr_simp
|
|||
from miasm.core.utils import Disasm_Exception, pck
|
||||
from miasm.core.graph import DiGraph, DiGraphSimplifier, MatchGraphJoker
|
||||
from miasm.core.interval import interval
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
log_asmblock = logging.getLogger("asmblock")
|
||||
|
|
@ -81,11 +80,12 @@ class AsmConstraintTo(AsmConstraint):
|
|||
|
||||
class AsmBlock(object):
|
||||
|
||||
def __init__(self, loc_key, alignment=1):
|
||||
def __init__(self, loc_db, loc_key, alignment=1):
|
||||
assert isinstance(loc_key, LocKey)
|
||||
|
||||
self.bto = set()
|
||||
self.lines = []
|
||||
self.loc_db = loc_db
|
||||
self._loc_key = loc_key
|
||||
self.alignment = alignment
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ class AsmBlock(object):
|
|||
'middle instruction? default middle')
|
||||
offsets.sort()
|
||||
return None
|
||||
new_block = AsmBlock(loc_key)
|
||||
new_block = AsmBlock(loc_db, loc_key)
|
||||
i = offsets.index(offset)
|
||||
|
||||
self.lines, new_block.lines = self.lines[:i], self.lines[i:]
|
||||
|
|
@ -263,12 +263,12 @@ class AsmBlockBad(AsmBlock):
|
|||
ERROR_IO: "IOError",
|
||||
}
|
||||
|
||||
def __init__(self, loc_key=None, alignment=1, errno=ERROR_UNKNOWN, *args, **kwargs):
|
||||
def __init__(self, loc_db, loc_key=None, alignment=1, errno=ERROR_UNKNOWN, *args, **kwargs):
|
||||
"""Instantiate an AsmBlock_bad.
|
||||
@loc_key, @alignment: same as AsmBlock.__init__
|
||||
@errno: (optional) specify a error type associated with the block
|
||||
"""
|
||||
super(AsmBlockBad, self).__init__(loc_key, alignment, *args, **kwargs)
|
||||
super(AsmBlockBad, self).__init__(loc_db, loc_key, alignment, *args, **kwargs)
|
||||
self._errno = errno
|
||||
|
||||
errno = property(lambda self: self._errno)
|
||||
|
|
@ -307,7 +307,7 @@ class AsmCFG(DiGraph):
|
|||
AsmCFGPending = namedtuple("AsmCFGPending",
|
||||
["waiter", "constraint"])
|
||||
|
||||
def __init__(self, loc_db=None, *args, **kwargs):
|
||||
def __init__(self, loc_db, *args, **kwargs):
|
||||
super(AsmCFG, self).__init__(*args, **kwargs)
|
||||
# Edges -> constraint
|
||||
self.edges2constraint = {}
|
||||
|
|
@ -1196,7 +1196,7 @@ class disasmEngine(object):
|
|||
- dis_block_callback: callback after each new disassembled block
|
||||
"""
|
||||
|
||||
def __init__(self, arch, attrib, bin_stream, **kwargs):
|
||||
def __init__(self, arch, attrib, bin_stream, loc_db, **kwargs):
|
||||
"""Instantiate a new disassembly engine
|
||||
@arch: targeted architecture
|
||||
@attrib: architecture attribute
|
||||
|
|
@ -1206,7 +1206,7 @@ class disasmEngine(object):
|
|||
self.arch = arch
|
||||
self.attrib = attrib
|
||||
self.bin_stream = bin_stream
|
||||
self.loc_db = LocationDB()
|
||||
self.loc_db = loc_db
|
||||
|
||||
# Setup options
|
||||
self.dont_dis = []
|
||||
|
|
@ -1236,7 +1236,7 @@ class disasmEngine(object):
|
|||
offsets_to_dis = set()
|
||||
add_next_offset = False
|
||||
loc_key = self.loc_db.get_or_create_offset_location(offset)
|
||||
cur_block = AsmBlock(loc_key)
|
||||
cur_block = AsmBlock(self.loc_db, loc_key)
|
||||
log_asmblock.debug("dis at %X", int(offset))
|
||||
while not in_delayslot or delayslot_count > 0:
|
||||
if in_delayslot:
|
||||
|
|
@ -1246,7 +1246,7 @@ class disasmEngine(object):
|
|||
if not cur_block.lines:
|
||||
job_done.add(offset)
|
||||
# Block is empty -> bad block
|
||||
cur_block = AsmBlockBad(loc_key, errno=AsmBlockBad.ERROR_FORBIDDEN)
|
||||
cur_block = AsmBlockBad(self.loc_db, loc_key, errno=AsmBlockBad.ERROR_FORBIDDEN)
|
||||
else:
|
||||
# Block is not empty, stop the desassembly pass and add a
|
||||
# constraint to the next block
|
||||
|
|
@ -1289,7 +1289,7 @@ class disasmEngine(object):
|
|||
if not cur_block.lines:
|
||||
job_done.add(offset)
|
||||
# Block is empty -> bad block
|
||||
cur_block = AsmBlockBad(loc_key, errno=error)
|
||||
cur_block = AsmBlockBad(self.loc_db, loc_key, errno=error)
|
||||
else:
|
||||
# Block is not empty, stop the desassembly pass and add a
|
||||
# constraint to the next block
|
||||
|
|
@ -1303,7 +1303,7 @@ class disasmEngine(object):
|
|||
instr.b.count(b'\x00') == instr.l):
|
||||
log_asmblock.warning("reach nul instr at %X", int(off_i))
|
||||
# Block is empty -> bad block
|
||||
cur_block = AsmBlockBad(loc_key, errno=AsmBlockBad.ERROR_NULL_STARTING_BLOCK)
|
||||
cur_block = AsmBlockBad(self.loc_db, loc_key, errno=AsmBlockBad.ERROR_NULL_STARTING_BLOCK)
|
||||
break
|
||||
|
||||
# special case: flow graph modificator in delayslot
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import miasm.expression.expression as m2_expr
|
|||
from miasm.core.bin_stream import bin_stream, bin_stream_str
|
||||
from miasm.core.utils import Disasm_Exception
|
||||
from miasm.expression.simplifications import expr_simp
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
from miasm.core.asm_ast import AstNode, AstInt, AstId, AstOp
|
||||
|
|
@ -1016,17 +1015,15 @@ class instruction(object):
|
|||
def get_asm_next_offset(self, expr):
|
||||
return m2_expr.ExprInt(self.offset+self.l, expr.size)
|
||||
|
||||
def resolve_args_with_symbols(self, symbols=None):
|
||||
if symbols is None:
|
||||
symbols = LocationDB()
|
||||
def resolve_args_with_symbols(self, loc_db):
|
||||
args_out = []
|
||||
for expr in self.args:
|
||||
# try to resolve symbols using symbols (0 for default value)
|
||||
# try to resolve symbols using loc_db (0 for default value)
|
||||
loc_keys = m2_expr.get_expr_locs(expr)
|
||||
fixed_expr = {}
|
||||
for exprloc in loc_keys:
|
||||
loc_key = exprloc.loc_key
|
||||
names = symbols.get_location_names(loc_key)
|
||||
names = loc_db.get_location_names(loc_key)
|
||||
# special symbols
|
||||
if b'$' in names:
|
||||
fixed_expr[exprloc] = self.get_asm_offset(exprloc)
|
||||
|
|
@ -1034,14 +1031,14 @@ class instruction(object):
|
|||
if b'_' in names:
|
||||
fixed_expr[exprloc] = self.get_asm_next_offset(exprloc)
|
||||
continue
|
||||
arg_int = symbols.get_location_offset(loc_key)
|
||||
arg_int = loc_db.get_location_offset(loc_key)
|
||||
if arg_int is not None:
|
||||
fixed_expr[exprloc] = m2_expr.ExprInt(arg_int, exprloc.size)
|
||||
continue
|
||||
if not names:
|
||||
raise ValueError('Unresolved symbol: %r' % exprloc)
|
||||
|
||||
offset = symbols.get_location_offset(loc_key)
|
||||
offset = loc_db.get_location_offset(loc_key)
|
||||
if offset is None:
|
||||
raise ValueError(
|
||||
'The offset of loc_key "%s" cannot be determined' % names
|
||||
|
|
@ -1050,7 +1047,7 @@ class instruction(object):
|
|||
# Fix symbol with its offset
|
||||
size = exprloc.size
|
||||
if size is None:
|
||||
default_size = self.get_symbol_size(exprloc, symbols)
|
||||
default_size = self.get_symbol_size(exprloc, loc_db)
|
||||
size = default_size
|
||||
value = m2_expr.ExprInt(offset, size)
|
||||
fixed_expr[exprloc] = value
|
||||
|
|
@ -1383,7 +1380,7 @@ class cls_mn(with_metaclass(metamn, object)):
|
|||
yield c
|
||||
|
||||
@classmethod
|
||||
def asm(cls, instr, symbols=None):
|
||||
def asm(cls, instr, loc_db=None):
|
||||
"""
|
||||
Re asm instruction by searching mnemo using name and args. We then
|
||||
can modify args and get the hex of a modified instruction
|
||||
|
|
@ -1392,7 +1389,7 @@ class cls_mn(with_metaclass(metamn, object)):
|
|||
clist = [x for x in clist]
|
||||
vals = []
|
||||
candidates = []
|
||||
args = instr.resolve_args_with_symbols(symbols)
|
||||
args = instr.resolve_args_with_symbols(loc_db)
|
||||
|
||||
for cc in clist:
|
||||
|
||||
|
|
|
|||
|
|
@ -88,21 +88,16 @@ def asm_ast_to_expr_with_size(arg, loc_db, size):
|
|||
return ExprInt(arg.value, size)
|
||||
return None
|
||||
|
||||
def parse_txt(mnemo, attrib, txt, loc_db=None):
|
||||
"""Parse an assembly listing. Returns a couple (asmcfg, loc_db), where
|
||||
asmcfg is an AsmCfg instance and loc_db the associated LocationDB
|
||||
def parse_txt(mnemo, attrib, txt, loc_db):
|
||||
"""Parse an assembly listing. Returns an AsmCfg instance
|
||||
|
||||
@mnemo: architecture used
|
||||
@attrib: architecture attribute
|
||||
@txt: assembly listing
|
||||
@loc_db: (optional) the LocationDB instance used to handle labels
|
||||
of the listing
|
||||
@loc_db: the LocationDB instance used to handle labels of the listing
|
||||
|
||||
"""
|
||||
|
||||
if loc_db is None:
|
||||
loc_db = asmblock.LocationDB()
|
||||
|
||||
C_NEXT = asmblock.AsmConstraint.c_next
|
||||
C_TO = asmblock.AsmConstraint.c_to
|
||||
|
||||
|
|
@ -233,9 +228,9 @@ def parse_txt(mnemo, attrib, txt, loc_db=None):
|
|||
# First line must be a label. If it's not the case, generate
|
||||
# it.
|
||||
loc = guess_next_new_label(loc_db)
|
||||
cur_block = asmblock.AsmBlock(loc, alignment=mnemo.alignment)
|
||||
cur_block = asmblock.AsmBlock(loc_db, loc, alignment=mnemo.alignment)
|
||||
else:
|
||||
cur_block = asmblock.AsmBlock(line, alignment=mnemo.alignment)
|
||||
cur_block = asmblock.AsmBlock(loc_db, line, alignment=mnemo.alignment)
|
||||
i += 1
|
||||
# Generate the current block
|
||||
asmcfg.add_block(cur_block)
|
||||
|
|
@ -302,4 +297,4 @@ def parse_txt(mnemo, attrib, txt, loc_db=None):
|
|||
|
||||
# Log block
|
||||
asmblock.log_asmblock.info(block)
|
||||
return asmcfg, loc_db
|
||||
return asmcfg
|
||||
|
|
|
|||
|
|
@ -773,7 +773,7 @@ class IntermediateRepresentation(object):
|
|||
if loc_key is None:
|
||||
offset = getattr(instr, "offset", None)
|
||||
loc_key = self.loc_db.get_or_create_offset_location(offset)
|
||||
block = AsmBlock(loc_key)
|
||||
block = AsmBlock(self.loc_db, loc_key)
|
||||
block.lines = [instr]
|
||||
self.add_asmblock_to_ircfg(block, ircfg, gen_pc_updt)
|
||||
return loc_key
|
||||
|
|
|
|||
|
|
@ -189,7 +189,8 @@ class PE(object):
|
|||
parse_resources=True,
|
||||
parse_delay=True,
|
||||
parse_reloc=True,
|
||||
wsize=32):
|
||||
wsize=32,
|
||||
**kwargs):
|
||||
self._rva = ContectRva(self)
|
||||
self._virt = ContentVirtual(self)
|
||||
self.img_rva = StrPatchwork()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from miasm.core.asmblock import asm_resolve_final
|
|||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.analysis.dse import DSEEngine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
class DSETest(object):
|
||||
|
|
@ -31,9 +32,10 @@ class DSETest(object):
|
|||
run_addr = 0x0
|
||||
|
||||
def __init__(self, jitter_engine):
|
||||
self.loc_db = LocationDB()
|
||||
self.machine = Machine(self.arch_name)
|
||||
jitter = self.machine.jitter
|
||||
self.myjit = jitter(jitter_engine)
|
||||
self.myjit = jitter(self.loc_db, jitter_engine)
|
||||
self.myjit.init_stack()
|
||||
|
||||
self.myjit.set_trace_log()
|
||||
|
|
@ -52,7 +54,7 @@ class DSETest(object):
|
|||
self.myjit.cpu.ECX = 4
|
||||
self.myjit.cpu.EDX = 5
|
||||
|
||||
self.dse = DSEEngine(self.machine)
|
||||
self.dse = DSEEngine(self.machine, self.loc_db)
|
||||
self.dse.attach(self.myjit)
|
||||
|
||||
def __call__(self):
|
||||
|
|
@ -71,17 +73,17 @@ class DSETest(object):
|
|||
|
||||
def asm(self):
|
||||
mn_x86 = self.machine.mn
|
||||
blocks, loc_db = parse_asm.parse_txt(
|
||||
blocks = parse_asm.parse_txt(
|
||||
mn_x86,
|
||||
self.arch_attrib,
|
||||
self.TXT,
|
||||
loc_db=self.myjit.ir_arch.loc_db
|
||||
self.loc_db
|
||||
)
|
||||
|
||||
# fix shellcode addr
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
self.loc_db.set_location_offset(self.loc_db.get_name_location("main"), 0x0)
|
||||
output = StrPatchwork()
|
||||
patches = asm_resolve_final(mn_x86, blocks, loc_db)
|
||||
patches = asm_resolve_final(mn_x86, blocks, self.loc_db)
|
||||
for offset, raw in viewitems(patches):
|
||||
output[offset] = raw
|
||||
|
||||
|
|
@ -120,7 +122,7 @@ class DSEAttachInBreakpoint(DSETest):
|
|||
|
||||
def bp_attach(self, jitter):
|
||||
"""Attach a DSE in the current jitter"""
|
||||
self.dse = DSEEngine(self.machine)
|
||||
self.dse = DSEEngine(self.machine, self.loc_db)
|
||||
self.dse.attach(self.myjit)
|
||||
self.dse.update_state_from_concrete()
|
||||
self.dse.update_state({
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ from miasm.core import asmblock
|
|||
from miasm.loader.strpatchwork import StrPatchwork
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import *
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
reg_and_id = dict(mn_aarch64.regs.all_regs_ids_byname)
|
||||
|
||||
class Asm_Test(object):
|
||||
def __init__(self, jitter):
|
||||
self.myjit = Machine("aarch64l").jitter(jitter)
|
||||
self.loc_db = LocationDB()
|
||||
self.myjit = Machine("aarch64l").jitter(self.loc_db, jitter)
|
||||
self.myjit.init_stack()
|
||||
|
||||
def __call__(self):
|
||||
|
|
@ -24,12 +26,11 @@ class Asm_Test(object):
|
|||
self.check()
|
||||
|
||||
def asm(self):
|
||||
blocks, loc_db = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT,
|
||||
loc_db = self.myjit.ir_arch.loc_db)
|
||||
blocks = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, self.loc_db)
|
||||
# fix shellcode addr
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
self.loc_db.set_location_offset(self.loc_db.get_name_location("main"), 0x0)
|
||||
s = StrPatchwork()
|
||||
patches = asmblock.asm_resolve_final(mn_aarch64, blocks, loc_db)
|
||||
patches = asmblock.asm_resolve_final(mn_aarch64, blocks, self.loc_db)
|
||||
for offset, raw in viewitems(patches):
|
||||
s[offset] = raw
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from __future__ import print_function
|
|||
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
def jit_instructions(mn_str):
|
||||
|
|
@ -13,6 +14,7 @@ def jit_instructions(mn_str):
|
|||
# Get the miasm Machine
|
||||
machine = Machine("mepb")
|
||||
mn_mep = machine.mn()
|
||||
loc_db = LocationDB()
|
||||
|
||||
# Assemble the instructions
|
||||
asm = b""
|
||||
|
|
@ -22,7 +24,7 @@ def jit_instructions(mn_str):
|
|||
asm += mn_mep.asm(instr)[0]
|
||||
|
||||
# Init the jitter and add the assembled instructions to memory
|
||||
jitter = machine.jitter(jit_type="gcc")
|
||||
jitter = machine.jitter(loc_db, jit_type="gcc")
|
||||
jitter.vm.add_memory_page(0, PAGE_READ | PAGE_WRITE, asm)
|
||||
|
||||
# Set the breakpoint
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from miasm.core import asmblock
|
|||
from miasm.loader.strpatchwork import StrPatchwork
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import *
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
reg_and_id = dict(mn_mips32.regs.all_regs_ids_byname)
|
||||
|
|
@ -17,7 +18,8 @@ reg_and_id = dict(mn_mips32.regs.all_regs_ids_byname)
|
|||
class Asm_Test(object):
|
||||
|
||||
def __init__(self, jitter):
|
||||
self.myjit = Machine("mips32l").jitter(jitter)
|
||||
self.loc_db = LocationDB()
|
||||
self.myjit = Machine("mips32l").jitter(self.loc_db, jitter)
|
||||
self.myjit.init_stack()
|
||||
|
||||
def __call__(self):
|
||||
|
|
@ -26,12 +28,11 @@ class Asm_Test(object):
|
|||
self.check()
|
||||
|
||||
def asm(self):
|
||||
blocks, loc_db = parse_asm.parse_txt(mn_mips32, 'l', self.TXT,
|
||||
loc_db=self.myjit.ir_arch.loc_db)
|
||||
blocks = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, self.loc_db)
|
||||
# fix shellcode addr
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
self.loc_db.set_location_offset(self.loc_db.get_name_location("main"), 0x0)
|
||||
s = StrPatchwork()
|
||||
patches = asmblock.asm_resolve_final(mn_mips32, blocks, loc_db)
|
||||
patches = asmblock.asm_resolve_final(mn_mips32, blocks, self.loc_db)
|
||||
for offset, raw in viewitems(patches):
|
||||
s[offset] = raw
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ except AttributeError:
|
|||
from miasm.analysis.sandbox import Sandbox_Linux_x86_32
|
||||
from miasm.jitter.jitload import log_func
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Utils
|
||||
def parse_fmt(s):
|
||||
|
|
@ -122,7 +123,8 @@ options = parser.parse_args()
|
|||
expected = open(options.expected)
|
||||
|
||||
# Create sandbox
|
||||
sb = Sandbox_Linux_x86_32(options.filename, options, globals())
|
||||
loc_db = LocationDB()
|
||||
sb = Sandbox_Linux_x86_32(loc_db, options.filename, options, globals())
|
||||
try:
|
||||
addr = sb.elf.getsectionbyname(".symtab")[options.funcname].value
|
||||
except AttributeError:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ except AttributeError:
|
|||
from miasm.analysis.sandbox import Sandbox_Linux_x86_64
|
||||
from miasm.jitter.jitload import log_func
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Utils
|
||||
def parse_fmt(s):
|
||||
|
|
@ -118,7 +119,8 @@ options = parser.parse_args()
|
|||
expected = open(options.expected)
|
||||
|
||||
# Create sandbox
|
||||
sb = Sandbox_Linux_x86_64(options.filename, options, globals())
|
||||
loc_db = LocationDB()
|
||||
sb = Sandbox_Linux_x86_64(loc_db, options.filename, options, globals())
|
||||
try:
|
||||
addr = sb.elf.getsectionbyname(".symtab")[options.funcname].value
|
||||
except AttributeError:
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ def compute(ir, mode, asm, inputstate={}, debug=False):
|
|||
|
||||
|
||||
def compute_txt(ir, mode, txt, inputstate={}, debug=False):
|
||||
asmcfg, loc_db = parse_asm.parse_txt(mn, mode, txt)
|
||||
loc_db = LocationDB()
|
||||
asmcfg = parse_asm.parse_txt(mn, mode, txt, loc_db)
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
patches = asmblock.asm_resolve_final(mn, asmcfg, loc_db)
|
||||
ir_arch = ir(loc_db)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
"""Test getter and setter for XMM registers (128 bits)"""
|
||||
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Jitter engine doesn't matter, use the always available 'python' one
|
||||
myjit = Machine("x86_32").jitter("python")
|
||||
loc_db = LocationDB()
|
||||
myjit = Machine("x86_32").jitter(loc_db, "python")
|
||||
|
||||
# Test basic access (get)
|
||||
assert myjit.cpu.XMM0 == 0
|
||||
|
|
|
|||
|
|
@ -11,15 +11,16 @@ from miasm.expression.expression import *
|
|||
from miasm.core import asmblock
|
||||
from miasm.loader.strpatchwork import StrPatchwork
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
from miasm.jitter.csts import *
|
||||
|
||||
reg_and_id = dict(mn_x86.regs.all_regs_ids_byname)
|
||||
|
||||
class Asm_Test(object):
|
||||
run_addr = 0x0
|
||||
|
||||
def __init__(self, jitter_engine):
|
||||
self.myjit = Machine(self.arch_name).jitter(jitter_engine)
|
||||
self.loc_db = LocationDB()
|
||||
self.myjit = Machine(self.arch_name).jitter(self.loc_db, jitter_engine)
|
||||
self.myjit.init_stack()
|
||||
|
||||
def test_init(self):
|
||||
|
|
@ -44,12 +45,11 @@ class Asm_Test(object):
|
|||
assert(self.myjit.pc == self.ret_addr)
|
||||
|
||||
def asm(self):
|
||||
blocks, loc_db = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT,
|
||||
loc_db = self.myjit.ir_arch.loc_db)
|
||||
blocks = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, self.loc_db)
|
||||
# fix shellcode addr
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
|
||||
self.loc_db.set_location_offset(self.loc_db.get_name_location("main"), 0x0)
|
||||
s = StrPatchwork()
|
||||
patches = asmblock.asm_resolve_final(mn_x86, blocks, loc_db)
|
||||
patches = asmblock.asm_resolve_final(mn_x86, blocks, self.loc_db)
|
||||
for offset, raw in viewitems(patches):
|
||||
s[offset] = raw
|
||||
|
||||
|
|
@ -77,7 +77,8 @@ class Asm_Test_16(Asm_Test):
|
|||
ret_addr = 0x1337
|
||||
|
||||
def __init__(self, jitter_engine):
|
||||
self.myjit = Machine(self.arch_name).jitter(jitter_engine)
|
||||
self.loc_db = LocationDB()
|
||||
self.myjit = Machine(self.arch_name).jitter(self.loc_db, jitter_engine)
|
||||
self.myjit.stack_base = 0x1000
|
||||
self.myjit.stack_size = 0x1000
|
||||
self.myjit.init_stack()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Test_PUSHAD_32(Asm_Test_32):
|
|||
MYSTRING = "test pushad 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -48,7 +48,7 @@ class Test_PUSHA_32(Asm_Test_32):
|
|||
MYSTRING = "test pusha 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -75,7 +75,7 @@ class Test_PUSHA_16(Asm_Test_16):
|
|||
MYSTRING = "test pusha 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -102,7 +102,7 @@ class Test_PUSHAD_16(Asm_Test_16):
|
|||
MYSTRING = "test pushad 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -129,7 +129,7 @@ class Test_PUSH_mode32_32(Asm_Test_32):
|
|||
MYSTRING = "test push mode32 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -152,7 +152,7 @@ class Test_PUSH_mode32_16(Asm_Test_32):
|
|||
MYSTRING = "test push mode32 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -175,7 +175,7 @@ class Test_PUSH_mode16_16(Asm_Test_16):
|
|||
MYSTRING = "test push mode16 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -198,7 +198,7 @@ class Test_PUSH_mode16_32(Asm_Test_16):
|
|||
MYSTRING = "test push mode16 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
init_regs(self)
|
||||
|
|
@ -221,7 +221,7 @@ class Test_POP_mode32_32(Asm_Test_32):
|
|||
MYSTRING = "test pop mode32 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
self.value = 0x11223344
|
||||
|
|
@ -243,7 +243,7 @@ class Test_POP_mode32_16(Asm_Test_32):
|
|||
MYSTRING = "test pop mode32 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
self.value = 0x1122
|
||||
|
|
@ -265,7 +265,7 @@ class Test_POP_mode16_16(Asm_Test_16):
|
|||
MYSTRING = "test pop mode16 16"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
self.value = 0x1122
|
||||
|
|
@ -287,7 +287,7 @@ class Test_POP_mode16_32(Asm_Test_16):
|
|||
MYSTRING = "test pop mode16 32"
|
||||
|
||||
def prepare(self):
|
||||
self.myjit.ir_arch.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
self.loc_db.add_location("lbl_ret", self.ret_addr)
|
||||
|
||||
def test_init(self):
|
||||
self.value = 0x11223344
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ from miasm.core import asmblock
|
|||
from miasm.arch.x86 import arch
|
||||
from miasm.core import parse_asm
|
||||
from miasm.core.interval import interval
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
my_mn = arch.mn_x86
|
||||
loc_db = LocationDB()
|
||||
|
||||
|
||||
asmcfg, loc_db = parse_asm.parse_txt(my_mn, 64, r'''
|
||||
asmcfg = parse_asm.parse_txt(
|
||||
my_mn, 64, r'''
|
||||
main:
|
||||
PUSH RBP
|
||||
MOV RBP, RSP
|
||||
|
|
@ -18,7 +20,9 @@ end:
|
|||
POP RBP
|
||||
RET
|
||||
|
||||
''')
|
||||
''',
|
||||
loc_db
|
||||
)
|
||||
|
||||
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x100001000)
|
||||
dst_interval = interval([(0x100001000, 0x100002000)])
|
||||
|
|
|
|||
|
|
@ -12,14 +12,16 @@ from miasm.core.asmblock import AsmCFG, AsmConstraint, AsmBlock, \
|
|||
bbl_simplifier
|
||||
from miasm.core.graph import DiGraphSimplifier, MatchGraphJoker
|
||||
from miasm.expression.expression import ExprId
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Initial data: from 'samples/simple_test.bin'
|
||||
data = decode_hex("5589e583ec10837d08007509c745fc01100000eb73837d08017709c745fc02100000eb64837d08057709c745fc03100000eb55837d080774138b450801c083f80e7509c745fc04100000eb3c8b450801c083f80e7509c745fc05100000eb298b450883e03085c07409c745fc06100000eb16837d08427509c745fc07100000eb07c745fc081000008b45fcc9c3")
|
||||
cont = Container.from_string(data)
|
||||
loc_db = LocationDB()
|
||||
cont = Container.from_string(data, loc_db)
|
||||
|
||||
# Test Disasm engine
|
||||
machine = Machine("x86_32")
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
## Disassembly of one block
|
||||
first_block = mdis.dis_block(0)
|
||||
assert len(first_block.lines) == 5
|
||||
|
|
@ -111,8 +113,8 @@ open("graph2.dot", "w").write(asmcfg.dot())
|
|||
# Test helper methods
|
||||
## loc_key_to_block should always be updated
|
||||
assert asmcfg.loc_key_to_block(first_block.loc_key) == first_block
|
||||
testlabel = mdis.loc_db.get_or_create_name_location("testlabel")
|
||||
my_block = AsmBlock(testlabel)
|
||||
testlabel = loc_db.get_or_create_name_location("testlabel")
|
||||
my_block = AsmBlock(loc_db, testlabel)
|
||||
asmcfg.add_block(my_block)
|
||||
assert len(asmcfg) == 3
|
||||
assert asmcfg.loc_key_to_block(first_block.loc_key) == first_block
|
||||
|
|
@ -122,8 +124,8 @@ assert asmcfg.loc_key_to_block(my_block.loc_key) == my_block
|
|||
assert len(list(asmcfg.get_bad_blocks())) == 0
|
||||
assert len(list(asmcfg.get_bad_blocks_predecessors())) == 0
|
||||
### Add a bad block, not linked
|
||||
testlabel_bad = mdis.loc_db.get_or_create_name_location("testlabel_bad")
|
||||
my_bad_block = AsmBlockBad(testlabel_bad)
|
||||
testlabel_bad = loc_db.get_or_create_name_location("testlabel_bad")
|
||||
my_bad_block = AsmBlockBad(loc_db, testlabel_bad)
|
||||
asmcfg.add_block(my_bad_block)
|
||||
assert list(asmcfg.get_bad_blocks()) == [my_bad_block]
|
||||
assert len(list(asmcfg.get_bad_blocks_predecessors())) == 0
|
||||
|
|
@ -141,8 +143,8 @@ assert len(list(asmcfg.get_bad_blocks_predecessors(strict=True))) == 0
|
|||
## Sanity check
|
||||
asmcfg.sanity_check()
|
||||
### Next on itself
|
||||
testlabel_nextitself = mdis.loc_db.get_or_create_name_location("testlabel_nextitself")
|
||||
my_block_ni = AsmBlock(testlabel_nextitself)
|
||||
testlabel_nextitself = loc_db.get_or_create_name_location("testlabel_nextitself")
|
||||
my_block_ni = AsmBlock(loc_db, testlabel_nextitself)
|
||||
my_block_ni.bto.add(AsmConstraintNext(my_block_ni.loc_key))
|
||||
asmcfg.add_block(my_block_ni)
|
||||
error_raised = False
|
||||
|
|
@ -155,13 +157,13 @@ assert error_raised
|
|||
asmcfg.del_block(my_block_ni)
|
||||
asmcfg.sanity_check()
|
||||
### Multiple next on the same node
|
||||
testlabel_target = mdis.loc_db.get_or_create_name_location("testlabel_target")
|
||||
my_block_target = AsmBlock(testlabel_target)
|
||||
testlabel_target = loc_db.get_or_create_name_location("testlabel_target")
|
||||
my_block_target = AsmBlock(loc_db, testlabel_target)
|
||||
asmcfg.add_block(my_block_target)
|
||||
testlabel_src1 = mdis.loc_db.get_or_create_name_location("testlabel_src1")
|
||||
testlabel_src2 = mdis.loc_db.get_or_create_name_location("testlabel_src2")
|
||||
my_block_src1 = AsmBlock(testlabel_src1)
|
||||
my_block_src2 = AsmBlock(testlabel_src2)
|
||||
testlabel_src1 = loc_db.get_or_create_name_location("testlabel_src1")
|
||||
testlabel_src2 = loc_db.get_or_create_name_location("testlabel_src2")
|
||||
my_block_src1 = AsmBlock(loc_db, testlabel_src1)
|
||||
my_block_src2 = AsmBlock(loc_db, testlabel_src2)
|
||||
my_block_src1.bto.add(AsmConstraintNext(my_block_target.loc_key))
|
||||
asmcfg.add_block(my_block_src1)
|
||||
### OK for now
|
||||
|
|
@ -190,10 +192,10 @@ assert asmcfg.loc_key_to_block(my_block_src1.loc_key).max_size == 0
|
|||
|
||||
## Check pendings
|
||||
### Create a pending element
|
||||
testlabel_pend_src = mdis.loc_db.get_or_create_name_location("testlabel_pend_src")
|
||||
testlabel_pend_dst = mdis.loc_db.get_or_create_name_location("testlabel_pend_dst")
|
||||
my_block_src = AsmBlock(testlabel_pend_src)
|
||||
my_block_dst = AsmBlock(testlabel_pend_dst)
|
||||
testlabel_pend_src = loc_db.get_or_create_name_location("testlabel_pend_src")
|
||||
testlabel_pend_dst = loc_db.get_or_create_name_location("testlabel_pend_dst")
|
||||
my_block_src = AsmBlock(loc_db, testlabel_pend_src)
|
||||
my_block_dst = AsmBlock(loc_db, testlabel_pend_dst)
|
||||
my_block_src.bto.add(AsmConstraintTo(my_block_dst.loc_key))
|
||||
asmcfg.add_block(my_block_src)
|
||||
### Check resulting state
|
||||
|
|
@ -220,8 +222,8 @@ asmcfg.sanity_check()
|
|||
|
||||
# Test block_merge
|
||||
data2 = decode_hex("31c0eb0c31c9750c31d2eb0c31ffebf831dbebf031edebfc31f6ebf031e4c3")
|
||||
cont2 = Container.from_string(data2)
|
||||
mdis = machine.dis_engine(cont2.bin_stream, loc_db=cont2.loc_db)
|
||||
cont2 = Container.from_string(data2, loc_db)
|
||||
mdis = machine.dis_engine(cont2.bin_stream, loc_db=loc_db)
|
||||
## Elements to merge
|
||||
asmcfg = mdis.dis_multiblock(0)
|
||||
## Block alone
|
||||
|
|
@ -253,7 +255,7 @@ assert len(entry_block.lines) == 4
|
|||
assert list(map(str, entry_block.lines)) == ['XOR EAX, EAX',
|
||||
'XOR EBX, EBX',
|
||||
'XOR ECX, ECX',
|
||||
'JNZ loc_key_3']
|
||||
'JNZ loc_key_27']
|
||||
assert len(asmcfg.successors(entry_block.loc_key)) == 2
|
||||
assert len(entry_block.bto) == 2
|
||||
nextb = asmcfg.loc_key_to_block(next((cons.loc_key for cons in entry_block.bto
|
||||
|
|
@ -264,11 +266,11 @@ assert len(nextb.lines) == 4
|
|||
assert list(map(str, nextb.lines)) == ['XOR EDX, EDX',
|
||||
'XOR ESI, ESI',
|
||||
'XOR EDI, EDI',
|
||||
'JMP loc_key_4']
|
||||
'JMP loc_key_28']
|
||||
assert asmcfg.successors(nextb.loc_key) == [nextb.loc_key]
|
||||
assert len(tob.lines) == 2
|
||||
assert list(map(str, tob.lines)) == ['XOR EBP, EBP',
|
||||
'JMP loc_key_3']
|
||||
'JMP loc_key_27']
|
||||
assert asmcfg.successors(tob.loc_key) == [tob.loc_key]
|
||||
|
||||
# Check split_block
|
||||
|
|
@ -278,7 +280,7 @@ mdis.apply_splitting(asmcfg)
|
|||
assert asmcfg_bef == asmcfg
|
||||
open("graph5.dot", "w").write(asmcfg.dot())
|
||||
## Create conditions for a block split
|
||||
inside_firstbbl = mdis.loc_db.get_offset_location(4)
|
||||
inside_firstbbl = loc_db.get_offset_location(4)
|
||||
tob.bto.add(AsmConstraintTo(inside_firstbbl))
|
||||
asmcfg.rebuild_edges()
|
||||
assert len(asmcfg.pendings) == 1
|
||||
|
|
@ -295,7 +297,7 @@ lbl_newb = asmcfg.successors(entry_block.loc_key)[0]
|
|||
newb = asmcfg.loc_key_to_block(lbl_newb)
|
||||
assert len(newb.lines) == 2
|
||||
assert list(map(str, newb.lines)) == ['XOR ECX, ECX',
|
||||
'JNZ loc_key_3']
|
||||
'JNZ loc_key_27']
|
||||
preds = asmcfg.predecessors(lbl_newb)
|
||||
assert len(preds) == 2
|
||||
assert entry_block.loc_key in preds
|
||||
|
|
@ -306,8 +308,8 @@ assert asmcfg.edges2constraint[(tob.loc_key, lbl_newb)] == AsmConstraint.c_to
|
|||
|
||||
# Check double block split
|
||||
data = decode_hex("74097405b8020000007405b803000000b804000000c3")
|
||||
cont = Container.from_string(data)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
||||
cont = Container.from_string(data, loc_db)
|
||||
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
|
||||
asmcfg = mdis.dis_multiblock(0)
|
||||
## Check resulting disasm
|
||||
assert len(asmcfg.nodes()) == 6
|
||||
|
|
@ -328,10 +330,10 @@ solutions = list(matcher.match(asmcfg))
|
|||
assert len(solutions) == 1
|
||||
solution = solutions.pop()
|
||||
for jbbl, label in viewitems(solution):
|
||||
offset = mdis.loc_db.get_location_offset(label)
|
||||
offset = loc_db.get_location_offset(label)
|
||||
assert offset == int(jbbl._name, 16)
|
||||
|
||||
loc_key_dum = mdis.loc_db.get_or_create_name_location("dummy_loc")
|
||||
loc_key_dum = loc_db.get_or_create_name_location("dummy_loc")
|
||||
asmcfg.add_node(loc_key_dum)
|
||||
error_raised = False
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
from builtins import range
|
||||
import unittest
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
class TestParseAsm(unittest.TestCase):
|
||||
|
|
@ -10,6 +11,7 @@ class TestParseAsm(unittest.TestCase):
|
|||
def test_ParseTxt(self):
|
||||
from miasm.arch.x86.arch import mn_x86
|
||||
from miasm.core.parse_asm import parse_txt
|
||||
loc_db = LocationDB()
|
||||
|
||||
ASM0 = '''
|
||||
;
|
||||
|
|
@ -33,13 +35,14 @@ class TestParseAsm(unittest.TestCase):
|
|||
ASM1 = '''
|
||||
.XXX
|
||||
'''
|
||||
self.assertTrue(parse_txt(mn_x86, 32, ASM0))
|
||||
self.assertRaises(ValueError, parse_txt, mn_x86, 32, ASM1)
|
||||
self.assertTrue(parse_txt(mn_x86, 32, ASM0, loc_db))
|
||||
self.assertRaises(ValueError, parse_txt, mn_x86, 32, ASM1, loc_db)
|
||||
|
||||
def test_DirectiveDontSplit(self):
|
||||
from miasm.arch.x86.arch import mn_x86
|
||||
from miasm.core.parse_asm import parse_txt
|
||||
from miasm.core.asmblock import asm_resolve_final
|
||||
loc_db = LocationDB()
|
||||
|
||||
ASM0 = '''
|
||||
lbl0:
|
||||
|
|
@ -65,10 +68,8 @@ class TestParseAsm(unittest.TestCase):
|
|||
.string "toto"
|
||||
'''
|
||||
|
||||
asmcfg, loc_db = parse_txt(mn_x86, 32, ASM0)
|
||||
patches = asm_resolve_final(mn_x86,
|
||||
asmcfg,
|
||||
loc_db)
|
||||
asmcfg = parse_txt(mn_x86, 32, ASM0, loc_db)
|
||||
patches = asm_resolve_final(mn_x86, asmcfg, loc_db)
|
||||
lbls = []
|
||||
for i in range(6):
|
||||
lbls.append(loc_db.get_name_location('lbl%d' % i))
|
||||
|
|
@ -87,6 +88,7 @@ class TestParseAsm(unittest.TestCase):
|
|||
def test_DirectiveSplit(self):
|
||||
from miasm.arch.x86.arch import mn_x86
|
||||
from miasm.core.parse_asm import parse_txt
|
||||
loc_db = LocationDB()
|
||||
|
||||
ASM0 = '''
|
||||
lbl0:
|
||||
|
|
@ -96,7 +98,7 @@ class TestParseAsm(unittest.TestCase):
|
|||
RET
|
||||
'''
|
||||
|
||||
asmcfg, loc_db = parse_txt(mn_x86, 32, ASM0)
|
||||
asmcfg = parse_txt(mn_x86, 32, ASM0, loc_db)
|
||||
lbls = []
|
||||
for i in range(2):
|
||||
lbls.append(loc_db.get_name_location('lbl%d' % i))
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from miasm.core.types import MemStruct, Num, Ptr, Str, \
|
|||
set_allocator, MemUnion, Struct
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.os_dep.common import heap
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
# Two structures with some fields
|
||||
class OtherStruct(MemStruct):
|
||||
|
|
@ -35,7 +36,8 @@ class MyStruct(MemStruct):
|
|||
("i", Ptr("I", Num("I"))),
|
||||
]
|
||||
|
||||
jitter = Machine("x86_32").jitter("python")
|
||||
loc_db = LocationDB()
|
||||
jitter = Machine("x86_32").jitter(loc_db, "python")
|
||||
jitter.init_stack()
|
||||
addr = 0x1000
|
||||
size = 0x1000
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import sys
|
|||
from miasm.core.utils import decode_hex
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_UNK_MNEMO
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
def code_sentinelle(jitter):
|
||||
jitter.run = False
|
||||
|
|
@ -9,7 +10,8 @@ def code_sentinelle(jitter):
|
|||
return True
|
||||
|
||||
machine = Machine("x86_32")
|
||||
jitter = machine.jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
jitter = machine.jitter(loc_db, sys.argv[1])
|
||||
|
||||
jitter.init_stack()
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import sys
|
|||
from miasm.core.utils import decode_hex
|
||||
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
|
||||
|
||||
# Shellcode
|
||||
|
|
@ -21,16 +22,17 @@ from pdb import pm
|
|||
|
||||
data = decode_hex("b810000000bb0100000083e8010f44cb75f8c3")
|
||||
run_addr = 0x40000000
|
||||
loc_db = LocationDB()
|
||||
|
||||
def code_sentinelle(jitter):
|
||||
jitter.run = False
|
||||
jitter.pc = 0
|
||||
return True
|
||||
|
||||
def init_jitter():
|
||||
def init_jitter(loc_db):
|
||||
global data, run_addr
|
||||
# Create jitter
|
||||
myjit = Machine("x86_32").jitter(sys.argv[1])
|
||||
myjit = Machine("x86_32").jitter(loc_db, sys.argv[1])
|
||||
|
||||
myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, data)
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ def init_jitter():
|
|||
|
||||
# Test 'max_exec_per_call'
|
||||
print("[+] First run, to jit blocks")
|
||||
myjit = init_jitter()
|
||||
myjit = init_jitter(loc_db)
|
||||
myjit.init_run(run_addr)
|
||||
myjit.continue_run()
|
||||
|
||||
|
|
@ -78,7 +80,7 @@ assert myjit.cpu.EAX >= 0xA
|
|||
|
||||
# Test 'jit_maxline'
|
||||
print("[+] Run instr one by one")
|
||||
myjit = init_jitter()
|
||||
myjit = init_jitter(loc_db)
|
||||
myjit.jit.options["jit_maxline"] = 1
|
||||
myjit.jit.options["max_exec_per_call"] = 1
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import sys
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
from miasm.analysis.machine import Machine
|
||||
machine = Machine("x86_64")
|
||||
jitter = machine.jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
jitter = machine.jitter(loc_db, sys.argv[1])
|
||||
|
||||
jitter.cpu.RAX = 16565615892967251934
|
||||
assert jitter.cpu.RAX == 16565615892967251934
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ from miasm.core.utils import decode_hex, encode_hex
|
|||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.expression.expression import ExprId, ExprAssign, ExprInt, ExprMem
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
# Initial data: from 'example/samples/x86_32_sc.bin'
|
||||
data = decode_hex("8d49048d5b0180f90174058d5bffeb038d5b0189d8c3")
|
||||
loc_db = LocationDB()
|
||||
|
||||
# Init jitter
|
||||
myjit = Machine("x86_32").jitter(sys.argv[1])
|
||||
myjit = Machine("x86_32").jitter(loc_db, sys.argv[1])
|
||||
myjit.init_stack()
|
||||
|
||||
run_addr = 0x40000000
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import sys
|
|||
from miasm.core.utils import decode_hex
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
def code_sentinelle(jitter):
|
||||
jitter.run = False
|
||||
|
|
@ -10,7 +12,8 @@ def code_sentinelle(jitter):
|
|||
|
||||
|
||||
machine = Machine("x86_32")
|
||||
jitter = machine.jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
jitter = machine.jitter(loc_db, sys.argv[1])
|
||||
|
||||
jitter.init_stack()
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from miasm.core.utils import decode_hex
|
|||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, \
|
||||
EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
def mem_breakpoint_handler(jitter):
|
||||
print("======")
|
||||
|
|
@ -35,7 +36,8 @@ def mem_breakpoint_handler(jitter):
|
|||
return True
|
||||
|
||||
machine = Machine("aarch64l")
|
||||
jitter = machine.jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
jitter = machine.jitter(loc_db, sys.argv[1])
|
||||
|
||||
start_addr = 0xFFFFFF8008080000
|
||||
end_addr = start_addr + 0x8000000
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ from miasm.core.utils import decode_hex
|
|||
from miasm.analysis.machine import Machine
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, \
|
||||
EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
machine = Machine("x86_32")
|
||||
jitter = machine.jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
jitter = machine.jitter(loc_db, sys.argv[1])
|
||||
|
||||
# Prepare stack and reset memory accesses to avoid an exception
|
||||
jitter.vm.add_memory_page(0x10000, PAGE_READ|PAGE_WRITE, b"\x00"*0x1000, "stack")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import sys
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.analysis.machine import Machine
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
myjit = Machine("x86_32").jitter(sys.argv[1])
|
||||
loc_db = LocationDB()
|
||||
myjit = Machine("x86_32").jitter(loc_db, sys.argv[1])
|
||||
|
||||
base_addr = 0x13371337
|
||||
page_size = 0x1000
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ from miasm.analysis.machine import Machine
|
|||
import miasm.os_dep.common as commonapi
|
||||
from miasm.core.utils import pck32
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
machine = Machine("x86_32")
|
||||
|
||||
jit = machine.jitter()
|
||||
loc_db = LocationDB()
|
||||
jit = machine.jitter(loc_db)
|
||||
jit.init_stack()
|
||||
|
||||
class TestCommonAPI(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ from miasm.analysis.machine import Machine
|
|||
import miasm.os_dep.linux_stdlib as stdlib
|
||||
from miasm.core.utils import pck32
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
machine = Machine("x86_32")
|
||||
|
||||
jit = machine.jitter()
|
||||
loc_db = LocationDB()
|
||||
jit = machine.jitter(loc_db)
|
||||
jit.init_stack()
|
||||
|
||||
heap = stdlib.linobjs.heap
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from pdb import pm
|
|||
from miasm.analysis.binary import Container
|
||||
from miasm.analysis.sandbox import Sandbox_Linux_x86_32, Sandbox_Linux_x86_64,\
|
||||
Sandbox_Linux_arml, Sandbox_Linux_aarch64l
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: %s <arch> ..." % sys.argv[0])
|
||||
|
|
@ -29,7 +30,8 @@ parser.add_argument("filename", help="ELF Filename")
|
|||
options = parser.parse_args(sys.argv[2:])
|
||||
|
||||
# Create sandbox
|
||||
sb = sandbox(options.filename, options, globals())
|
||||
loc_db = LocationDB()
|
||||
sb = sandbox(loc_db, options.filename, options, globals())
|
||||
|
||||
# Run
|
||||
sb.run()
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ import miasm.os_dep.win_api_x86_32 as winapi
|
|||
from miasm.os_dep.win_api_x86_32 import get_win_str_a, get_win_str_w
|
||||
from miasm.core.utils import pck32
|
||||
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
machine = Machine("x86_32")
|
||||
|
||||
jit = machine.jitter()
|
||||
loc_db = LocationDB()
|
||||
jit = machine.jitter(loc_db)
|
||||
jit.init_stack()
|
||||
|
||||
heap = winapi.winobjs.heap
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue