ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

Variable rename doesn't work

Open croghostrider opened this issue 6 years ago • 7 comments

Describe the bug Hi, I have tried to change a variable name in a small binary, but it does not change the name from all equal variables. Its create a new variable declaration, see screen capture. Sorry for my bad English.

To Reproduce Steps to reproduce the behavior: screencapture

Expected behavior Change all equal variable names

Attachments main.zip

Environment (please complete the following information):

  • OS: Kali 2019.1a (VMware Workstetion Pro on Windows N 10 Pro 64bit)
  • Java Version: 11.0.3
  • Ghidra Version: 9.0

croghostrider avatar Mar 14 '19 12:03 croghostrider

The renaming of a variable in the decompiler can be problematic at times. If you introduce a variable that the decompiler has at the beginning of it's analysis versus a variable it creates as part of data flow analysis, you can end up with differing variables. The variable merging algorithm can be affected by the initial information of the variable rename.

In your case, I believe the decompiler is correct but not an optimal re-use of the variable. The variable assigned from the ror8 could be considered as another variable in Static Single Assignment.

What happens if you rename uvar2 to be ror8Value?

emteere avatar Mar 19 '19 12:03 emteere

it comes error message "Duplicate name"

croghostrider avatar Mar 19 '19 14:03 croghostrider

Duplicate name was not expected.

Can you post the debug Decompiler .xml file?

emteere avatar Apr 12 '19 01:04 emteere

Yes, where can I find the file?

croghostrider avatar Apr 14 '19 16:04 croghostrider

any news about this issue? I have similair bug: when renaming local var, I don't see it has been renamed. But I get the "duplicate error" when trying to rename again

alexbrooy avatar Nov 16 '20 12:11 alexbrooy

Seems like this bug is still alive in 10.1.2

acama avatar Mar 17 '22 00:03 acama

Same for 10.1.4

antiaim avatar Sep 25 '22 15:09 antiaim

I believe one can find the said decompiler XML when clicking this button

Screenshot_20221214_151136

Here's decompiler xml (zipped for github) of a function I encountered the bug in

image

Any attempt to rename or retype puVar1 creates a dynamic (identified by hash rather than an address) local variable (can be seen in the ghidra UI too)

Screenshot_20221214_153304

But later when the decompiler is re-run, it seems that the hash does not match what has been previously calculated and so the variable you see in UI stays the same.

Unfortunately, I don't know enough about how the hash is calculated (and how to debug the decompiler...), so I am kind stuck here.

DCNick3 avatar Dec 14 '22 13:12 DCNick3

Any progress on this?

palmerj avatar Jan 07 '23 11:01 palmerj

Note my issue is 16bit MZ DOS EXEs (Real mode).

palmerj avatar Jan 09 '23 07:01 palmerj