Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder reset_arch: param forced, elf header, gdb conf #1004

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ def checksec(filename: str) -> Dict[str, bool]:
return Elf(filename).checksec


@lru_cache()
josx marked this conversation as resolved.
Show resolved Hide resolved
@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)
josx marked this conversation as resolved.
Show resolved Hide resolved
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
Loading