-
-
Notifications
You must be signed in to change notification settings - Fork 739
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
Conversation
🤖 Coverage Update
To this point, this PR:
|
Hi @josx First thanks for your PR but to be honest I'm not big on merging this: it doesn't fix the problem, just moves it as a last case hoping the first 2 conditions will be met. Like I mentioned in the thread, the correct approach is to entirely remove the obsolete function Considering we only support ELF in GEF, having a valid |
Sorry but i dont get very well, what do you want to do? |
The function Over time, other methods were added to determine the architecture to use. Currently the most reliable is through the parsing of the ELF file itself. So Lines 3682 to 3695 in 5927df4
So what I'm suggesting is to re-work the logic so we don't need There are currently (AFAIK) 2 ways to determine the architecture from the Python API, and both require the ELF to be loaded.
So the only thing is in It is a bit more work but worth it, as we'll be also improving the perf ( Hope this clarifies my point. |
Ok this clarify me a little more, something like this would work for you (BTW i get rid of get_arch): def reset_architecture(arch: Optional[str] = None) -> None:
"""Sets the current architecture.
If an architecture is explicitly specified by parameter, try to use that one. If this fails, an `OSError`
exception will occur.
If no architecture is specified, then GEF will attempt to determine automatically based on the current
ELF target. If this fails, an `OSError` exception will occur.
"""
global gef
arches = __registered_architectures__
# check if the architecture is forced by parameter
if arch:
try:
gef.arch = arches[arch]()
except KeyError:
raise OSError(f"Specified arch {arch.upper()} is not supported")
return
# check for bin running
if is_alive():
try:
arch = gdb.selected_frame().architecture()
gef.arch = arches[arch.name()]()
except KeyError:
raise OSError(f"Running Binary arch {arch.name().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
# Unknown, we throw an exception to be safe
raise RuntimeError(f"Unknown architecture: {arch_str}")
|
Yes, this is much closer to what I had in mind. |
Let me update de PR |
c49ea4f
to
53d0aa5
Compare
🤖 Coverage Update
To this point, this PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems all good, just minor changes
By the way @josx do you confirm this PR solves your problem? |
53d0aa5
to
7042208
Compare
🤖 Coverage Update
To this point, this PR:
|
Yes, solves my problem. |
Updated with your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supports_gdb_arch
was removed, it should not be as it is an important part of the logic to let users enforce their own gdb arch with gef. It should be restored
…elf header Signed-off-by: José Luis Di Biase <josx@interorganic.com.ar>
7042208
to
c34bda9
Compare
🤖 Coverage Update
To this point, this PR:
|
Sorry for the delay I was on long holiday. I'll review this PR asap |
No problem. Every one deserves a long vacation :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Quick local tests went ok so merging. |
Description
Reorder how on reset_architecture fn is going to find arch. Now:
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.
Checklist