diff --git a/docs/commands/arch.md b/docs/commands/arch.md index fb6ff7212..9dd638e12 100644 --- a/docs/commands/arch.md +++ b/docs/commands/arch.md @@ -9,4 +9,3 @@ There are 3 available sub-commands: gef do magic to detect the architecture by not providing arguments. ![arch](https://imgur.com/a/6JUoOmS) - diff --git a/gef.py b/gef.py index 6854a6da8..181f98c63 100644 --- a/gef.py +++ b/gef.py @@ -4768,29 +4768,55 @@ def __set_repeat_count(self, argv: List[str], from_tty: bool) -> None: @register -class ArchCommand(GenericCommand): +class PieCommand(GenericCommand): """Manage the current loaded architecture""" _cmdline_ = "arch" _syntax_ = f"{_cmdline_} (list|get|set) ..." _example_ = f"{_cmdline_}" + def __init__(self) -> None: + super().__init__(prefix=True) + return + + def do_invoke(self, argv: List[str]) -> None: + if not argv: + self.usage() + return + +@register +class ArchGetCommand(GenericCommand): + """Get the current loaded architecture""" + + _cmdline_ = "arch get" + _syntax_ = f"{_cmdline_}" + _example_ = f"{_cmdline_}" + def do_invoke(self, args: List[str]) -> None: - if len(args) == 0 or args[0] == 'get': - self._get_cmd() - elif args[0] == 'set': - self._set_cmd(*args[1:]) - elif args[0] == 'list': - self._list_cmd() + gef_print(f"{Color.greenify('Arch')}: {gef.arch}") + gef_print(f"{Color.greenify('Reason')}: {gef.arch_reason}") - def _get_cmd(self) -> None: - gef_print(f"{Color.greenify("Arch")}: {gef.arch}") - gef_print(f"{Color.greenify("Reason")}: {gef.arch_reason}") - def _set_cmd(self, arch = None, *args) -> None: - reset_architecture(arch) +@register +class ArchSetCommand(GenericCommand): + """Set the current loaded architecture""" + + _cmdline_ = "arch set" + _syntax_ = f"{_cmdline_} " + _example_ = f"{_cmdline_}" + + def do_invoke(self, args: List[str]) -> None: + reset_architecture(args[0] if args else None) - def _list_cmd(self) -> None: +@register +class ArchListCommand(GenericCommand): + """List the available architectures""" + + _cmdline_ = "arch list" + _syntax_ = f"{_cmdline_}" + _example_ = f"{_cmdline_}" + + def do_invoke(self, args: List[str]) -> None: gef_print(Color.greenify("Available architectures:")) for arch in __registered_architectures__.keys(): if type(arch) == str: