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

[feature] Plug-in development issues, variables in functions cannot be obtained and adding comments is invalid #2350

Open
dooker520 opened this issue Nov 20, 2024 · 3 comments

Comments

@dooker520
Copy link

Describe your idea

https://github.com/dooker520/Jadx-hzhuAi-Plugin

I encountered a problem when developing a plug-in. I couldn't get the variable list in the function through the function, and the modified comments were invalid.

@skylot
Copy link
Owner

skylot commented Nov 20, 2024

I couldn't get the variable list
List argNodes = methodNode.collectArgNodes();

That method should work, I will check it, although to reproduce this I need some tests, so it might take some time

and the modified comments were invalid

Comments don't have any public API to be saved into project and applied in class code generation. So no easy way for now, only using additional pass (check jadx example plugin code). You need to save all your comments in map like Map<ClassNode, String> and in your comment pass add to class in visit method. To force code reload, you need to invoke ClassNode.reloadCode() also to refresh open tabs in gui you might need to run JadxGuiContext.reloadAllTabs()

Actually, using decompilation pass is always a preferred way to change code, so issue with variables also can be solved same way as an approach with comments. I think, I will prepare example for that.

@dooker520
Copy link
Author

List argNodes = methodNode.collectArgNodes();

I tested this method and can only get it. The passed in parameter list cannot get the local variables.

If you use AI to optimize the code during the decompilation process, there may be performance problems, because some codes themselves do not need too much AI optimization.

@skylot
Copy link
Owner

skylot commented Nov 21, 2024

@dooker520
I make an example plugin to show how to rename classes, fields, methods and method parameters, check code here:
https://github.com/jadx-decompiler/jadx-plugin-examples/blob/main/examples/bulk-rename/src/main/java/jadx/plugins/examples/bulkrename/BulkRenamePlugin.java#L16
The same approach can be used to add code comments.
Hope it will help 🙂

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

No branches or pull requests

2 participants