From 3e4ad608af25f4cca0333e3c3421b9747ec63681 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Tue, 14 Sep 2021 00:11:53 +0200 Subject: [PATCH] Fixes #955: don't return 'target:' prefix in pwndbg.proc.exe Before this commit the `pwndbg.proc.exe` could return a "target:" prefix when `pwndbg.proc.exe` was executed on remote targets. This could be seen by: 1. Executing gdbserver in one terminal: gdbserver 127.0.0.1:1234 `which ps` 2. Executing `gdb -ex 'target remote :1234'` in another terminal and then invoking `pi pwndbg.proc.exe`. This resulted in `checksec` (and some other) commands crashes which were using the `pwndbg.file.get_fille` functionality as it downloaded the remote file by using the `gdb.execute("remote get %s %s")` command passing it a path prefixed with `"target:"` which this GDB command does not support. --- pwndbg/proc.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pwndbg/proc.py b/pwndbg/proc.py index d3b747170..729c79905 100644 --- a/pwndbg/proc.py +++ b/pwndbg/proc.py @@ -58,7 +58,19 @@ class module(ModuleType): @property def exe(self): - return gdb.current_progspace().filename + """ + We lstrip "target:" for remote debugging. Otherwise, the + `pwndbg.file.get_file(pwndbg.proc.exe)` would not work on remote targets. + + This should not be a problem on local targets as `gdb.current_progspace().filename` + seems to return absolute paths. + """ + fn = gdb.current_progspace().filename + + if fn.startswith('target:'): + return fn[7:] # len('target') == 7 + + return fn @property def mem_page(self):