如何“反编译”Java 类文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/272535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I "decompile" Java class files?
提问by Kip
What program can I use to decompile a class file? Will I actually get Java code, or is it just JVM assembly code?
我可以使用什么程序来反编译类文件?我真的会得到 Java 代码,还是只是 JVM 汇编代码?
On Java performance questions on this site I often see responses from people who have "decompiled" the Java class file to see how the compiler optimizes certain things.
在这个站点上的 Java 性能问题上,我经常看到有人“反编译”了 Java 类文件以查看编译器如何优化某些东西。
采纳答案by VonC
Update February 2016:
2016 年 2 月更新:
www.javadecompilers.comlists JAD as being:
www.javadecompilers.com将 JAD 列为:
the most popular Java decompiler, but primarily of this age only. Written in C++, so very fast.
Outdated, unsupported and does not decompile correctly Java 5 and later
最流行的 Java 反编译器,但主要是在这个时代。用 C++ 写的,所以非常快。
过时、不受支持且无法正确反编译 Java 5 及更高版本
So your mileage may vary with recent jdk (7, 8).
所以你的里程可能会随着最近的jdk(7、8)而变化。
The same site list other tools.
同一个站点列出了其他工具。
And javadecompiler, as noted by Salvador Valenciain the comments(Sept 2017), offers a SaaS where you upload the .class
file to the cloud and it returns you the decompiled code.
正如Salvador Valencia在评论(2017 年 9 月)中所指出的,javadecompiler提供了一个 SaaS,您可以在其中将.class
文件上传到云,并返回反编译的代码。
Original answer: Oct. 2008
原答案:2008 年 10 月
- The final release of JSR 176, defining the major features of J2SE 5.0 (Java SE 5), has been published on September 30, 2004.
- The lastest Java version supported by JAD, the famous Java decompiler written by Mr. Pavel Kouznetsov, is JDK 1.3.
- Most of the Java decompilers downloadable today from the Internet, such as “DJ Java Decompiler” or “Cavaj Java Decompiler”, are powered by JAD: they can not display Java 5 sources.
- JSR 176 的最终版本已于 2004 年 9 月 30 日发布,它定义了 J2SE 5.0 (Java SE 5) 的主要特性。
- 由Pavel Kouznetsov 先生编写的著名Java 反编译器JAD 支持的最新Java 版本是JDK 1.3。
- 今天可以从 Internet 下载的大多数 Java 反编译器,例如“DJ Java Decompiler”或“Cavaj Java Decompiler”,都由 JAD 提供支持:它们无法显示 Java 5 源代码。
Java Decompiler(Yet another Fast Java decompiler) has:
Java Decompiler(又一个快速 Java 反编译器)具有:
- Explicit support for decompiling and analyzing Java 5+“.class” files.
- A nice GUI:
- 显式支持反编译和分析Java 5+“.class”文件。
- 一个不错的图形用户界面:
It works with compilers from JDK 1.1.8 up to JDK 1.7.0, and others (Jikes, JRockit, etc.).
它适用于从 JDK 1.1.8 到 JDK 1.7.0 以及其他(Jikes、JRockit等)的编译器。
It features an online live demo versionthat is actually fully functional! You can just drop a jar file on the page and see the decompiled source code without installing anything.
它具有在线实时演示版本,实际上功能齐全!您只需在页面上放置一个 jar 文件即可查看反编译的源代码,而无需安装任何东西。
回答by Marko
To see Java source code check some decompiler. Go search for jad.
要查看 Java 源代码,请检查一些反编译器。去寻找jad。
If you want to see bytecodes, just use javapwhich comes with the JDK.
如果您想查看字节码,只需使用JDK 附带的javap。
回答by billjamesdev
There are a few decompilers out there... A quick search yields:
有一些反编译器......快速搜索产生:
- Procyon: open-source (Apache 2) and actively developed
- Krakatau: open-source (GPLv3) and actively developed
- CFR: open-source (MIT) and actively developed
- JAD
- DJ Java Decompiler
- Mocha
And many more.
还有很多。
These produce Java code. Java comes with something that lets you see JVM byte code (javap).
这些生成 Java 代码。Java 附带了一些可以让您查看 JVM 字节码 ( javap) 的东西。
回答by Mike Pone
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.
您可以使用一些程序。您将获得实际的 Java 代码,但有时代码会被混淆,因此方法以一个字母或数字或字母和数字的随机组合命名。
回答by sakana
I use JAD Decompiler.
我使用JAD 反编译器。
There is an Eclipseplugin for it, jadeclipse. It is pretty nice.
有一个Eclipse插件,jadeclipse。这很不错。
回答by John Meagher
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.
大多数 Java 反编译器都基于JAD。这是一个很棒的工具,但不幸的是,它已经有一段时间没有更新了,并且不能很好地处理 Java 1.5+ 类。我还没有看到任何可以正确处理 1.5+ 类的工具。
回答by Quinn Taylor
Sootis an option for newer Java code. At least it has the advantage of still being recently maintained...
Soot是较新的 Java 代码的一个选项。至少它的优点是最近还在维护......
Also, Java Decompileris a decompiler with both a stand-alone GUI and Eclipse integration.
此外,Java Decompiler是一个具有独立 GUI 和 Eclipse 集成的反编译器。
Lastly, Jdechasn't been mentioned, though it's not as polished as other options.
最后,还没有提到Jdec,尽管它不像其他选项那样完善。
回答by Berlin Brown
JAD is one that works and is simple.
Also, if you just want to see the methods, use javap.
JAD 是一种有效且简单的方法。
另外,如果您只想查看方法,请使用 javap。