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

Allow a program driving ILSpy.Decompilation to provide variable names during decompilation #3155

Open
Velociraptor115 opened this issue Jan 16, 2024 · 3 comments
Labels
Enhancement Areas for improvement

Comments

@Velociraptor115
Copy link

Is your feature request related to a problem? Please describe.
Some assemblies have huge methods with complex logic. ILSpy decompiles them with generic variable names. It takes time to understand the meaning of the variables. It would be helpful for programs that specialize the decompiling capability provided by ILSpy for their specific use cases, if ILSpy would provide a way for the driver program to hook into the variable name generation part

Describe the solution you'd like
An interface or hook for the driver program to provide suggested names to ILVariables

Additional context
In the C# game modding context, we would like to track changes to the main assembly and possibly share our own local name mapping with fellow modders (it would be problematic to share the entire decompiled source).
I have modified ILSpy a tiny bit here to help provide a map of local names with the driver program
I believe this is a common problem for modders in general, so it would be beneficial to have a common, better way of doing this

@Velociraptor115 Velociraptor115 added the Enhancement Areas for improvement label Jan 16, 2024
@dgrunwald
Copy link
Member

There's already an interface IDebugInfoProvider intended for proving pluggable support for debug information (e.g. different .pdb file readers). This includes the functionality to provide variable names for local slots via the TryGetName method.

@Velociraptor115
Copy link
Author

Velociraptor115 commented Jan 22, 2024

That is what I used initially
However, it doesn't cover StackSlot variables - the intermediate variables introduced by ILSpy for the sake of readability
What I'm describing is a way to extend or hook into the name generation part, rather than a mapping of locals to variable names

@Velociraptor115
Copy link
Author

I have noticed a related issue
The variable name generation in ILSpy.Decompilation performs name collision checks on the entire method, I assume for performance and simplicity reasons.

For the reasons stated initially in this thread, long methods result in loop index variables, loop enumerator variables, and similar limited scope variables having unnecessary number suffixes appended to them.

Would modifying the logic to perform scope-based name collision detection be a good enhancement to ILSpy.Decompilation in general?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Areas for improvement
Projects
None yet
Development

No branches or pull requests

2 participants