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

时间:2022-11-24 20:44:08

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 applet的类文件在幕后做什么。用记事本或文本本打开它只会显示一堆乱七八糟的东西。

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安装。

17 个解决方案

#1


182  

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

jd-gui是目前最好的反编译器。与尘土飞扬的JAD相比,它可以处理Java中的更新特性。

#2


66  

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

#3


7  

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

您需要一个java反编译器,您可以使用命令行工具javap来实现这一点。此外,Java反编译器how - to描述了如何对类文件进行反编译。

#4


2  

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

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

#5


2  

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

您正在寻找的是java反编译器。我推荐http://www.jad 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.

注意:这不会使代码与编写的代码完全相同。也就是说,你会丢失注释和变量名,所以这比仅仅阅读普通的源代码要难得多。如果开发人员真的保密,他们也会混淆他们的代码,使其更难阅读。

#6


2  

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支持的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.

如果您的小应用程序是用最近的编译器编译的,那么您可以尝试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 :)

DarenW,谢谢你的邮件。JD-GUI并不是最好的反编译器…但我正在努力:)

#7


1  

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这样的反编译器

#8


1  

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.

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

#9


1  

JAD and/or JADclipse Eclipse plugin, for sure.

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

#10


1  

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. that way, you can just view the code of some library class as if it were your own

如果要查看的类文件是开放源码的,那么不应该对其进行分解,而应该将源文件直接附加到IDE中。这样,您就可以查看一些库类的代码,就像它是您自己的一样。

#11


0  

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,或者使用DJ Java反编译器,它比命令行JAD更容易使用

#12


0  

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 .class file 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 really want to, you can open up any .class file in a hex editor and read the bytecode directly. The result is identical to using javap.

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

#13


0  

There is no need to decompile 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. You can find compressed in src.zip (located in your JDK installation folder).

没有必要分解Applet.class。公共Java API类sourcecode附带了JDK(如果您选择安装它),并且比反编译字节码可读性更好。在src中可以找到压缩文件。zip(位于JDK安装文件夹中)。

#14


0  

jd-gui "http://code.google.com/p/innlab/downloads/detail?name=jd-gui-0.3.3.windows.zip&can=2&q=" is the best and user friendly option for decompiling .class file....

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

#15


0  

CFR - another java decompiler is a great decompiler for modern Java written i Java 6.

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

#16


0  

As pointed out by @MichaelMyers, use

正如@MichaelMyers所指出的,使用。

javap -c <name of java class file> 

to get the JVM assembly code. You may also redirect the output to a text file for better visibility.

获取JVM组装代码。您还可以将输出重定向到文本文件,以获得更好的可见性。

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

#17


0  

you can also use the online java decompilers available. For e.g. http://www.javadecompilers.com

您还可以使用可用的在线java反编译器。例如,http://www.javadecompilers.com

#1


182  

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

jd-gui是目前最好的反编译器。与尘土飞扬的JAD相比,它可以处理Java中的更新特性。

#2


66  

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

#3


7  

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

您需要一个java反编译器,您可以使用命令行工具javap来实现这一点。此外,Java反编译器how - to描述了如何对类文件进行反编译。

#4


2  

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

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

#5


2  

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

您正在寻找的是java反编译器。我推荐http://www.jad 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.

注意:这不会使代码与编写的代码完全相同。也就是说,你会丢失注释和变量名,所以这比仅仅阅读普通的源代码要难得多。如果开发人员真的保密,他们也会混淆他们的代码,使其更难阅读。

#6


2  

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支持的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.

如果您的小应用程序是用最近的编译器编译的,那么您可以尝试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 :)

DarenW,谢谢你的邮件。JD-GUI并不是最好的反编译器…但我正在努力:)

#7


1  

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这样的反编译器

#8


1  

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.

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

#9


1  

JAD and/or JADclipse Eclipse plugin, for sure.

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

#10


1  

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. that way, you can just view the code of some library class as if it were your own

如果要查看的类文件是开放源码的,那么不应该对其进行分解,而应该将源文件直接附加到IDE中。这样,您就可以查看一些库类的代码,就像它是您自己的一样。

#11


0  

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,或者使用DJ Java反编译器,它比命令行JAD更容易使用

#12


0  

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 .class file 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 really want to, you can open up any .class file in a hex editor and read the bytecode directly. The result is identical to using javap.

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

#13


0  

There is no need to decompile 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. You can find compressed in src.zip (located in your JDK installation folder).

没有必要分解Applet.class。公共Java API类sourcecode附带了JDK(如果您选择安装它),并且比反编译字节码可读性更好。在src中可以找到压缩文件。zip(位于JDK安装文件夹中)。

#14


0  

jd-gui "http://code.google.com/p/innlab/downloads/detail?name=jd-gui-0.3.3.windows.zip&can=2&q=" is the best and user friendly option for decompiling .class file....

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

#15


0  

CFR - another java decompiler is a great decompiler for modern Java written i Java 6.

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

#16


0  

As pointed out by @MichaelMyers, use

正如@MichaelMyers所指出的,使用。

javap -c <name of java class file> 

to get the JVM assembly code. You may also redirect the output to a text file for better visibility.

获取JVM组装代码。您还可以将输出重定向到文本文件,以获得更好的可见性。

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

#17


0  

you can also use the online java decompilers available. For e.g. http://www.javadecompilers.com

您还可以使用可用的在线java反编译器。例如,http://www.javadecompilers.com