From c49ea4fa65773fbfcb5e0433721517a28e12db18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Di=20Biase?= Date: Sat, 2 Sep 2023 10:39:21 -0300 Subject: [PATCH] Reorder reset_arch: param forced, elf header, gdb conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Luis Di Biase --- gef.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gef.py b/gef.py index 660c77f9f..48ac9d374 100644 --- a/gef.py +++ b/gef.py @@ -3677,6 +3677,15 @@ def reset_architecture(arch: Optional[str] = None) -> None: raise OSError(f"Specified arch {arch.upper()} is not supported") return + # check for elf header architecture + if gef.binary.e_machine: + try: + gef.arch = arches[gef.binary.e_machine]() + except KeyError: + raise OSError(f"CPU type is currently not supported: {gef.binary.e_machine}") + return + + # last resort, use gdb default architecture gdb_arch = get_arch() preciser_arch = next((a for a in arches.values() if a.supports_gdb_arch(gdb_arch)), None) @@ -3684,14 +3693,6 @@ def reset_architecture(arch: Optional[str] = None) -> None: gef.arch = preciser_arch() return - # last resort, use the info from elf header to find it from the known architectures - try: - arch_name = gef.binary.e_machine if gef.binary else gdb_arch - gef.arch = arches[arch_name]() - except KeyError: - raise OSError(f"CPU type is currently not supported: {get_arch()}") - return - @lru_cache() def cached_lookup_type(_type: str) -> Optional[gdb.Type]: