简体   繁体   English

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

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

I'm trying to figure out what a Java applet's class file is doing under the hood. 我正在试图弄清楚Java applet的类文件在做什么。 Opening it up with Notepad or Textpad just shows a bunch of gobbledy-gook. 用记事本或Textpad打开它只会显示出一堆狼吞虎咽的东西。

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. 环境== Windows w / VS 2008已安装。

jd-gui is the best decompiler at the moment. jd-gui是目前最好的反编译器。 it can handle newer features in Java, as compared to the getting-dusty JAD. 与尘封的JAD相比,它可以处理Java中的新功能。

If you don't mind reading bytecode, javap should work fine. 如果您不介意阅读字节码,javap应该可以正常工作。 It's part of the standard JDK installation. 它是标准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

You want a java decompiler, you can use the command line tool javap to do this. 你想要一个java反编译器,你可以使用命令行工具javap来做到这一点。 Also, Java Decompiler HOW-TO describes how you can decompile a class file. 此外, Java Decompiler HOW-TO描述了如何反编译类文件。

As pointed out by @MichaelMyers, use 正如@MichaelMyers所指出的,使用

javap -c <name of java class file> 

to get the JVM assembly code. 获取JVM汇编代码。 You may also redirect the output to a text file for better visibility. 您还可以将输出重定向到文本文件以获得更好的可见性。

javap -c <name of java class file> > decompiled.txt

jd-gui“ http://code.google.com/p/innlab/downloads/detail?name=jd-gui-0.3.3.windows.zip&can=2&q= ”是反编译.class的最佳和用户友好选项文件....

cpuguru, if your applet has been compiled with javac 1.3 (or less), your best option is to use Jad. cpuguru,如果您的applet已经使用javac 1.3(或更低版本)编译,那么您最好的选择是使用Jad。

Unfortunately, the last JDK supported by JAD 1.5.8 (Apr 14, 2001) is JDK 1.3. 不幸的是,JAD 1。5。8(2001年4月14日)支持的最后一个JDK是JDK 1.3。

If your applet has been compiled with a more recent compiler, you could try JD-GUI : this decompiler is under development, nevertheless, it generates correct Java sources, most of time, for classes compiled with the JDKs 1.4, 1.5 or 1.6. 如果您的applet已经使用更新的编译器进行编译,那么您可以尝试使用JD-GUI :这个反编译器正在开发中,但是,对于使用JDK 1.4,1.5或1.6编译的类,它大多数时间都会生成正确的Java源代码。

DarenW, thank you for your post. 达伦,谢谢你的帖子。 JD-GUI is not the best decompiler yet ... but I'm working on :) JD-GUI还不是最好的反编译器......但我正在努力:)

Using Jad to decompile it is probably your best option. 使用Jad进行反编译可能是您最好的选择。 Unless the code has been obfuscated, it will produce an okay result. 除非代码被混淆,否则它将产生一个好的结果。

what you are looking for is a java de-compiler. 您正在寻找的是java解编译器。 I recommend JAD http://www.kpdus.com/jad.html It's free for non commercial use and gets the job done. 我推荐JAD http://www.kpdus.com/jad.html它可以免费用于非商业用途并完成工作。

Note: this isn't going to make the code exactly the same as what was written. 注意:这不会使代码与编写的代码完全相同。 ie 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. 如果开发人员真的很隐秘,他们也会对代码进行模糊处理,使其更难阅读。

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

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. 如果代码使用泛型,由于擦除,它看起来会特别有趣。

肯定是JAD和/或JADclipse Eclipse插件。

If the class file you want to look into is open source, you should not decompile it, but instead attach the source files directly into your IDE. 如果要查看的类文件是开源的,则不应对其进行反编译,而是将源文件直接附加到IDE中。 that way, you can just view the code of some library class as if it were your own 这样,您可以只查看某些库类的代码,就好像它是您自己的代码一样

CFR - 另一个java反编译器是一个伟大的反编译器,用于编写Java 6的现代Java。

you can also use the online java decompilers available. 你也可以使用在线java反编译器。 For eg http://www.javadecompilers.com 例如http://www.javadecompilers.com

As suggested you can use JAD to decompile it and view the files. 如建议您可以使用JAD对其进行反编译并查看文件。 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 为了便于阅读,您可以使用eclipse的JADclipse插件将JAD直接集成到eclipse或使用DJ Java Decompiler,它比命令行JAD更容易使用

JAD is an excellent option if you want readable Java code as a result. 如果您想要可读的Java代码,JAD是一个很好的选择。 If you really want to dig into the internals of the .class file format though, you're going to want javap . 如果您真的想深入研究.class文件格式的内部,那么您将需要javap It's bundled with the JDK and allows you to "decompile" the hexadecimal bytecode into readable ASCII. 它与JDK捆绑在一起,允许您将十六进制字节码“反编译”为可读的ASCII。 The language it produces is still bytecode (not anything like Java), but it's fairly readable and extremely instructive. 它产生的语言仍然是字节码(不像Java那样),但它具有相当的可读性和极具指导性。

Also, if you really want to, you can open up any .class file in a hex editor and read the bytecode directly. 此外,如果您真的想要,可以在十六进制编辑器中打开任何.class文件并直接读取字节码。 The result is identical to using javap . 结果与使用javap相同。

There is no need to decompile Applet.class. 无需反编译Applet.class。 The public Java API classes sourcecode comes with the JDK (if you choose to install it), and is better readable than decompiled bytecode. 公共Java API类源代码随JDK一起提供(如果您选择安装它),并且比反编译的字节码更易读。 You can find compressed in src.zip (located in your JDK installation folder). 您可以在src.zip(位于JDK安装文件夹中)中找到压缩文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM