From 814e198eb117a793123e24d2c1dc51ab4c60231d Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Wed, 31 Jan 2024 00:17:53 +0100 Subject: [PATCH] Fix https://github.com/hugsy/gef/pull/1045#discussion_r1451640332 Even if we don't raise an exception (still discussing about it) we need to manage properly the cases were the binary was not setup. --- gef.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gef.py b/gef.py index 109e929be..15a1568a7 100644 --- a/gef.py +++ b/gef.py @@ -3335,7 +3335,7 @@ class MIPS64(MIPS): @staticmethod def supports_gdb_arch(gdb_arch: str) -> Optional[bool]: - return gdb_arch.startswith("mips") and gef.binary.e_class == Elf.Class.ELF_64_BITS + return gdb_arch.startswith("mips") and gef.binary and gef.binary.e_class == Elf.Class.ELF_64_BITS def copy_to_clipboard(data: bytes) -> None: @@ -3722,7 +3722,7 @@ def reset_architecture(arch: Optional[str] = None) -> None: return # last resort, use the info from elf header to find it from the known architectures - if gef.binary.e_machine: + if gef.binary and gef.binary.e_machine: try: gef.arch = arches[gef.binary.e_machine]() except KeyError: @@ -7222,7 +7222,7 @@ def do_invoke(self, argv: List[str]) -> None: return if not os.access(fpath, os.X_OK): - warn(f"The file '{fpath}' is not executable.") + warn(f"The file '{fpath}' does not exists or is not executable.") return if is_alive() and not gef.session.qemu_mode: @@ -11114,9 +11114,10 @@ def setup(self) -> bool: # refresh gef to consider the binary reset_all_caches() - if self.file.exists(): + if self.lfile.exists(): gef.binary = Elf(self.lfile) + reset_architecture() return success