Exemplo n.º 1
0
    '''
    # map 2MB memory for this emulation
    panda.map_memory("mymem", 2 * 1024 * 1024, ADDRESS)

    # Write code into memory
    panda.physical_memory_write(ADDRESS, bytes(encoding))

    # Set up registers
    cpu.env_ptr.active_tc.gpr[8] = 0x10

    # Set starting_pc
    cpu.env_ptr.active_tc.PC = ADDRESS


# Always run insn_exec
panda.cb_insn_translate(lambda x, y: True)

md = capstone.Cs(capstone.CS_ARCH_MIPS, 4)  # misp32


@panda.cb_insn_exec
def on_insn(cpu, pc):
    '''
    At each instruction, print capstone disassembly.
    '''
    if pc >= stop_addr:
        print("Finished execution")
        #dump_regs(panda, cpu)
        print("Register t0 contains:", hex(cpu.env_ptr.active_tc.gpr[8]))
        print("Register t1 contains:", hex(cpu.env_ptr.active_tc.gpr[9]))
        os._exit(0)  # TODO: we need a better way to stop here