5

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 Answers 2

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.

1
  • Thanks @Florian Magin! 9.2 would be pretty exciting then. :)
    – Yadli
    Commented Mar 26, 2020 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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