我可以使用什么程序来反编译类文件?我真的会得到Java代码,还是仅仅是JVM汇编代码?

关于这个网站上的Java性能问题,我经常看到一些人的回答,他们“反编译”了Java类文件,以了解编译器如何优化某些东西。


当前回答

我尝试了几种,Procyon似乎最适合我。它正在积极开发中,支持最新版本Java的许多特性。

以下是我尝试过的其他方法:

CFR Promising, but often failed method decompilation. I'll be keeping my eye on this one. Also actively developed with support for the latest Java features. Krakatau Takes a different approach in that it tries to output equivalent Java code instead of trying to reconstruct the original source, which has the potential of making it better for obfuscated code. From my testing it was roughly on par with Procyon, but still nice to have something different. I did have to use the -skip command-line flag so it wouldn't stop on errors. Actively developed, and interestingly enough it's written in Python. JD-GUI Worked, but Procyon's output was much better. Here's a page comparing Procyon output to the original and JD-GUI. JD-GUI is also available as an Eclipse plugin, which didn't work for me at all. Doesn't seem to be open source and development seems sporadic. JAD Worked, but only supports Java 1.4 and below. Also available as an Eclipse plugin. No longer under development.

其他回答

在IntelliJ IDEA平台上,可以使用Java反编译器IntelliJ Plugin。它允许您在调试过程中显示所有Java源代码,即使您没有全部Java源代码。它基于著名的工具JD-GUI。

以下是截至2015年2月的反编译器列表:

Procyon,开源,https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler

CFR,免费,没有源代码,http://www.benf.org/other/cfr/

JD,仅供非商业用途免费,http://jd.benow.ca/

Fernflower,开源,https://github.com/fesh0r/fernflower,

JAD -此处仅为历史原因。免费,没有源代码,http://varaneckas.com/jad/ 过时,不受支持,不能正确反编译Java 5及更高版本。

您可以在线测试上述反编译器,不需要安装,并做出自己的选择。

云中的Java反编译器:http://www.javadecompilers.com/

如果你想知道Java编译器是如何做某些事情的,你不想要反编译,你想要的是反汇编。反编译涉及到将字节码转换为Java源代码,这意味着会丢失大量低级信息,如果您想了解编译器优化,那么这可能正是您感兴趣的信息。

不管怎样,我碰巧写了一个开源Java反汇编程序。与Javap不同的是,这甚至适用于高度病态的类,因此您可以看到混淆工具对您的类做了什么。它还可以进行反编译,尽管我不推荐这样做。

这里有一些反编译器…快速搜索会得到:

Procyon:开源(Apache 2),积极开发 Krakatau:开源(GPLv3),并积极开发 CFR:开源(MIT)并积极开发 联合应用开发 DJ Java反编译器 摩卡

还有更多。

它们生成Java代码。Java自带一些功能,可以让您看到JVM字节代码(javap)。

到目前为止列出的JAD链接似乎都是坏的,所以我找到了这个网站。工作得很好(至少对于Linux)!在Ubuntu 11.10上,不知什么原因,我不得不下载静态版本。

http://www.varaneckas.com/jad