MCPcopy Create free account
hub / github.com/HexHive/NASS / GefRemoteSessionManager

Class GefRemoteSessionManager

tools/gef.py:10617–10799  ·  view source on GitHub ↗

Class for managing remote sessions with GEF. It will create a temporary environment designed to clone the remote one.

Source from the content-addressed store, hash-verified

10615 return self._root
10616
10617class GefRemoteSessionManager(GefSessionManager):
10618 """Class for managing remote sessions with GEF. It will create a temporary environment
10619 designed to clone the remote one."""
10620 def __init__(self, host: str, port: int, pid: int =-1, qemu: Optional[pathlib.Path] = None) -> None:
10621 super().__init__()
10622 self.__host = host
10623 self.__port = port
10624 self.__local_root_fd = tempfile.TemporaryDirectory()
10625 self.__local_root_path = pathlib.Path(self.__local_root_fd.name)
10626 self.__qemu = qemu
10627 dbg(f"[remote] initializing remote session with {self.target} under {self.root}")
10628 if not self.connect(pid):
10629 raise EnvironmentError(f"Cannot connect to remote target {self.target}")
10630 if not self.setup():
10631 raise EnvironmentError(f"Failed to create a proper environment for {self.target}")
10632 return
10633
10634 def close(self) -> None:
10635 self.__local_root_fd.cleanup()
10636 try:
10637 gef_on_new_unhook(self.remote_objfile_event_handler)
10638 gef_on_new_hook(new_objfile_handler)
10639 except Exception as e:
10640 warn(f"Exception while restoring local context: {str(e)}")
10641 return
10642
10643 def in_qemu_user(self) -> bool:
10644 return self.__qemu is not None
10645
10646 def __str__(self) -> str:
10647 return f"RemoteSession(target='{self.target}', local='{self.root}', pid={self.pid}, qemu_user={bool(self.in_qemu_user())})"
10648
10649 @property
10650 def target(self) -> str:
10651 return f"{self.__host}:{self.__port}"
10652
10653 @property
10654 def root(self) -> pathlib.Path:
10655 return self.__local_root_path.absolute()
10656
10657 @property
10658 def file(self) -> pathlib.Path:
10659 """Path to the file being debugged as seen by the remote endpoint."""
10660 if not self._file:
10661 filename = gdb.current_progspace().filename
10662 if not filename:
10663 raise RuntimeError("No session started")
10664 start_idx = len("target:") if filename.startswith("target:") else 0
10665 self._file = pathlib.Path(filename[start_idx:])
10666 return self._file
10667
10668 @property
10669 def lfile(self) -> pathlib.Path:
10670 """Local path to the file being debugged."""
10671 return self.root / str(self.file).lstrip("/")
10672
10673 @property
10674 def maps(self) -> pathlib.Path:

Callers 1

do_invokeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected