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

2022-08-31 08:20:47

我试图弄清楚Java小程序的类文件在引擎盖下做了什么。用记事本或 Textpad 打开它只会显示一堆胡言乱语的咕噜咕噜。

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

  • 环境 == Windows 已安装 VS 2008。

答案 1

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


答案 2

如果你不介意阅读字节码,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