Skip to content

Commit

Permalink
Add support for virtualenv
Browse files Browse the repository at this point in the history
Add a `gef.virtualenv_path` config var, and activate it at startup.
  • Loading branch information
ValekoZ committed Jun 5, 2024
1 parent 1b6f46a commit 65330a7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -9854,6 +9854,9 @@ def __init__(self) -> None:
plugins_dir = GefSetting("", str, "Autoload additional GEF commands from external directory", hooks={"on_write": [GefSetting.no_spaces, ]})
plugins_dir.add_hook("on_changed", [lambda _, new_val: GefSetting.must_exist(new_val), lambda _, new_val: self.load_extra_plugins(new_val), ])
gef.config["gef.extra_plugins_dir"] = plugins_dir
venv_path = GefSetting("", str, "Path to the virtualenv used by GEF", hooks={"on_write": [GefSetting.no_spaces, ]})
venv_path.add_hook("on_changed", [lambda _, new_val: GefSetting.must_exist(new_val), lambda _, new_val: self.load_virtualenv(new_val), ])
gef.config["gef.virtualenv_path"] = venv_path
gef.config["gef.disable_color"] = GefSetting(False, bool, "Disable all colors in GEF")
gef.config["gef.tempdir"] = GefSetting(GEF_TEMP_DIR, pathlib.Path, "Directory to use for temporary/cache content", hooks={"on_write": [GefSetting.no_spaces, GefSetting.create_folder_tree]})
gef.config["gef.show_deprecation_warnings"] = GefSetting(True, bool, "Toggle the display of the `deprecated` warnings")
Expand Down Expand Up @@ -9943,6 +9946,13 @@ def load_plugins_from_directory(plugin_directory: pathlib.Path):
dbg(f"Loading extra plugins from directory={directory}")
return load_plugins_from_directory(directory)


def load_virtualenv(self, new_path: Optional[pathlib.Path] = None):
path = new_path or pathlib.Path(gef.config["gef.virtualenv_path"])
activate_script_path = path / "bin" / "activate_this.py"
if path:
exec(open(activate_script_path).read(), {'__file__': activate_script_path})

@property
def loaded_command_names(self) -> Iterable[str]:
print("obsolete loaded_command_names")
Expand Down Expand Up @@ -11717,6 +11727,9 @@ def target_remote_posthook():
gef.gdb.load()
gef.gdb.show_banner()

# load venv
gef.gdb.load_virtualenv()

# load config
gef.gdb.load_extra_plugins()

Expand Down

0 comments on commit 65330a7

Please sign in to comment.