def get_emulator(arch, isa): emu = Emulator(arch) map_code_segment(emu, 'code', CODE_ADDRESS, isa) emu.mem.map(DATA_ADDRESS, DATA_SIZE, 'data', AccessType.RW) emu.mem.default_isa = isa emu.sp = STACK_ADDRESS emu.jump(CODE_ADDRESS, isa) return emu
def test_copy(emu: Emulator): emu.mem.map(0x1000, 0x80) emu.mem.write_code(0x1000, 'NOP; NOP; NOP') emu.mem.write(0x1040, b'AAAA') emu.jump(0x1000) other = emu.copy() emu.mem.write(0x1040, b'BBBB') emu.run(3) assert emu.pc == 0x100C assert other.pc == 0x1000 assert other.mem.read(0x1040, 4) == b'AAAA'
from megastone import Emulator, ARCH_ARM64, HOOK_STOP_ONCE emu = Emulator(ARCH_ARM64) segment = emu.mem.allocate(0x1000, 'code') emu.mem.write_code( segment.address, """ start: MOV X0, 0 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 ADD X0, X0, 1 B start """) emu.add_breakpoint(segment.address + 0x8) emu.add_code_hook(HOOK_STOP_ONCE, segment.address + 0x10) emu.add_breakpoint(segment.address + 0x18) emu.add_code_hook(lambda e: print(e.get_curr_insn(), e.regs.x0)) emu.jump(segment.address) for _ in range(5): print(emu.run())