如何“反编译” Java 类文件?

发布于 2024-07-07 21:00:58 字数 131 浏览 8 评论 0 原文

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

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

What program can I use to decompile a class file? Will I actually get Java code, or is it just JVM assembly code?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

奈何桥上唱咆哮 2024-07-14 21:00:59

如果您想了解 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.

撩人痒 2024-07-14 21:00:59

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.

东走西顾 2024-07-14 21:00:59

在 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.

enter image description here

往日 2024-07-14 21:00:59

使用 AndroChef Java Decompiler,您可以反编译 apk、dex、jar 和 java 类文件。 这很简单。 AndroChef JD 基于 FernFlower。 您可以免费使用 10 次来对其进行评估。

AndroChef 支持 Java 语言功能,例如泛型、枚举和注释。 根据一些研究,AndroChef Java Decompiler 能够反编译 98.04% 的使用传统 Java 编译器生成的 Java 应用程序 - 恢复率非常高。 它是一个简单但功能强大的工具,允许您将 Java 和 Dalvik 字节码(DEX、APK)反编译为可读的 Java 源代码。

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.

AndroChef supports Java language features like generics, enums and annotations. According to some studies, AndroChef Java Decompiler is able to decompile 98.04% of Java applications generated with traditional Java compilers - a very high recovery rate. It is simple but powerful tool that allows you to decompile Java and Dalvik bytecode (DEX, APK) into readable Java source.

我的鱼塘能养鲲 2024-07-14 21:00:59

对于 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/

梦魇绽荼蘼 2024-07-14 21:00:58

2016 年 2 月更新:

www.javadecompilers.com 将 JAD 列出为:

最流行的 Java 反编译器,但主要仅限于这个时代。 用 C++ 编写,速度非常快。
过时、不受支持且无法正确反编译 Java 5 及更高版本

因此,您的情况可能会因最新的 jdk (7, 8) 而异。

同一网站列出了其他工具。

和 javadecompiler,如 Salvador Valencia评论(2017 年 9 月),提供了一个 SaaS,您可以将 .class 文件上传到云端,它会返回反编译的代码。


原始答案:2008年10月

  • JSR 176的最终版本定义了J2SE 5.0(Java SE 5)的主要功能,已于2004年9月30日发布。JAD
  • 支持的最新Java版本,JAD是由Mr.编写的著名Java反编译器帕维尔·库兹涅佐夫 (Pavel Kouznetsov),是 JDK 1.3
  • 目前可从 Internet 下载的大多数 Java 反编译器(例如“DJ Java Decompiler”或“Cavaj Java Decompiler”)均由 JAD 提供支持:它们无法显示 Java 5 源代码。

Java Decompiler(又一个快速 Java 反编译器)具有:

  • 对反编译和分析 Java 5+< 的显式支持/strong> “.class” 文件。
  • 一个漂亮的 GUI:

screenshot

它适用于从 JDK 1.1.8 到 JDK 1.7.0 及其他版本的编译器(Jikes, JRockit 等)。

它具有在线现场演示版本,实际上功能齐全! 您只需将 jar 文件拖放到页面上即可查看反编译的源代码,而无需安装任何东西。

Update February 2016:

www.javadecompilers.com lists JAD as being:

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

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

  • 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.

Java Decompiler (Yet another Fast Java decompiler) has:

  • Explicit support for decompiling and analyzing Java 5+ “.class” files.
  • A nice GUI:

screenshot

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.

瑾兮 2024-07-14 21:00:58

那里有一些反编译器...快速搜索一下:

  1. Procyon:开源(Apache 2 )并积极开发
  2. Krakatau:开源(GPLv3)并积极开发
  3. CFR:开源 (MIT) 并积极开发
  4. JAD
  5. DJ Java 反编译器
  6. 摩卡

还有更多。

这些生成 Java 代码。 Java 附带了一些可以让您查看 JVM 字节码的东西 (javap )。

There are a few decompilers out there... A quick search yields:

  1. Procyon: open-source (Apache 2) and actively developed
  2. Krakatau: open-source (GPLv3) and actively developed
  3. CFR: open-source (MIT) and actively developed
  4. JAD
  5. DJ Java Decompiler
  6. Mocha

And many more.

These produce Java code. Java comes with something that lets you see JVM byte code (javap).

琴流音 2024-07-14 21:00:58

要查看 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.

凉栀 2024-07-14 21:00:58

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

这些是我尝试过的其他方法:

  • CFR
    • 很有希望,但方法反编译经常失败。 我会密切关注这一点。 还积极开发对最新 Java 功能的支持。
  • 喀拉喀托
    • 采用不同的方法,它尝试输出等效的 Java 代码,而不是尝试重建原始源代码,这有可能使其更好地处理混淆代码。 从我的测试来看,它与 Procyon 大致相当,但仍然很高兴有一些不同的东西。 我确实必须使用 -skip 命令行标志,这样它就不会因错误而停止。 积极开发,有趣的是它是用 Python 编写的。
  • JD-GUI
  • JAD
    • 可以工作,但仅支持 Java 1.4 及更低版本。 也可作为 Eclipse 插件使用。 不再开发。

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:

  • 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
  • JAD
    • Worked, but only supports Java 1.4 and below. Also available as an Eclipse plugin. No longer under development.
不必你懂 2024-07-14 21:00:58

我使用 JAD 反编译器

有一个 Eclipse 插件,jadeclipse。 这是相当不错的。

I use JAD Decompiler.

There is an Eclipse plugin for it, jadeclipse. It is pretty nice.

方圜几里 2024-07-14 21:00:58

Procyon 包含一个反编译器。 这是福斯。

Procyon includes a decompiler. It is FOSS.

友欢 2024-07-14 21:00:58

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.

江南月 2024-07-14 21:00:58

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.

可可 2024-07-14 21:00:58

以下是截至 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/

我不吻晚风 2024-07-14 21:00:58

您可以使用一些程序。 您将获得实际的 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

苏别ゝ 2024-07-14 21:00:58

大多数 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.

打小就很酷 2024-07-14 21:00:58

看看cavaj

Take a look at cavaj.

萌面超妹 2024-07-14 21:00:58

到目前为止列出的所有 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

审判长 2024-07-14 21:00:58
  • JAD 是一种有效且简单的方法。

  • 另外,如果您只想查看方法,请使用 javap。

  • JAD is one that works and is simple.

  • Also, if you just want to see the methods, use javap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文