Refactor pwndbg.proc.exe and pwndbg.proc.get_file

Revert the change from 3e4ad60 and make the `pwndbg.proc.get_file` to strip the "target:" prefix instead of the `pwndbg.proc.exe`.

This way, we will prevent bugs when pwndbg code would use `pwndbg.proc.exe` on remote targets but not pass the returned path to `pwndbg.proc.get_file` to get the real remote file and instead use the local one (if it exists in the same path).

Additionally, we assert the `path` passed to `pwndbg.proc.get_file` so we prevent incorrect use of the function when an absolute path or not a remote path is passed to it.
pull/958/head
Disconnect3d 4 years ago
parent 933be39838
commit 790ba574c0

@ -22,13 +22,23 @@ def get_file(path):
Downloads the specified file from the system where the current process is Downloads the specified file from the system where the current process is
being debugged. being debugged.
If the `path` is prefixed with "target:" the prefix is stripped
(to support remote target paths properly).
Returns: Returns:
The local path to the file The local path to the file
""" """
assert path.startswith('/') or path.startswith('target:'), "get_file called with incorrect path"
if path.startswith('target:'):
path = path[7:] # len('target:') == 7
local_path = path local_path = path
qemu_root = pwndbg.qemu.root() qemu_root = pwndbg.qemu.root()
if qemu_root: if qemu_root:
return os.path.join(qemu_root, path) return os.path.join(qemu_root, path)
elif pwndbg.remote.is_remote(): elif pwndbg.remote.is_remote():
if not pwndbg.qemu.is_qemu(): if not pwndbg.qemu.is_qemu():
local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir) local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir)

@ -59,21 +59,17 @@ class module(ModuleType):
@property @property
def exe(self): def exe(self):
""" """
We lstrip "target:" for remote debugging. Otherwise, the Returns the debugged file name.
`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` On remote targets, this may be prefixed with "target:" string.
seems to return absolute paths. See this by executing those in two terminals:
1. gdbserver 127.0.0.1:1234 /bin/ls
2. gdb -ex "target remote :1234" -ex "pi pwndbg.proc.exe"
DO NOT USE THIS if you want to process the debugged file with another tool. If you need to process the debugged file use:
For this, use `pwndbg.file.get_file` as it supports remote target. `pwndbg.file.get_file(pwndbg.proc.exe)`
""" """
fn = gdb.current_progspace().filename return gdb.current_progspace().filename
if fn.startswith('target:'):
return fn[7:] # len('target') == 7
return fn
@property @property
def mem_page(self): def mem_page(self):

Loading…
Cancel
Save