4

I'm working on a function in the Ghidra decompiler with a bunch of variables that are re-used across different scopes. I don't see any way to rename this variable on a per-line basis. Is it possible?

2

Yaldi already mentioned the important first step of Commit Locals for finer variable scoping.

If your Ghidra version has at least the commit https://github.com/NationalSecurityAgency/ghidra/commit/885402bbc3618b895c4b9b8f09300d3120a9abe8 which will probably be in the 9.2 release you can explicitly split a variable after Commit Locals, by right clicking the variable in the decompiler view and selecting Split out as New Variable.

| improve this answer | |
  • Thanks @Florian Magin! 9.2 would be pretty exciting then. :) – Yadli Mar 26 at 17:22
1

This workaround is suggested by GitHub user ubitux, here: https://github.com/NationalSecurityAgency/ghidra/issues/1510, and I can confirm it works around the problem to some degrees.

When you "Commit Locals" for the function, some variable types and the names will be fixed, and the variable scopes will become smaller, so that one variable will be automatically split across multiple scopes. You can then iteratively annotate variable types, rename variables, commit, and the scopes will shrink further.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.