diff --git a/gef.py b/gef.py index 3b3fc3961..c18046ccd 100644 --- a/gef.py +++ b/gef.py @@ -83,7 +83,7 @@ from io import StringIO, TextIOWrapper from types import ModuleType from typing import (Any, ByteString, Callable, Dict, Generator, IO, Iterable, Iterator, List, - NoReturn, Optional, Sequence, Tuple, Type, Union) + NoReturn, Optional, Sequence, Set, Tuple, Type, Union) from urllib.request import urlopen @@ -161,7 +161,7 @@ def update_gef(argv: List[str]) -> int: __registered_commands__ : List[Type["GenericCommand"]] = [] __registered_functions__ : List[Type["GenericFunction"]] = [] __registered_architectures__ : Dict[Union["Elf.Abi", str], Type["Architecture"]] = {} -__registered_file_formats__ : List[ Type["FileFormat"] ] = [] +__registered_file_formats__ : Set[ Type["FileFormat"] ] = set() def reset_all_caches() -> None: @@ -687,11 +687,16 @@ def __int__(self) -> int: return self.value +class FileFormatSection: + misc: Any + + class FileFormat: name: str path: pathlib.Path entry_point: int checksec: Dict[str, bool] + sections: List[FileFormatSection] def __init__(self, path: Union[str, pathlib.Path]) -> None: raise NotImplemented @@ -703,13 +708,16 @@ def __init_subclass__(cls: Type["FileFormat"], **kwargs): for attr in required_attributes: if not hasattr(cls, attr): raise NotImplementedError(f"File format '{cls.__name__}' is invalid: missing attribute '{attr}'") - __registered_file_formats__.append(cls) + __registered_file_formats__.add(cls) return @classmethod def is_valid(cls, path: pathlib.Path) -> bool: raise NotImplemented + def __str__(self) -> str: + return f"{self.name}('{self.path.absolute()}', entry @ {self.entry_point:#x})" + class Elf(FileFormat): """Basic ELF parsing. @@ -10805,9 +10813,6 @@ def reset_caches(self) -> None: [PYTHONBIN, "-c", "import os, sys;print(os.linesep.join(sys.path).strip())"]).decode("utf-8").split() sys.path.extend(SITE_PACKAGES_DIRS) - # setup prompt - gdb.prompt_hook = __gef_prompt__ - # setup config gdb_initial_settings = ( "set confirm off", @@ -10832,6 +10837,9 @@ def reset_caches(self) -> None: gef.gdb.load() gef.gdb.show_banner() + # setup prompt + gdb.prompt_hook = __gef_prompt__ + # gdb events configuration gef_on_continue_hook(continue_handler) gef_on_stop_hook(hook_stop_handler)