question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Offsetted pointers don't seem to apply to left-hand side of assignment sometimes

See original GitHub issue

Describe 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.

image

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.

image

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanDSMcommented, Jun 19, 2022

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:

image

FAIL4 has multiple similar looking failures (only one is demonstrated on the following screenshot) for different structures:

image

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.

0reactions
caheckmancommented, Jul 1, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4. Pointers and Arrays - Understanding and Using C ... - O'Reilly
The pointer pv is an lvalue . An lvalue denotes the term used on the lefthand side of an assignment operator. An lvalue...
Read more >
Why can't *pointer+offset be used as an l-value? ("error
When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on ......
Read more >
CS 160 Lecture Notes – Fall '20 - UCSB Computer Science
The main reason for this restriction is that the assignments usually depend on the solution of the previous assignment, and we want to...
Read more >
Reference and Value Semantics, C++ FAQ - Standard C++
Value (or “copy”) semantics mean assignment copies the value, not just the pointer. C++ gives you the choice: use the assignment operator to...
Read more >
English 12 HW & Assignments Page - Ms. Carota
For the most part, we will use Schoology, but I may sometimes ask you to navigate to this class ... The assignment details...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found