用于代码操作的 Eclipse 抽象语法树解析器的替代方案
背景
我正在编写一个程序,它将对 java 源代码目录中的成员和函数进行一些批量重命名,以根据传入程序的查找表 .csv 文件对代码进行反混淆。
这是为了我的源代码是针对一个混淆的 jar 编写的。我有一个通过自定义版本 RetroGaurd 运行的 jar 的去混淆版本我想解析传递到 RetroGaurd 的映射文件,以对我的源代码在 jar 中进行的函数调用进行反混淆。如果我只是编译我的代码并在反编译时也通过 RetroGaurd 运行它,我会丢失所有好的注释和格式(除非我错过了 RetroGaurd 上的一个选项)。
问题
我发现构建了 抽象语法树 解析器到 Eclipse 中,它看起来非常适合我的使用,但是我不打算将我的程序编写为 Eclipse 的插件,这将是一个可以在任何计算机上运行的独立 jar。
我主要担心的是,当我编写代码时,我对 Eclipse 使用的内部 jar 产生了很多依赖。我知道,如果我符合库 jar 的 EPL 我将没有分发它的问题,但我担心这个项目会随着我编写它而变得越来越大,因为需要来自 Eclipse SDK 的越来越多的 jars。
是否有其他项目可以让我能够像 AST 那样解析 Java 源代码以进行可靠的查找和替换,或者有没有办法使用 RetroGaurd(或类似的程序)来运行相同的功能去混淆但保持我的注释和功能相同,而不需要随后通过反编译器运行去混淆的程序?
Background
I am writing a program that will do some bulk renaming of members and functions in a directory of java source code to de-obfuscate the code based on a look-up table .csv file passed in to the program.
What this is for is the source code I have was written against a obfuscated jar. I have a de-obfuscated version of the jar that was run through a customized version RetroGaurd and I would like to parse the mapping file that was passed in to RetroGaurd to de-obfuscate the function calls my source code makes in to the jar. If I just compile my code and run it through RetroGaurd too when I decompile I loose all of my nice commenting and formatting (unless there is a option on RetroGaurd that I missed).
Problem
I found the Abstract Syntax Tree parser built in to Eclipse and it looks perfect for my uses, however I am not planning on writing my program as a plugin for Eclipse, this is going to be a stand alone jar that can be run on any machine.
My main concern is as I write my code I am getting a lot of dependencies on internal jars that Eclipse uses. I know that if I conform to the EPL for the library jars I will have no issues distributing it, but I am concerned about this project getting bigger and bigger as I write it as more and more jars from Eclipse's SDK are required.
Are there any other projects out there that would give me the ability to parse Java source code to do find and replace reliably like AST will allow me to, or is there a way to use RetroGaurd (or a program like it) to run the same de-obfuscation but keep my comments and functions the same without needing to run the de-obfuscated program though a de-compiler afterwards?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您担心需要运行 Eclipse GUI 来执行代码,那么您可以考虑在无头模式下运行插件。这将允许您的插件从命令行运行。请参阅此SO 线程。
您还可以使用任何其他开源 java 编译器。例如,openjdk 的 Java 编译器。请参阅资源部分。
希望有帮助。
If you're worried about the need to run Eclipse GUI to execute your code, then you could consider running the plugin in headless mode. This would allow your plugin to be run from command line. See this SO thread.
You could also use any other open source java compiler. For e.g., openjdk's Java compiler. Please refer to the Resources section.
Hope it helps.