Skip to content

Commit

Permalink
[target-remote] Basic support for the target remote command
Browse files Browse the repository at this point in the history
  • Loading branch information
ValekoZ committed Dec 6, 2023
1 parent 295cbf7 commit 558b712
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6006,6 +6006,13 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None:
# This prevents some spurious errors being thrown during startup
gef.session.remote_initializing = True
gef.session.remote = GefRemoteSessionManager(args.host, args.port, args.pid, qemu_binary)

dbg(f"[remote] initializing remote session with {gef.session.remote.target} under {gef.session.remote.root}")
if not gef.session.remote.connect(args.pid):
raise EnvironmentError(f"Cannot connect to remote target {gef.session.remote.target}")
if not gef.session.remote.setup():
raise EnvironmentError(f"Failed to create a proper environment for {gef.session.remote.target}")

gef.session.remote_initializing = False
reset_all_caches()
gdb.execute("context")
Expand Down Expand Up @@ -10861,12 +10868,6 @@ def __init__(self, host: str, port: int, pid: int =-1, qemu: Optional[pathlib.Pa
self.__local_root_fd = tempfile.TemporaryDirectory()
self.__local_root_path = pathlib.Path(self.__local_root_fd.name)
self.__qemu = qemu
dbg(f"[remote] initializing remote session with {self.target} under {self.root}")
if not self.connect(pid):
raise EnvironmentError(f"Cannot connect to remote target {self.target}")
if not self.setup():
raise EnvironmentError(f"Failed to create a proper environment for {self.target}")
return

def close(self) -> None:
self.__local_root_fd.cleanup()
Expand Down Expand Up @@ -11136,6 +11137,14 @@ def reset_caches(self) -> None:
return


def target_remote_posthook():
if gef.session.remote_initializing:
return

gef.session.remote = GefRemoteSessionManager('', 0)
if not gef.session.remote.setup():
raise EnvironmentError(f"Failed to create a proper environment for {gef.session.remote}")

if __name__ == "__main__":
if sys.version_info[0] == 2:
err("GEF has dropped Python2 support for GDB when it reached EOL on 2020/01/01.")
Expand Down Expand Up @@ -11220,6 +11229,13 @@ def reset_caches(self) -> None:
gdb.execute(f"define target hook-remote\n{hook}\nend")
gdb.execute(f"define target hook-extended-remote\n{hook}\nend")

gdb.execute("""
define target hookpost-remote
pi target_remote_posthook()
context
end
""")

# restore saved breakpoints (if any)
bkp_fpath = pathlib.Path(gef.config["gef.autosave_breakpoints_file"]).expanduser().absolute()
if bkp_fpath.exists() and bkp_fpath.is_file():
Expand Down

0 comments on commit 558b712

Please sign in to comment.