Skip to content

Commit

Permalink
Fix double loading of external plugins (#816)
Browse files Browse the repository at this point in the history
`register_external_command` was receiving an instance of a class for each new external script. This lead to a double initialization when calling `gef.gdb.load(cls)`. Fixed by registering directly a class (just like `register_command`)
  • Loading branch information
hugsy authored Feb 4, 2022
1 parent d1fa00f commit 4365d9c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4554,9 +4554,8 @@ def pane_title(): return "example:pane"
# Commands
#

def register_external_command(obj: "GenericCommand") -> Type["GenericCommand"]:
def register_external_command(cls: Type["GenericCommand"]) -> Type["GenericCommand"]:
"""Registering function for new GEF (sub-)command to GDB."""
cls = obj.__class__
__registered_commands__.append(cls)
gef.gdb.load(initial=False)
gef.gdb.doc.add_command_to_doc((cls._cmdline_, cls, None))
Expand Down Expand Up @@ -10545,14 +10544,14 @@ def __load_extra_plugins(self) -> int:
directories = gef.config["gef.extra_plugins_dir"]
if directories:
for directory in directories.split(";"):
directory = os.path.realpath(os.path.expanduser(directory))
if os.path.isdir(directory):
sys.path.append(directory)
for fname in os.listdir(directory):
if not fname.endswith(".py"): continue
fpath = f"{directory}/{fname}"
if os.path.isfile(fpath):
gdb.execute(f"source {fpath}")
directory = pathlib.Path(directory).expanduser()
if not directory.is_dir():
continue
for entry in directory.iterdir():
if not entry.is_file(): continue
if entry.suffix != ".py": continue
if entry.name == "__init__.py": continue
gdb.execute(f"source {entry}")
nb_added = len(self.loaded_commands) - nb_inital
if nb_added > 0:
ok(f"{Color.colorify(nb_added, 'bold green')} extra commands added from "
Expand Down

0 comments on commit 4365d9c

Please sign in to comment.