| 9400 | return |
| 9401 | |
| 9402 | def load_extra_plugins(self) -> int: |
| 9403 | def load_plugin(fpath: pathlib.Path) -> bool: |
| 9404 | try: |
| 9405 | dbg(f"Loading '{fpath}'") |
| 9406 | gdb.execute(f"source {fpath}") |
| 9407 | except Exception as e: |
| 9408 | warn(f"Exception while loading {fpath}: {str(e)}") |
| 9409 | return False |
| 9410 | return True |
| 9411 | |
| 9412 | nb_added = -1 |
| 9413 | start_time = time.perf_counter() |
| 9414 | try: |
| 9415 | nb_inital = len(__registered_commands__) |
| 9416 | directories: List[str] = gef.config["gef.extra_plugins_dir"].split(";") or [] |
| 9417 | for d in directories: |
| 9418 | d = d.strip() |
| 9419 | if not d: continue |
| 9420 | directory = pathlib.Path(d).expanduser() |
| 9421 | if not directory.is_dir(): continue |
| 9422 | sys.path.append(str(directory.absolute())) |
| 9423 | for entry in directory.iterdir(): |
| 9424 | if entry.is_dir(): |
| 9425 | if entry.name in ('gdb', 'gef', '__pycache__'): continue |
| 9426 | load_plugin(entry / "__init__.py") |
| 9427 | else: |
| 9428 | if entry.suffix != ".py": continue |
| 9429 | if entry.name == "__init__.py": continue |
| 9430 | load_plugin(entry) |
| 9431 | |
| 9432 | nb_added = len(__registered_commands__) - nb_inital |
| 9433 | if nb_added > 0: |
| 9434 | self.load() |
| 9435 | nb_failed = len(__registered_commands__) - len(self.commands) |
| 9436 | end_time = time.perf_counter() |
| 9437 | load_time = end_time - start_time |
| 9438 | ok(f"{Color.colorify(str(nb_added), 'bold green')} extra commands added from " |
| 9439 | f"'{Color.colorify(', '.join(directories), 'bold blue')}' in {load_time:.2f} seconds") |
| 9440 | if nb_failed != 0: |
| 9441 | warn(f"{Color.colorify(str(nb_failed), 'bold light_gray')} extra commands/functions failed to be added. " |
| 9442 | "Check `gef missing` to know why") |
| 9443 | |
| 9444 | except gdb.error as e: |
| 9445 | err(f"failed: {e}") |
| 9446 | return nb_added |
| 9447 | |
| 9448 | @property |
| 9449 | def loaded_command_names(self) -> Iterable[str]: |