本文整理汇总了Python中miasm2.analysis.machine.Machine类的典型用法代码示例。如果您正苦于以下问题:Python Machine类的具体用法?Python Machine怎么用?Python Machine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Machine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jit_instructions
def jit_instructions(mn_str):
"""JIT instructions and return the jitter object."""
# Get the miasm2 Machine
machine = Machine("mepb")
mn_mep = machine.mn()
# Assemble the instructions
asm = ""
for instr_str in mn_str.split("\n"):
instr = mn_mep.fromstring(instr_str, "b")
instr.mode = "b"
asm += mn_mep.asm(instr)[0]
# Init the jitter and add the assembled instructions to memory
jitter = machine.jitter(jit_type="gcc")
jitter.vm.add_memory_page(0, PAGE_READ | PAGE_WRITE, asm)
# Set the breakpoint
jitter.add_breakpoint(len(asm), lambda x: False)
# Jit the instructions
#jitter.init_stack()
jitter.init_run(0)
jitter.continue_run()
return jitter
示例2: run
def run(self):
# Architecture
architecture = False
if self.args.architecture:
architecture = self.args.architecture
else:
with open(self.args.filename) as fdesc:
architecture = ArchHeuristic(fdesc).guess()
if not architecture:
raise ValueError("Unable to recognize the architecture, please specify it")
if self.args.verbose:
print "Guessed architecture: %s" % architecture
cont = Container.from_stream(open(self.args.filename))
machine = Machine(architecture)
addr_size = machine.ira().pc.size / 4
fh = FuncHeuristic(cont, machine)
# Enable / disable heuristics
for name in self.args.enable_heuristic:
heur = fh.name2heuristic(name)
if heur not in fh.heuristics:
fh.heuristics.append(heur)
for name in self.args.disable_heuristic:
heur = fh.name2heuristic(name)
fh.heuristics.remove(heur)
if self.args.verbose:
print "Heuristics to run: %s" % ", ".join(fh.heuristic_names)
# Launch guess
fmt = "0x{:0%dx}" % addr_size
for addr in fh.guess():
print fmt.format(addr)
示例3: main
def main():
native_code = assemble_text(asm_helloworld, [("L_MAIN", 0)])
mach = Machine("x86_64")
jitter = mach.jitter(jit_type="tcc")
run_addr =0x40000000
jitter.init_stack()
jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, native_code)
jitter.push_uint64_t(0xdeadbeef)
jitter.add_breakpoint(0xdeadbeef, on_exit)
jitter.jit.log_mn = True
jitter.init_run(run_addr)
jitter.continue_run()
示例4: do_trace
def do_trace(self):
'''Run miasm and construct the trace'''
self.trace = Trace()
# Retrieve miasm tools
machine = Machine(self.machine)
jitter = machine.jitter("python")
# Set the jitter to use our custom emulator
jitter.jit.symbexec = CustomEmulatedSymbExec(
jitter.cpu, jitter.vm, jitter.jit.ir_arch, {})
jitter.jit.symbexec.enable_emulated_simplifications()
jitter.jit.symbexec.reset_regs()
elf = vm_load_elf(jitter.vm, open(self.program, "rb").read())
# Init segment
jitter.ir_arch.do_stk_segm = True
jitter.ir_arch.do_ds_segm = True
jitter.ir_arch.do_str_segm = True
jitter.ir_arch.do_all_segm = True
FS_0_ADDR = 0x7ff70000
jitter.cpu.FS = 0x4
jitter.cpu.set_segm_base(jitter.cpu.FS, FS_0_ADDR)
jitter.vm.add_memory_page(
FS_0_ADDR + 0x28, PAGE_READ, "\x42\x42\x42\x42\x42\x42\x42\x42")
# Init stack and push main args
jitter.init_stack()
jitter.push_uint64_t(1)
jitter.vm.add_memory_page(0x800000, PAGE_READ, self.program)
jitter.push_uint64_t(0x800000)
jitter.push_uint64_t(0xDEADDEAD)
jitter.add_breakpoint(0xDEADDEAD, self.end_do_trace)
jitter.add_breakpoint(0x1337beef, self.end_func)
jitter.add_breakpoint(self.address, self.begin_func)
# Run the execution
if self.main_address is None:
jitter.init_run(elf.Ehdr.entry)
else:
jitter.init_run(self.main_address)
jitter.continue_run()
assert jitter.run == False
return self.trace
示例5: __init__
def __init__(self, jitter_engine):
self.machine = Machine(self.arch_name)
self.myjit = self.machine.jitter(jitter_engine)
self.myjit.init_stack()
self.myjit.jit.log_regs = False
self.myjit.jit.log_mn = False
示例6: __init__
class ethRE:
def __init__(self):
self.machine = Machine("evm")
self.mn = self.machine.mn
def get_bytecode(self, account_addr):
code = evm_env.code(int(account_addr[2:],16))
code = code[2:] # To remove '0x'..
if len(code) % 2 == 1:
code = "0"+code
code = binascii.unhexlify(code)
return code
def from_bytecode(self, bytecode):
container = Container.from_string(bytecode)
mdis = self.machine.dis_engine(container.bin_stream)
self.blks = mdis.dis_multibloc(0)
def from_asm(self, asm_text):
all_bloc, symbol_pool = parse_asm.parse_txt(self.mn,0, asm_text)
self.blks = all_bloc
raise Exception("Not correctly implemented")
def graph(self):
if not self.blks:
raise Exception("Need to parse bytecode before")
return self.blks.dot()
示例7: __init__
def __init__(self, jitter_engine):
self.myjit = Machine(self.arch_name).jitter(jitter_engine)
self.myjit.stack_base = 0x1000
self.myjit.stack_size = 0x1000
self.myjit.init_stack()
self.myjit.jit.log_regs = False
self.myjit.jit.log_mn = False
示例8: init_jitter
def init_jitter():
global data, run_addr
# Create jitter
myjit = Machine("x86_32").jitter(sys.argv[1])
myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, data)
# Init jitter
myjit.init_stack()
myjit.set_trace_log()
myjit.push_uint32_t(0x1337beef)
myjit.add_breakpoint(0x1337beef, code_sentinelle)
return myjit
示例9: Asm_Test
class Asm_Test(object):
def __init__(self):
self.myjit = Machine("x86_32").jitter()
self.myjit.init_stack()
self.myjit.jit.log_regs = False
self.myjit.jit.log_mn = False
def __call__(self):
self.asm()
self.run()
self.check()
def asm(self):
blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, self.TXT,
symbol_pool = self.myjit.ir_arch.symbol_pool)
# fix shellcode addr
symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0)
s = StrPatchwork()
patches = asmbloc.asm_resolve_final(mn_x86, blocs[0], symbol_pool)
for offset, raw in patches.items():
s[offset] = raw
s = str(s)
self.assembly = s
def run(self):
run_addr = 0
self.myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
self.myjit.push_uint32_t(0x1337beef)
self.myjit.add_breakpoint(0x1337beef, lambda x:False)
self.myjit.init_run(run_addr)
self.myjit.continue_run()
assert(self.myjit.pc == 0x1337beef)
def check(self):
raise NotImplementedError('abstract method')
示例10: main
def main():
sc = assemble_text(asm_helloworld, [("L_MAIN", 0)])
mach = Machine("x86_64")
jitter = mach.jitter(jit_type="tcc")
run_addr =0x40000000
jitter.init_stack()
jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, sc)
jitter.push_uint64_t(0xdeadbeef)
jitter.add_breakpoint(0xdeadbeef, on_exit)
#jitter.jit.log_regs = True
jitter.jit.log_mn = True
init_syscall(jitter)
jitter.vm.add_memory_page(ADDR_COUNTER, PAGE_READ | PAGE_WRITE, "\x00" * 8)
jitter.init_run(run_addr)
jitter.continue_run()
print "MOV: %d" % unpack("I", jitter.vm.get_mem(ADDR_COUNTER, 4))[0]
示例11: Arch
class Arch(object):
"""
Parent class for Arch abstraction
"""
# Architecture name
_ARCH_ = None
def __init__(self):
self.machine = Machine(self._ARCH_)
self.jitter = self.machine.jitter(self.options.jitter)
@classmethod
def update_parser(cls, parser):
pass
示例12: __init__
def __init__(self, testcreator, replayed_snapshot):
'''
@testcreator: TestCreator instance with associated information
@replayed_snapshot: snapshot to be used
'''
self.isFuncFound = False
self.filename = testcreator.program
self.learned_addr = testcreator.address
self.snapshot = replayed_snapshot
self.replayexception = []
self.abicls = testcreator.abicls
self.machine = Machine(testcreator.machine)
self.trace = testcreator.trace
self.logger = testcreator.logger
self.ira = self.machine.ira()
self.ptr_size = self.ira.sizeof_pointer()/8
示例13: Asm_Test
class Asm_Test(object):
def __init__(self, jitter):
self.myjit = Machine("mips32l").jitter(jitter)
self.myjit.init_stack()
def __call__(self):
self.asm()
self.run()
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)
# fix shellcode addr
loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0)
s = StrPatchwork()
patches = asmblock.asm_resolve_final(mn_mips32, blocks, loc_db)
for offset, raw in patches.items():
s[offset] = raw
s = str(s)
self.assembly = s
def run(self):
run_addr = 0
self.myjit.vm.add_memory_page(
run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
self.myjit.cpu.RA = 0x1337beef
self.myjit.add_breakpoint(0x1337beef, lambda x: False)
self.myjit.init_run(run_addr)
self.myjit.continue_run()
assert(self.myjit.pc == 0x1337beef)
def check(self):
raise NotImplementedError('abstract method')
示例14: __init__
def __init__(self, abicls, machine):
self.abicls = abicls
self.input_reg = {}
self.output_reg = {}
self._previous_addr = 0
self._current_addr = 0
self._instr_count = 0
self._pending_call = []
# Function addr -> list of information on calls
self.function_calls = {}
self.paths = DiGraph()
self.in_memory = {}
self.out_memory = {}
self._ira = Machine(machine).ira()
self._ptr_size = self._ira.sizeof_pointer()/8
self.sp = self._ira.sp.name
示例15: Asm_Test_16
class Asm_Test_16(Asm_Test):
arch_name = "x86_16"
arch_attrib = 16
ret_addr = 0x1337
def __init__(self, jitter_engine):
self.myjit = Machine(self.arch_name).jitter(jitter_engine)
self.myjit.stack_base = 0x1000
self.myjit.stack_size = 0x1000
self.myjit.init_stack()
def init_machine(self):
self.myjit.vm.add_memory_page(self.run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
self.myjit.push_uint16_t(self.ret_addr)
self.myjit.add_breakpoint(self.ret_addr, lambda x:False)