Don't catch the error of the heap commands when `set exception-* on` (#1270)

* Don't catch the error of the heap commands for developers

* Use `pwndbg.config` and re-raise the error

See https://github.com/pwndbg/pwndbg/pull/1270#discussion_r992209956

* Update pwndbg/commands/__init__.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
This commit is contained in:
Alan Li 2022-10-12 18:30:23 +08:00 committed by GitHub
parent 8da9c5b9f9
commit 75ece8e2a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import pwndbg.exception
import pwndbg.gdblib.memory
import pwndbg.gdblib.regs
import pwndbg.gdblib.symbol
import pwndbg.heap
import pwndbg.hexdump
import pwndbg.ui
from pwndbg.heap.ptmalloc import SymbolUnresolvableError
@ -276,6 +277,7 @@ def OnlyWithResolvedHeapSyms(function):
e = lambda s: print(message.error(s))
w = lambda s: print(message.warn(s))
if pwndbg.heap.current.can_be_resolved():
# Note: We will still raise the error for developers when exception-* is set to "on"
try:
return function(*a, **kw)
except SymbolUnresolvableError as err:
@ -283,14 +285,18 @@ def OnlyWithResolvedHeapSyms(function):
w(
f"You can try to determine the libc symbols addresses manually and set them appropriately. For this, see the `heap_config` command output and set the config about `{err.symbol}`."
)
if pwndbg.config.exception_verbose.value or pwndbg.config.exception_debugger.value:
raise err
except Exception as err:
e(f"{function.__name__}: Unknown error: `{err}` when running this symbols.")
e(f"{function.__name__}: An unknown error occurred when running this command.")
if pwndbg.config.resolve_heap_via_heuristic:
w(
"Maybe you can try to determine the libc symbols addresses manually, set them appropriately and re-run this command. For this, see the `heap_config` command output and set the `main_arena`, `mp_`, `global_max_fast`, `tcache` and `thread_arena` addresses."
)
else:
w("You can try `set resolve-heap-via-heuristic on` and re-run this command.\n")
if pwndbg.config.exception_verbose or pwndbg.config.exception_debugger:
raise err
else:
print(message.error(f"{function.__name__}: "), end="")
if not pwndbg.config.resolve_heap_via_heuristic: