def emu(dev, regdev): emu = ms.Emulator(ms.ARCH_ARM) emu.mem.map(CODE_ADDR, SEG_SIZE, 'code') emu.jump(CODE_ADDR) dev.attach(emu) regdev.attach(emu) return emu
def test_code(code): emu = ms.Emulator(ARCH) data = ARCH.default_isa.assemble(code, BASE) emu.mem.load(BASE, data, 'seg') emu.mem.map(RO_ADDR, ms.Emulator.PAGE_SIZE, 'rodata', ms.AccessType.R) emu.add_code_hook(ms.HOOK_STOP, BASE + len(data)) emu.add_code_hook(trace_func) try: emu.run(address=BASE) except ms.CPUError as e: print(e)
def create_emu(arch): emu = ms.Emulator(arch) emu.mem.map(CODE_ADDRESS, 0x1000, 'code') emu.mem.map(DATA_ADDRESS, 0x1000, 'data') nop = arch.default_isa.assemble('nop') emu.mem.write(CODE_ADDRESS, nop * NUM_NOPS) emu.regs.retval = REG_VALUE emu.sp = SP_VALUE emu.jump(CODE_ADDRESS) return emu
import megastone as ms isa = ms.ISA_ARM emu = ms.Emulator(ms.ARCH_ARM) seg = emu.mem.allocate(0x1000) emu.mem.write_code(seg.address, """ PUSH {LR} ADD R0, R1 ADD R0, R2 POP {PC} """, isa) emu.allocate_stack() emu.regs.set(r0=3, r1=5, r2=1) print(emu.run_function(seg.address, isa=isa)) print(emu.run_function(seg.address, isa=isa))
def test_unsupported(): emu = ms.Emulator(ms.ARCH_X86_16) with pytest.raises(ms.UnsupportedError): ms.GDBServer(emu)