コード例 #1
0
def test_stop_hook(arch_dbg: Debugger, nop):
    hook_addr = CODE_ADDRESS + 10 * len(nop)

    arch_dbg.add_code_hook(HOOK_STOP, hook_addr)

    for _ in range(3):
        reason = arch_dbg.run()
        assert reason.type is StopType.HOOK
        assert reason.hook.func is HOOK_STOP
        assert arch_dbg.pc == hook_addr

    arch_dbg.step()
    assert arch_dbg.pc == hook_addr
コード例 #2
0
def test_replace_func_arm(armthumb_dbg: Debugger, arm_isa, other_arm_isa):
    armthumb_dbg.mem.write_code(
        CODE_ADDRESS, f"""
        MOV R0, #3
        MOV R1, #4
        BLX 0x{other_arm_isa.address_to_pointer(CODE2_ADDRESS):X}
        MOV R4, R0
        {'nop;'*30}
    """)

    armthumb_dbg.mem.write_code(CODE2_ADDRESS,
                                f"""
        MOV R0, 15
        BX LR
    """,
                                isa=other_arm_isa)

    armthumb_dbg.add_breakpoint(CODE_ADDRESS + 0x20)

    armthumb_dbg.run()
    assert armthumb_dbg.regs.r4 == 15

    armthumb_dbg.replace_function(CODE2_ADDRESS, arm_replacement_func)
    armthumb_dbg.run(address=CODE_ADDRESS, isa=arm_isa)
    assert armthumb_dbg.regs.r4 == 7
コード例 #3
0
def test_breakpoint(arch_dbg: Debugger, isa, nop):
    break_addr = CODE_ADDRESS + 3 * len(nop)
    stop_addr = break_addr + len(nop)

    arch_dbg.add_breakpoint(break_addr)
    arch_dbg.add_code_hook(HOOK_STOP, stop_addr)

    for _ in range(3):
        arch_dbg.run()
        assert arch_dbg.pc == break_addr

        arch_dbg.run()
        assert arch_dbg.pc == stop_addr

        arch_dbg.jump(CODE_ADDRESS, isa=isa)
コード例 #4
0
def test_stop_once_hook(arch_dbg: Debugger, isa, nop):
    hook_addr = CODE_ADDRESS + 10 * len(nop)
    stop_addr = hook_addr + 5 * len(nop)

    arch_dbg.add_code_hook(HOOK_STOP_ONCE, hook_addr)
    arch_dbg.add_code_hook(HOOK_STOP, stop_addr)

    arch_dbg.run()
    assert arch_dbg.pc == hook_addr

    arch_dbg.run()
    assert arch_dbg.pc == stop_addr

    arch_dbg.run(address=CODE_ADDRESS, isa=isa)
    assert arch_dbg.pc == stop_addr
コード例 #5
0
def test_rw_hook(rw_test_dbg: Debugger, access_hook):
    rw_test_dbg.add_access_hook(access_hook, TEST_ADDRESS)
    rw_test_dbg.run()
    assert access_hook.count == 2
コード例 #6
0
def test_write_hook(rw_test_dbg: Debugger, access_hook):
    rw_test_dbg.add_write_hook(access_hook, TEST_ADDRESS)
    rw_test_dbg.run()
    assert access_hook.count == 1
    assert access_hook.access == Access.write(TEST_ADDRESS, b'\x03')
コード例 #7
0
def test_read_hook(rw_test_dbg: Debugger, access_hook):
    rw_test_dbg.add_read_hook(access_hook, TEST_ADDRESS)
    rw_test_dbg.run()
    assert access_hook.count == 1
    assert access_hook.access == Access.read(TEST_ADDRESS, 1)