如何“反编译” Java 类文件?
我可以使用什么程序来反编译类文件? 我真的会得到 Java 代码吗?还是只是 JVM 汇编代码?
在这个网站上的 Java 性能问题上,我经常看到人们的回答,他们“反编译”了 Java 类文件,以了解编译器如何优化某些内容。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
如果您想了解 Java 编译器如何执行某些操作,您不需要反编译,您需要反汇编。 反编译涉及将字节码转换为 Java 源代码,这意味着会丢失大量低级信息,如果您想了解编译器优化,这可能正是您感兴趣的信息。
无论如何,我碰巧写了一个开源 Java 反汇编器。 与 Javap 不同,这甚至适用于高度病态的类,因此您也可以看到混淆工具对您的类做了什么。 它也可以进行反编译,但我不推荐它。
If you want to see how the Java compiler does certain things, you don't want decompilation, you want disassembly. Decompilation involves transforming the bytecode into Java source, meaning that a lot of low level information is lost, and if you're wondering about compiler optimization, this is probably the very information you're interested in.
Anyway, I happen to have written an open source Java disassembler. Unlike Javap, this works even on highly pathological classes, so you can see what obfuscation tools are doing to your classes as well. It can also do decompilation, though I wouldn't recommend it.
JAD 对我不起作用(Ubuntu 11.10 问题),所以我继续前进并放弃了 JODO。 至少它有开放的Java源代码并且能够正确反编译我的.class。
我建议首先查看'branches/generic'分支。 树干不稳定。
JAD doesn't work for me (Ubuntu 11.10 issue) so I've moved forward and sopped on JODO. At least it has Open Java source code and been able to decompile my .class properly.
I recommend to check out 'branches/generic' branch first. The trunks is not stable.
在 IntelliJ IDEA 平台上,您可以使用Java Decompiler IntelliJ Plugin。 它允许您在调试过程中显示所有 Java 源代码,即使您没有全部源代码。 它基于著名的工具JD-GUI。
On IntelliJ IDEA platform you can use Java Decompiler IntelliJ Plugin. It allows you to display all the Java sources during your debugging process, even if you do not have them all. It is based on the famous tools JD-GUI.
使用 AndroChef Java Decompiler,您可以反编译 apk、dex、jar 和 java 类文件。 这很简单。 AndroChef JD 基于 FernFlower。 您可以免费使用 10 次来对其进行评估。
With AndroChef Java Decompiler you can decompile apk, dex, jar and java class-files. It's simple and easy. AndroChef JD is based on FernFlower. You can evaluate it in 10 free uses.
对于 OSX,我推荐:jarzilla 或 JD-GUI
它们都允许您查看 jar、war 等。 文件内容并反编译其中的任何类文件。
Jarzilla:https://code.google.com/p/jarzilla/
JD-GUI:http://jd.benow.ca/
For OSX I recommend: jarzilla or JD-GUI
They both allow you to view jar,war,etc. file content and decompiles any class files inside of them.
Jarzilla: https://code.google.com/p/jarzilla/
JD-GUI: http://jd.benow.ca/
2016 年 2 月更新:
www.javadecompilers.com 将 JAD 列出为:
因此,您的情况可能会因最新的 jdk (7, 8) 而异。
同一网站列出了其他工具。
和 javadecompiler,如 Salvador Valencia 在 评论(2017 年 9 月),提供了一个 SaaS,您可以将
.class
文件上传到云端,它会返回反编译的代码。原始答案:2008年10月
Java Decompiler(又一个快速 Java 反编译器)具有:
它适用于从 JDK 1.1.8 到 JDK 1.7.0 及其他版本的编译器(Jikes, JRockit 等)。
它具有在线现场演示版本,实际上功能齐全! 您只需将 jar 文件拖放到页面上即可查看反编译的源代码,而无需安装任何东西。
Update February 2016:
www.javadecompilers.com lists JAD as being:
So your mileage may vary with recent jdk (7, 8).
The same site list other tools.
And javadecompiler, as noted by Salvador Valencia in the comments (Sept 2017), offers a SaaS where you upload the
.class
file to the cloud and it returns you the decompiled code.Original answer: Oct. 2008
Java Decompiler (Yet another Fast Java decompiler) has:
It works with compilers from JDK 1.1.8 up to JDK 1.7.0, and others (Jikes, JRockit, etc.).
It features an online live demo version that is actually fully functional! You can just drop a jar file on the page and see the decompiled source code without installing anything.
那里有一些反编译器...快速搜索一下:
还有更多。
这些生成 Java 代码。 Java 附带了一些可以让您查看 JVM 字节码的东西 (javap )。
There are a few decompilers out there... A quick search yields:
And many more.
These produce Java code. Java comes with something that lets you see JVM byte code (javap).
要查看 Java 源代码,请检查一些反编译器。 去搜索jad。
如果你想查看字节码,只需使用JDK自带的javap即可。
To see Java source code check some decompiler. Go search for jad.
If you want to see bytecodes, just use javap which comes with the JDK.
我尝试了几种,Procyon 似乎最适合我。 它正在积极开发中,并支持最新版本 Java 的许多功能。
这些是我尝试过的其他方法:
I tried several, and Procyon seemed to work the best for me. It's under active development and supports many features of the latest versions of Java.
These are the others I tried:
-skip
command-line flag so it wouldn't stop on errors. Actively developed, and interestingly enough it's written in Python.我使用 JAD 反编译器。
有一个 Eclipse 插件,jadeclipse。 这是相当不错的。
I use JAD Decompiler.
There is an Eclipse plugin for it, jadeclipse. It is pretty nice.
Procyon 包含一个反编译器。 这是福斯。
Procyon includes a decompiler. It is FOSS.
Soot 是较新 Java 代码的一个选项。 至少它的优点是最近仍在维护...
另外,Java Decompiler< /a> 是一个具有独立 GUI 和 Eclipse 集成的反编译器。
最后,Jdec 尚未被提及,尽管它不像其他选项那么完善。
Soot is an option for newer Java code. At least it has the advantage of still being recently maintained...
Also, Java Decompiler is a decompiler with both a stand-alone GUI and Eclipse integration.
Lastly, Jdec hasn't been mentioned, though it's not as polished as other options.
JD-GUI真的很好。 您只需打开一个 JAR 文件并浏览代码,就好像
您正在开发 IDE。 好东西。
JD-GUI is really good. You could just open a JAR file and browse through the code as if
you are working on an IDE. Good stuff.
以下是截至 2015 年 2 月的反编译器列表:
Procyon、开源、https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler
CFR,免费,无源代码可用,http://www.benf.org/other/cfr/
JD,非商业免费仅使用http://jd.benow.ca/
Fernflower,打开-source,https://github.com/fesh0r/fernflower,
JAD – 此处仅出于历史原因给出。 免费,无源代码,http://varaneckas.com/jad/
过时、不受支持且无法正确反编译 Java 5 及更高版本。
您可以在线测试上述反编译器,无需安装,并做出您自己的明智选择。
云中的 Java 反编译器: http://www.javadecompilers.com/
Here's a list of decompilers as of Feb 2015:
Procyon, open-source, https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler
CFR, free, no source-code available, http://www.benf.org/other/cfr/
JD, free for non-commercial use only, http://jd.benow.ca/
Fernflower, open-source, https://github.com/fesh0r/fernflower,
JAD – given here only for historical reason. Free, no source-code available, http://varaneckas.com/jad/
Outdated, unsupported and does not decompile correctly Java 5 and later.
You may test above-mentioned decompilers online, no installation required and make your own educated choice.
Java decompilers in the cloud: http://www.javadecompilers.com/
您可以使用一些程序。 您将获得实际的 Java 代码,但有时代码会被混淆,因此方法由一个字母或数字或字母和数字的随机组合命名。
DJ 反编译器
摩卡
There are a few programs you can use. You will get the actual Java code, but sometimes the code will have been obfuscated so methods are named by one letter or number or a random mix of letters and numbers.
DJ Decompiler
Mocha
大多数 Java 反编译器都基于 JAD。 这是一个很棒的工具,但不幸的是有一段时间没有更新了,并且不能很好地处理 Java 1.5+ 类。 我还没有看到任何工具可以正确处理 1.5+ 类。
Most decompilers for Java are based on JAD. It's a great tool, but unfortunately hasn't been updated for a while and does not handle Java 1.5+ classes very well. I have not seen any tools that will properly handle 1.5+ classes.
看看cavaj。
Take a look at cavaj.
到目前为止列出的所有 JAD 链接似乎都已损坏,所以我找到了这个网站。 效果很好(至少对于 Linux 来说)! 在 Ubuntu 11.10 上,无论出于何种原因,我都必须下载静态版本。
http://www.varaneckas.com/jad
All of the JAD links listed so far far seem to be broken, so I found this site. Works great (for Linux, at least)! On Ubuntu 11.10 I had to download the static one for whatever reason.
http://www.varaneckas.com/jad
JAD 是一种有效且简单的方法。
另外,如果您只想查看方法,请使用 javap。
JAD is one that works and is simple.
Also, if you just want to see the methods, use javap.