Skip to content

Commit

Permalink
🐛 fixes
Browse files Browse the repository at this point in the history
- moved prompt init after gef initial loading
- added a `__str__` for `FileFormat`
- `FileFormat` also requires a section member
  • Loading branch information
hugsy committed Jun 24, 2022
1 parent 0100c7b commit 5dd793d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions gef.py
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down

0 comments on commit 5dd793d

Please sign in to comment.