Skip to content

Commit

Permalink
Reorder reset_arch: parameter forced, elf header, gdb conf (#1004)
Browse files Browse the repository at this point in the history
Reorder how on reset_architecture fn is going to find arch. Now:
- Param forced
- Elf header
- gdb conf

It is based on chat on #947 with @Grazfather 

This change is needed because if first check for gdb conf if some has
another language active would raise an exception making gef not work at
all (some code match only english sentences).

This pattch would help non englihs users of gdb to not have many
problems to use gef.

Signed-off-by: José Luis Di Biase <josx@interorganic.com.ar>
  • Loading branch information
josx committed Nov 29, 2023
1 parent 0f6255e commit 295cbf7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions gef.py
Expand Up @@ -2150,7 +2150,7 @@ def checksec(filename: str) -> Dict[str, bool]:
return Elf(filename).checksec


@lru_cache()
@deprecated("Use `gef.arch` instead")
def get_arch() -> str:
"""Return the binary's architecture."""
if is_alive():
Expand Down Expand Up @@ -3679,20 +3679,22 @@ def reset_architecture(arch: Optional[str] = None) -> None:
raise OSError(f"Specified arch {arch.upper()} is not supported")
return

gdb_arch = get_arch()

preciser_arch = next((a for a in arches.values() if a.supports_gdb_arch(gdb_arch)), None)
if preciser_arch:
gef.arch = preciser_arch()
return
# check for bin running
if is_alive():
arch = gdb.selected_frame().architecture()
gdb_arch = arch.name()
preciser_arch = next((a for a in arches.values() if a.supports_gdb_arch(gdb_arch)), None)
if preciser_arch:
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
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


@lru_cache()
Expand Down

0 comments on commit 295cbf7

Please sign in to comment.