Skip to content

Commit

Permalink
Search for realpath in remote sessions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonmessmer committed Jun 1, 2024
1 parent 2e6166f commit 8cd572b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,30 @@ def size(self) -> int:
raise AttributeError
return self.page_end - self.page_start

def search_for_realpath(self) -> str:
# This function is a workaround for gdb bug #23764
# path might be wrong for remote sessions, so try a simple search for files
# that aren't found at the path indicated, which should be canonical.

# First, try the canonical path in the remote session root.
candidate1 = f"{gef.session.remote.root}/{self.path}"
if pathlib.Path(candidate1).is_file():
return candidate1

# On some systems, /lib(64) might be a symlink to /usr/lib(64), so try removing
# the /usr prefix.
if self.path.startswith("/usr"):
candidate = f"{gef.session.remote.root}/{self.path[4:]}"
if pathlib.Path(candidate).is_file():
return candidate

# Base case, return the original realpath
return candidate1

@property
def realpath(self) -> str:
# when in a `gef-remote` session, realpath returns the path to the binary on the local disk, not remote
return self.path if gef.session.remote is None else f"{gef.session.remote.root}/{self.path}"
return self.path if gef.session.remote is None else self.search_for_realpath()

def __str__(self) -> str:
return (f"Section(start={self.page_start:#x}, end={self.page_end:#x}, "
Expand Down

0 comments on commit 8cd572b

Please sign in to comment.