Fix exceptions during reverse execution in btrace (#1998)

pull/2003/head
∂ω∂ 2 years ago committed by GitHub
parent 9ea8b98afb
commit c340cc4740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,6 +52,9 @@ def get(
Returns:
A list representing pointers of each ```address``` and reference
"""
if address is None:
return None
limit = int(limit)
result = [address] if include_start else []
@ -78,6 +81,10 @@ def get(
result.append(address)
except gdb.MemoryError:
break
except gdb.error as e:
if str(e) == "value is not available":
break
raise
return result
@ -107,6 +114,9 @@ def format(value, limit=LIMIT, code=True, offset=0, hard_stop=None, hard_end=0,
A string representing pointers of each address and reference
Strings format: 0x0804a10 0x08061000 0x41414141
"""
if value is None:
return "<unavailable>"
limit = int(limit)
# Allow results from get function to be passed to format

@ -88,6 +88,9 @@ def comment(x: object) -> str:
def format_flags(value, flags, last=None):
if value is None:
return "<unavailable>"
desc = flag_value("%#x" % value)
if not flags:
return desc

@ -108,7 +108,12 @@ def telescope(
else:
telescope.offset = 0
address = int(address if address else pwndbg.gdblib.regs.sp) & pwndbg.gdblib.arch.ptrmask
address = address if address else pwndbg.gdblib.regs.sp
if address is None:
print("Cannot display stack frame because stack pointer is unavailable")
return
address = int(address) & pwndbg.gdblib.arch.ptrmask
input_address = address
count = max(int(count), 1) & pwndbg.gdblib.arch.ptrmask
delimiter = T.delimiter(offset_delimiter)

@ -6,6 +6,7 @@ address +/- a few instructions.
from __future__ import annotations
import collections
import re
from typing import DefaultDict
from typing import List
from typing import Union
@ -296,7 +297,15 @@ def near(address, instructions=1, emulate=False, show_prev_insns=True):
# If we hit the current instruction, we can do emulation going forward from there.
if address == pc and emulate and (not first_time_emulate or can_run_first_emulate()):
emu = pwndbg.emu.emulator.Emulator()
try:
emu = pwndbg.emu.emulator.Emulator()
except gdb.error as e:
message = str(e)
match = re.search(r"Memory at address (\w+) unavailable\.", message)
if match:
return []
else:
raise
# skip current line
emu.single_step()

@ -128,6 +128,8 @@ class DisassemblyAssistant(pwndbg.disasm.arch.DisassemblyAssistant):
return False
efl = pwndbg.gdblib.regs.eflags
if efl is None:
return False
cf = efl & (1 << 0)
pf = efl & (1 << 2)

@ -5,6 +5,8 @@ Reading, writing, and describing memory.
from __future__ import annotations
import re
import gdb
import pwndbg.gdblib.arch
@ -45,7 +47,13 @@ def read(addr: int, count: int, partial: bool = False) -> bytearray:
if not hasattr(e, "message"):
e.message = str(e)
stop_addr = int(e.message.split()[-1], 0)
stop_addr = addr
match = re.search(r"Memory at address (\w+) unavailable\.", e.message)
if match:
stop_addr = int(match.group(1), 0)
else:
stop_addr = int(e.message.split()[-1], 0)
if stop_addr != addr:
return read(addr, stop_addr - addr)

Loading…
Cancel
Save