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
Decompiler shows array indexing as index_var[0x1000] instead of DATA_0x1000[index_var] (because of incorrect dataflow inference) #6460
Comments
It seems Ghidra needs a little help (as is often the case). Try changing the type of |
I care specifically about the results the Ghidra decompiler generates by default without human intervention. Changing the type of |
Well, what made ghidra think that pcVar2 was a char *? That was the thing that really got it down the wrong track. When it's trying to figure out *(A+B), if it thinks that A is a pointer and B is a number that might be a pointer, then it seems to be the right choice to consider B to be a number, since adding two pointers doesn't make sense.. I'm forever annoyed by ghidra going the other way, when it produces something like fcn((int)&DATA_400010) when it should be fcn(0x400010), but because it is within the address range, ghidra really wants to make it into a pointer. Decompiling is inherently ambiguous, and ghidra isn't really a project to produce a decompiler to produce perfect code, but rather a tool that can be used to understand what a binary program is doing. To the extent that the decompiler usually produces readable enough code so that I can better understand the binary, and especially if I can work with the decompiler to help that along, then I personally consider ghidra a tremendous success. |
Describe the bug
Decompiler produces C Pseudo Code and P-Code with flipped interpretation of the
*(pointer+offset)
pattern in some cases0x20002600
is a location inside the memory space and has the labelreq_string
which is correctly recognized in the same code snippet in other lines.To Reproduce
Steps to reproduce the behavior:
http_recv
methodExpected behavior
Ideally Ghidra should correctly decompile this as
req_string[pcVar2]
instead ofpcVar2[0x20002600]
Attachments
samr21_http.elf.zip
Environment (please complete the following information):
Additional context
This only happens if the RO optimizations are enabled, disabling them flips the order to the correct one (with two variables, instead of variable and
0x20002600
)Architecture for that specific function is ARM THUMB
The text was updated successfully, but these errors were encountered: