예제 #1
0
def test_code_mem_fault(dbg):
    address = 0x80
    with pytest.raises(MemFaultError) as info:
        dbg.run(address=address)
    assert info.value.cause is FaultCause.UNMAPPED
    assert info.value.access == Access.execute(address)
    assert info.value.address == address
예제 #2
0
def test_write_error(emu):
    address = 0x1001
    data = b'3' * 3

    with pytest.raises(MemoryAccessError) as info:
        emu.mem.write(address, data)
    assert info.value.access == Access(AccessType.W, address, len(data), data)
예제 #3
0
def test_read_error(emu):
    address = 0x80
    size = 0x11

    with pytest.raises(MemoryAccessError) as info:
        emu.mem.read(address, size)
    assert info.value.access == Access.read(address, size)
예제 #4
0
def test_mem_fault(dbg):
    address = 0xDEADBEEF
    value = 0xFAFAFAFA

    dbg.mem.write_code(CODE_ADDRESS,
                       f'LDR R0, ={address}; LDR R1, ={value}; STR R1, [R0]')
    with pytest.raises(MemFaultError) as info:
        dbg.run(3)
    assert info.value.cause is FaultCause.UNMAPPED
    assert info.value.access == Access(AccessType.W, address, 4,
                                       dbg.arch.encode_word(value))
    assert info.value.address == CODE_ADDRESS + 8

    assert repr(
        info.value
    ) == f'MemFaultError(0x{CODE_ADDRESS + 8:X}, FaultCause.UNMAPPED, {info.value.access!r})'
예제 #5
0
def test_bad_split_write(mem):
    seg = mem.map(0x100000, 0x80)
    with pytest.raises(MemoryAccessError) as info:
        mem.write(seg.end - 2, b'AAAA')

    assert info.value.access == Access.write(seg.end - 2, b'AAAA')
예제 #6
0
def test_repr():
    address = 0x1000
    access = Access(AccessType.W, address, 5, b'AAAA')
    assert hex(address) in repr(access)
예제 #7
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')
예제 #8
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)