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

Decompiler recognizes local variable initialization prematurely #7339

Open
swine-flu opened this issue Jan 2, 2025 · 0 comments
Open

Decompiler recognizes local variable initialization prematurely #7339

swine-flu opened this issue Jan 2, 2025 · 0 comments
Assignees
Labels
Feature: Decompiler Status: Triage Information is being gathered

Comments

@swine-flu
Copy link

Describe the bug
Calling another function before the stack frame is being properly established for the current one causes Ghidra decompiler to identify this action as a local variable initialization. As a result, the very first variable on the stack is getting initialized with some garbage data (e.g. byte buffer init) or getting outright ignored (e.g. integer variable init) by the decompiler.

To Reproduce
Having a function with the stack frame init which looks like the following:

PUSH  BP
MOV   BP,SP
MOV   AX,imm16
CALLF __SomeRtlProc
SUB   SP,imm16

Expected behavior
Decompiler should not mess with the stack variables in cases like that, at the very least there should be an option to ignore the call to __SomeRtlProc as if this call never happened. I'm aware about the fixups but I wasn't able to make any use out of this feature, see below.

Screenshots
On the following screenshot decompiler creates a new variable (cVar1) instead of using the existing one (local_3):
Case_1
Next screenshot showcases filling the end of the buffer with some nonsensical unrelated to decompilation data:
Case_2

Environment (please complete the following information):

  • OS: Windows 10
  • Java Version: 21.05
  • Ghidra Version: 11.3
  • Ghidra Origin: locally built

Additional context
Here is the fixup code which I was using for the __StackCheck procedure:

<callfixup name="__StackCheck">
  <target name="__StackCheck"/>
  <pcode>
   <body><![CDATA[
	  temp:1 = 0;
   ]]></body>
  </pcode>
</callfixup>

I'm assuming that assigning an unused temp p-code variable to zero is considered a NOP. I also tried a few other variations which could've been considered as a no operation to the decompiler but to no avail.

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