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

Class GefInstallExtraScriptCommand

tools/gef.py:10051–10105  ·  view source on GitHub ↗

`gef install` command: installs one or more scripts from the `gef-extras` script repo. Note that the command doesn't check for external dependencies the script(s) might require.

Source from the content-addressed store, hash-verified

10049
10050
10051class GefInstallExtraScriptCommand(gdb.Command):
10052 """`gef install` command: installs one or more scripts from the `gef-extras` script repo. Note that the command
10053 doesn't check for external dependencies the script(s) might require."""
10054 _cmdline_ = "gef install"
10055 _syntax_ = f"{_cmdline_} SCRIPTNAME [SCRIPTNAME [SCRIPTNAME...]]"
10056
10057 def __init__(self) -> None:
10058 super().__init__(self._cmdline_, gdb.COMMAND_SUPPORT, gdb.COMPLETE_NONE, False)
10059 self.branch = gef.config.get("gef.extras_default_branch", GEF_EXTRAS_DEFAULT_BRANCH)
10060 return
10061
10062 def invoke(self, argv: str, from_tty: bool) -> None:
10063 self.dont_repeat()
10064 if not argv:
10065 err("No script name provided")
10066 return
10067
10068 args = argv.split()
10069
10070 if "--list" in args or "-l" in args:
10071 subprocess.run(["xdg-open", f"https://github.com/hugsy/gef-extras/{self.branch}/"])
10072 return
10073
10074 self.dirpath = pathlib.Path(gef.config["gef.tempdir"]).expanduser().absolute()
10075 if not self.dirpath.is_dir():
10076 err("'gef.tempdir' is not a valid directory")
10077 return
10078
10079 for script in args:
10080 script = script.lower()
10081 if not self.__install_extras_script(script):
10082 warn(f"Failed to install '{script}', skipping...")
10083 return
10084
10085
10086 def __install_extras_script(self, script: str) -> bool:
10087 fpath = self.dirpath / f"{script}.py"
10088 if not fpath.exists():
10089 url = f"https://raw.githubusercontent.com/hugsy/gef-extras/{self.branch}/scripts/{script}.py"
10090 info(f"Searching for '{script}.py' in `gef-extras@{self.branch}`...")
10091 data = http_get(url)
10092 if not data:
10093 warn("Not found")
10094 return False
10095
10096 with fpath.open("wb") as fd:
10097 fd.write(data)
10098 fd.flush()
10099
10100 old_command_set = set(gef.gdb.commands)
10101 gdb.execute(f"source {fpath}")
10102 new_command_set = set(gef.gdb.commands)
10103 new_commands = [f"`{c[0]}`" for c in (new_command_set - old_command_set)]
10104 ok(f"Installed file '{fpath}', new command(s) available: {', '.join(new_commands)}")
10105 return True
10106
10107
10108#

Callers 1

setupMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected