如何以人类可读的方式打开 Java .class 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/76314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:00:35  来源:igfitidea点击:

How can I open Java .class files in a human-readable way?

javawindowsclassapplet

提问by cpuguru

I'm trying to figure out what a Java applet's class file is doing under the hood. Opening it up with Notepad or Textpad just shows a bunch of gobbledy-gook.

我试图弄清楚 Java 小程序的类文件在幕后做了什么。用记事本或文本板打开它只会显示一堆狼吞虎咽的东西。

Is there any way to wrangle it back into a somewhat-readable format so I can try to figure out what it's doing?

有什么办法可以把它改回一种有点可读的格式,这样我就可以试着弄清楚它在做什么?

  • Environment == Windows w/ VS 2008 installed.
  • 环境 == 安装了 VS 2008 的 Windows。

采纳答案by DarenW

jd-guiis the best decompiler at the moment. it can handle newer features in Java, as compared to the getting-dusty JAD.

jd-gui是目前最好的反编译器。与越来越多的 JAD 相比,它可以处理 Java 中更新的功能。

回答by Rasmus Faber

Using Jadto decompile it is probably your best option. Unless the code has been obfuscated, it will produce an okay result.

使用Jad反编译它可能是你最好的选择。除非代码被混淆,否则它会产生一个好的结果。

回答by cynicalman

That's compiled code, you'll need to use a decompiler like JAD: http://www.kpdus.com/jad.html

这是编译后的代码,你需要使用像 JAD 这样的反编译器:http: //www.kpdus.com/jad.html

回答by Drew Frezell

You want a java decompiler, you can use the command line tool javapto do this. Also, Java Decompiler HOW-TOdescribes how you can decompile a class file.

你想要一个java反编译器,你可以使用命令行工具javap来做到这一点。此外,Java Decompiler HOW-TO描述了如何反编译类文件。

回答by David Beleznay

what you are looking for is a java de-compiler. I recommend JAD http://www.kpdus.com/jad.htmlIt's free for non commercial use and gets the job done.

你正在寻找的是一个java反编译器。我推荐 JAD http://www.kpdus.com/jad.html它可以免费用于非商业用途并完成工作。

Note: this isn't going to make the code exactly the same as what was written. i.e. you're going to lose comments and possibly variable names, so it's going to be a little bit harder than just reading normal source code. If the developer is really secretive they will have obfuscated their code as well, making it even harder to read.

注意:这不会使代码与所写的完全相同。也就是说,您将丢失注释和可能的变量名称,因此这比阅读普通源代码要困难一些。如果开发人员真的很保密,他们也会混淆他们的代码,使其更难阅读。

回答by David Beleznay

As suggested you can use JAD to decompile it and view the files. To make it easier to read you can use the JADclipse plugin for eclipse to integrate JAD directly to eclipse or use DJ Java Decompiler which is much easier to use than command line JAD

根据建议,您可以使用 JAD 对其进行反编译并查看文件。为了更容易阅读,您可以使用 Eclipse 的 JADclipse 插件将 JAD 直接集成到 Eclipse 或使用比命令行 JAD 更容易使用的 DJ Java Decompiler

回答by Michael Myers

If you don't mind reading bytecode, javap should work fine. It's part of the standard JDK installation.

如果您不介意阅读字节码,javap 应该可以正常工作。它是标准 JDK 安装的一部分。

Usage: javap <options> <classes>...

where options include:
   -c                        Disassemble the code
   -classpath <pathlist>     Specify where to find user class files
   -extdirs <dirs>           Override location of installed extensions
   -help                     Print this usage message
   -J<flag>                  Pass <flag> directly to the runtime system
   -l                        Print line number and local variable tables
   -public                   Show only public classes and members
   -protected                Show protected/public classes and members
   -package                  Show package/protected/public classes
                             and members (default)
   -private                  Show all classes and members
   -s                        Print internal type signatures
   -bootclasspath <pathlist> Override location of class files loaded
                             by the bootstrap class loader
   -verbose                  Print stack size, number of locals and args for methods
                             If verifying, print reasons for failure

回答by Daniel Spiewak

JAD is an excellent option if you want readable Java code as a result. If you really want to dig into the internals of the .classfile format though, you're going to want javap. It's bundled with the JDK and allows you to "decompile" the hexadecimal bytecode into readable ASCII. The language it produces is still bytecode (not anything like Java), but it's fairly readable and extremely instructive.

如果您想要可读的 Java 代码,JAD 是一个很好的选择。如果你真的想深入了解.class文件格式的内部结构,你会想要javap. 它与 JDK 捆绑在一起,允许您将十六进制字节码“反编译”为可读的 ASCII。它产生的语言仍然是字节码(与 Java 不同),但它具有相当的可读性并且非常有指导意义。

Also, if you reallywant to, you can open up any .classfile in a hex editor and read the bytecode directly. The result is identical to using javap.

此外,如果您真的愿意,可以.class在十六进制编辑器中打开任何文件并直接读取字节码。结果与使用相同javap

回答by Zac Gochenour

You need to use a decompiler. Others have suggested JAD, there are other options, JAD is the best.

您需要使用反编译器。其他人建议使用 JAD,还有其他选择,JAD 是最好的。

I'll echo the comments that you may lose a bit compared to the original source code. It is going to look especially funny if the code used generics, due to erasure.

我会回应那些与原始源代码相比您可能会丢失一点的评论。由于擦除,如果代码使用泛型,它看起来会特别有趣。

回答by John Gardner

JAD and/or JADclipse Eclipse plugin, for sure.

JAD 和/或 JADclipse Eclipse 插件,当然。