From 8cd572b60884719f1bad2df41c3b5675ec11abe5 Mon Sep 17 00:00:00 2001 From: Gordon Messmer Date: Sat, 1 Jun 2024 12:32:26 -0700 Subject: [PATCH] Search for realpath in remote sessions. --- gef.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gef.py b/gef.py index e4f0198e7..186441276 100644 --- a/gef.py +++ b/gef.py @@ -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}, "