Skip to content
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

Relative pointer variable for struct shows misleading increments/offsets in decompilation #7880

Open
KKhanhH opened this issue Mar 5, 2025 · 0 comments
Assignees
Labels
Feature: Decompiler Status: Triage Information is being gathered

Comments

@KKhanhH
Copy link

KKhanhH commented Mar 5, 2025

Describe the bug
The increments and offsets of relative pointers to structs is misleading. A variable of type Struct* when incremented by the sizeof Struct will show as incrementing by 1. An increment of a relative pointer of the same type will have its increment value be shown as (byte offset)/sizeof(pointed to struct member).

To Reproduce
Steps to reproduce the behavior:
Have a struct with some members defined.
Create a relative pointer for a struct by right-clicking on a variable and clicking "Adjust pointer offset", set DataType and offset accordingly.
Increments and offsets do not match that of DataType*.

Expected behavior
A clear and concise description of what you expected to happen.
The relative pointer should be treated the same as a pointer to the datatype, matching increments and offsets.
If the byte increment is not a valid multiple of the data type, then the pointer should have a cast done.

struct Struct {
  float a;
  float b;
};

Struct x;
Struct* ptr = &x->b;
ptr += 1; 

Struct_ptr_8_float relPtr = &x->b;
// ptr = (Struct_ptr_8_float)((int)relPtr + sizeof(Struct));
ptr += 2; //Current incorrect behavior, struct size is 8, float size is 4, so increments by 2

Struct_ptr_8_float relPtr2 = &x->b;
// ptr = (Struct_ptr_8_float)((int)relPtr + sizeof(Struct));
ptr += 1; //Correct behavior

Screenshots
If applicable, add screenshots to help explain your problem.

Attachments
If applicable, please attach any files that caused problems or log files generated by the software.

Environment (please complete the following information):

  • OS: Windows 11
  • Java Version: 21
  • Ghidra Version: 11.3.1
  • Ghidra Origin: GitHub Release

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Decompiler Status: Triage Information is being gathered
Projects
None yet
Development

No branches or pull requests

3 participants