-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ELF Parser locating imports incorrectly (PPC) #9825
Comments
Still actual with master. Found out, that problem is compilation specific. Because binary from another toolchain is disassembled well |
Fixed in #10526 |
i added a test too |
@radare Shall it be closed then? |
Not it's not merged |
Reopening this issue because while testing the provided binary (hello.ppc) I still get the wrong output.
|
@radare Moreover, the fix 5080179 does not seem to really fix the mosquito binary either.
I noticed this because I'm refactoring the |
Discover what
… On 4 Jan 2019, at 17:45, Riccardo Schirone ***@***.***> wrote:
@radare Moreover, the fix 5080179 does not seem to really fix the mosquito binary either.
ii on that binary gives some results that may seem, at a first look, correct, but if you look at the imp.XXXX entries they are all in the wrong place (e.g. imp.unlink falls where there is the .init_array).
I noticed this because I'm refactoring the get_import_addr function in elf.c and I was surprised to find that ppc64 was the only one to require the rel_sec section to compute the import address. Where did you discover that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
That you need to use |
I'm no PPC expert, but something like the following improves a bit the situation, though it is not perfect. From 9902b2082d55ffb1e39853adf2e127d8b89c5da8 Mon Sep 17 00:00:00 2001
From: Riccardo Schirone <sirmy15@gmail.com>
Date: Wed, 22 Apr 2020 16:04:15 +0200
Subject: [PATCH] Add PPC relocs
---
libr/bin/p/bin_elf.inc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libr/bin/p/bin_elf.inc b/libr/bin/p/bin_elf.inc
index 61d1570a6..b7595cca6 100644
--- a/libr/bin/p/bin_elf.inc
+++ b/libr/bin/p/bin_elf.inc
@@ -648,6 +648,15 @@ static RBinReloc *reloc_convert(struct Elf_(r_bin_elf_obj_t) *bin, RBinElfReloc
////eprintf("TODO(eddyb): uninmplemented ELF/ARM reloc type %i\n", rel->type);
}
break;
+ case EM_PPC: switch (rel->type) {
+ case R_PPC_NONE: break;
+ case R_PPC_GLOB_DAT: ADD (32, 0);
+ case R_PPC_JMP_SLOT: ADD (32, 0);
+ default:
+ eprintf ("unimplemented ELF/PPC reloc type %d\n", rel->type);
+ break;
+ }
+ break;
default: break;
}
--
2.25.3
In particular, the following solution identifies the relocations, but there are dupped ones (I think because they are both in RELA and REL sections). Also, I can't find any PLT section, but as I said I'm no PPC expert. Maybe this can be useful as a starting point for someone else interested. |
@ret2libc Indeed there is some duplication, the main problem is that the duplication come from the relocation table. This is not a bug. The binary seems to be invalid but functional. I don't know which entry we need to keep, the last one, first one, ect... |
Yeah I think we can live with the duplication, however I am not 100% confident of the patch I wrote above as I'm no PPC expert. We may include it nonetheless, as it improves a bit the situation, but it would be better to have someone familiar with PPC looking at this. |
We can ask on telegram? |
I think we can push this patch, if someone isn't happy he will create an issue. |
I agree. Are you willing to do it? Otherwise I can do it. |
I can do this. |
Done, i had one regression test |
Work environment
Arch Linux x86-64
PPC-32 ELF
radare2 2.5.0-git 17805 @ linux-x86-64 git.2.4.0-282-g43af9e3bb
commit: 43af9e3 build: 2018-04-06__23:16:3
I've compiled a simple hello world binary with toolchain for ppc build via crosstools-ng , and tried to analyze it with R2.
Expected behavior
Imports of file (
printf
func) is actually located at0x1002****
addresses, and one can see it from objdumpD.txt file that I've added to zip archive. Sorabin2 -ii hello.ppc
oris
should show it in output, andaaa; pdf main
should show, that printf functions is called from there.(something like this)
Actual behavior
However,
ii
,is
commands show, thatprintf
function and other imports is located at invalid0x4743430a
addresses:and r2 cant realize, that address called from main subroutine is actually
printf
function, therefore there is no Xref to string being used here.Steps to reproduce the behavior
just run
rabin2 -is
to see that imports is too far.Additional Logs, screenshots, source-code, configuration dump, ...
hello-ppc.zip
There is source file, binary file, and
objdump -D
output fileOne more thing
I'll be happy if someone will give me any hints to track down and fix this issue, so please respond even if you're not working on this arch etc.
The text was updated successfully, but these errors were encountered: