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

Output type forces input type in decompiler #7353

Open
mumbel opened this issue Jan 4, 2025 · 3 comments
Open

Output type forces input type in decompiler #7353

mumbel opened this issue Jan 4, 2025 · 3 comments
Assignees
Labels
Feature: Decompiler Status: Triage Information is being gathered

Comments

@mumbel
Copy link
Contributor

mumbel commented Jan 4, 2025

Describe the bug
When setting the output variable type, in some cases the decompiler changes the input type to match.

I've noticed this lately (at least 11.0.2) on SPARC and PPC. Not sure under what circumstances it happens, but seems often enough with functions like a typed malloc taking a size or "get pointer by index" like functions. Does not seem to matter how complex the function is, I've seen it in 10 line helper functions with barely any stack usage and 500 line functions with massive stack size

uVar = 3;
....
pVar = FUN_AABBCCDD(uVar); // thing * FUN_AABBCCDD(uint index);

would turn into

pVar = (thing *)0x00000003;
...
pVar = FUN_AABBCCDD((uint)pVar); // thing * FUN_AABBCCDD(uint index);

it's not automatic but once you type pVar (ctrl+l / enter) or commit it, then the decompiler removes the uVar.

Environment (please complete the following information):
Ghidra Version: 11.2.1
Ghidra Release: PUBLIC
Ghidra Build Date: 2024-Nov-05 1643 EST
Ghidra Revision: a34349b
Ghidra Development Mode: false
OS Name: Linux
OS Arch: amd64
OS Version: 6.8.0-51-generic
OS Pretty Name: Ubuntu 24.04.1 LTS
Java Vendor: Ubuntu
Java Version: 21.0.5

Additional context
Add any other context about the problem here.

@DualTachyon
Copy link

You can right click one of the instances of pVar and select "Split out as new variable" with a new variable name. You can then retype that to match whatever type, and it should fix it for you.

I would recommend you undo the changes to have the first pVar to be an integer first, because once Ghidra devices to do things like "(bla *)someLiteral" it has a hard time to shake it off. Not always, but it happens enough.

@mumbel
Copy link
Contributor Author

mumbel commented Jan 5, 2025

I don't have that as an option it looks like. right clicking either declaration, arg assignment, arg use, or return value; doesn't matter

@astrelsky
Copy link
Contributor

I don't have that as an option it looks like. right clicking either declaration, arg assignment, arg use, or return value; doesn't matter

It's never available when you need to split a variable.

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

5 participants