Offsetted pointers don't seem to apply to left-hand side of assignment sometimes
See original GitHub issueDescribe the bug In a situation where an offsetted pointer is being attributed to, the decompiler does not seem to be able to use the ADJ mnemonic to properly identify the structure field sometimes.
The following screenshot shows a real world example of this bug.
To Reproduce It is unclear how to reproduce this bug. I tried writing a sample C program to attempt to provide as an example but the decompiler managed to provide the expected result.
Expected behavior Given the following structure:
struct AStruct
{
int a;
int b;
}
and an offsetted pointer type X which points to member B of AStruct, an assignment of the number 2 to member a of an instance of AStruct pointed to by a pointer of type X should look like ADJ(ptrAStruct)->a = 2
. An example of a well-formed decompilation using AStruct is shown in the following screenshot.
Environment (please complete the following information):
- OS: Ubuntu 21.10
- Java Version: 17.0.3
- Ghidra Version: 10.2-DEV (0b66c98)
- Ghidra Origin: Locally built
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (3 by maintainers)
I’ve added more sample outputs to the gist. FAIL3 has a variable called unstablePtr that seems to get decompiled correctly in some cases but incorrectly in others:
FAIL4 has multiple similar looking failures (only one is demonstrated on the following screenshot) for different structures:
These were obtained from the same build as the original debug outputs, but if necessary I can check again with a new build based on the latest commit.
Thanks for the examples. I am reproducing. The problem occurs when the structure doesn’t have a defined field at the component offset of the pointer.
The “unstablePtr” example in FAIL3 will work fully if you redefine the pointer to be relative to KingsFieldMetaTile, instead of KingsFieldTile, and use an offset of 9.