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
gef fails to provide right context for aarch64 binary #458
Comments
Can you provide a small binary we can use to repro your issue? |
Sure, here you go. This is from a Samsung S7 phone. Most binaries I have pulled from this phone seem to be like this. I'm using gdb-multiarch BTW. |
I don't currently have a debug env for this, but GEF for me does correctly identify the arch gef➤ pi current_arch
<__main__.AARCH64 object at 0x7f58211569b0> Can you run |
@Grazfather Not for me apparently... This happens on gdb-multiarch 8.2.1 from Debian, and gdb-aarch64 8.2.1 that I built myself from buildroot. Maybe something to do with the fact that I'm using a gdb for aarch64 on a x86 platform? |
What if you try to force it ? gef➤ pi set_arch("ARM64") |
it accepts it: but still doesn't set the registers right: Both with gdb-multiarch and gdb-aarch64 |
Just like @Grazfather I really cannot reproduce your issue, gef correctly identifies the binary, see below (using stadnard
Your issue definitely comes from the fact that Can you try the following:
|
That seems to work! What do you think is going wrong? And how can I automate it? |
That's pretty weird but cool 👍 To automate, simply add those 3 lines after |
But won't that force aarch64 for all binaries that I load? What if I am loading a x86 or a MIPS binary? |
It will, my point was to have this in your .gdbinit.
Then type in |
Ok will do, thanks! But aren't you curious to get to the bottom of this? Any idea where I can investigate? |
Also, it doesn't seem a real fix - if I'm debugging remotely, disconnect to the target, and connect again, it will think the binary is x86 again... |
I am but if I (or any other gef devs) cannot reproduce it (it all works fine on my ARCH64 VM), I can't really do much. |
If you keep digging into this and come up with a proper solution and/or a good reproduction setup, then we can go further. |
I think this might be the problem - have you tried running gdb-multiarch or a cross compiled gdb for aarch64 in an x86-64 computer? Because that's my setup, and that's where it probably gets confused!
I'm happy to do it, just looking for some tips or places to dig! |
I am always using gdb-multiarch, and it was recognizing the architecture immediately. |
@hugsy sure, but did you use it on a x86 machine? Maybe I misunderstood, but I'm asking because you said this:
My use case is - I'm debugging a aarch64 phone, and doing it remotely on my x86 machine, running Debian x86, with gdb-multiarch. |
Yes. |
Ok, understood. I will try to dig further and see what is wrong with my setup... any ideas where I can look? |
First I would try to reproduce hugsy's setup... probably using qemu. @hugsy do you have a link to your qemus? Then with your phone and qemu you can compare what's different -- GDB's idea of the arch, GEF's, etc. |
I also encountered this issue, I built GDB 8.3 from google android source code using the following command. This gdb is built with LZMA support, it could try to read symbols from .gnu_debugdata. Reading symbols from target:/system/bin/app_process64... In the regular gdb from homebrew on macOS, it isn't built with LZMA. When you debug the app, it won't show up "Reading symbols from .gnu_debugdata for target:/system/bin/app_process64...". I added some debug code in GEF, last line is the output from debug code I added. I found in the function get_filepath(), the return value of gdb.current_progspace().filename is ".gnu_debugdata for target:/system/bin/app_process64" when the function get_filepath is invoked at first time. It will be "target:/system/bin/app_process64" when the function get_filepath is invoked at second time. def get_filepath(): Then in the function get_elf_headers(), it will pass the string ".gnu_debugdata for target:/system/bin/app_process64" to ELF(). @lru_cache()
Finally it could cause an error like "...not found/readable ...". In ELF, the default arch is X86. So it caused to display context info incorrectly. We need to add some code to handle this case in the function get_filepath() or get_elf_headers(). Additionally, I'm not sure if it's a bug in gdb.current_progspace().filename, it returns ".gnu_debugdata for target:/system/bin/app_process64". |
I patched the function get_filepath() like the following. def get_filepath():
Please review it. @hugsy |
Hi @k3vinlusec , Please send a proper Pull Request with a reference to this issue for it to be merged. Thanks, |
Hi, @hugsy I have sent a pull request for this case, please review it! Thanks! |
I'll take a look. Thanks for the PR |
Seems to have fixed it for me too, thanks! |
Your issue will be closed unless you confirm the following:
master
branch?Step 1: Describe your environment
GNU gdb (Debian 8.2.1-2) 8.2.1
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
Step 2: Describe your problem
When I load certain aarch64 binaries with gef, it complains about lack of .gnu_debugdata and then it says most features won't work. I would be OK with that if it actually displayed context correctly, but it doesn't. It then believes all code is x86, and proceeds to dereference x86 registers, which of course fails.
Steps to reproduce
Observed Results
I get the following warning when loading the binary
Which probably confuses gef, since it identifies the code as x86:32:
Expected results
As per the warning, I'm not expecting most of gef features to work (although to be honest, I haven't researched why), but I expect the context and registers to be displayed correctly.
The text was updated successfully, but these errors were encountered: