博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何查看java的class文件
阅读量:6862 次
发布时间:2019-06-26

本文共 15402 字,大约阅读时间需要 51 分钟。

1.首先拿到javac文件 例如:test.class

2.可以使用文本编辑器用二进制的方式打开()

cafe babe 0000 0034 0056 0a00 1200 32090010 0033 0b00 3400 3507 0036 0a00 04003208 0037 0a00 0400 380b 0039 003a 08003b0b 0039 003c 0a00 0400 3d09 0010 003e0b00 3f00 4008 0041 0800 4207 0043 0a004400 4507 0046 0100 066c 6f67 6765 72010012 4c6f 7267 2f73 6c66 346a 2f4c 6f676765 723b 0100 0663 6c69 656e 7401 003c4c6f 7267 2f73 7072 696e 6766 7261 6d65776f 726b 2f63 6c6f 7564 2f63 6c69 656e742f 6469 7363 6f76 6572 792f 4469 73636f76 6572 7943 6c69 656e 743b 0100 1952756e 7469 6d65 5669 7369 626c 6541 6e6e6f74 6174 696f 6e73 0100 384c 6f72 672f7370 7269 6e67 6672 616d 6577 6f72 6b2f6265 616e 732f 6661 6374 6f72 792f 616e6e6f 7461 7469 6f6e 2f41 7574 6f77 69726564 3b01 0006 3c69 6e69 743e 0100 03282956 0100 0443 6f64 6501 000f 4c69 6e654e75 6d62 6572 5461 626c 6501 0012 4c6f6361 6c56 6172 6961 626c 6554 6162 6c650100 0474 6869 7301 0038 4c63 6f6d 2f657861 6d70 6c65 2f73 7072 696e 6763 6c6f7564 2f70 726f 7669 6465 722f 6865 6c6c6f2f 4865 6c6c 6f43 6f6e 7472 6f6c 6c65723b 0100 0569 6e64 6578 0100 1428 294c6a61 7661 2f6c 616e 672f 5374 7269 6e673b01 0008 696e 7374 616e 6365 0100 324c6f72 672f 7370 7269 6e67 6672 616d 65776f72 6b2f 636c 6f75 642f 636c 6965 6e742f53 6572 7669 6365 496e 7374 616e 63653b01 0005 6865 6c6c 6f01 0012 4c6a 6176612f 6c61 6e67 2f53 7472 696e 673b 0100384c 6f72 672f 7370 7269 6e67 6672 616d6577 6f72 6b2f 7765 622f 6269 6e64 2f616e6e 6f74 6174 696f 6e2f 5265 7175 6573744d 6170 7069 6e67 3b01 0005 7661 6c756501 0001 2f01 0026 284c 6a61 7661 2f6c616e 672f 5374 7269 6e67 3b29 4c6a 6176612f 6c61 6e67 2f53 7472 696e 673b 0100046e 616d 6501 0006 2f68 656c 6c6f 01002252 756e 7469 6d65 5669 7369 626c 65506172 616d 6574 6572 416e 6e6f 7461 74696f6e 7301 0036 4c6f 7267 2f73 7072 696e6766 7261 6d65 776f 726b 2f77 6562 2f62696e 642f 616e 6e6f 7461 7469 6f6e 2f526571 7565 7374 5061 7261 6d3b 0100 083c636c 696e 6974 3e01 000a 536f 7572 63654669 6c65 0100 1448 656c 6c6f 436f 6e74726f 6c6c 6572 2e6a 6176 6101 0038 4c6f7267 2f73 7072 696e 6766 7261 6d65 776f726b 2f77 6562 2f62 696e 642f 616e 6e6f7461 7469 6f6e 2f52 6573 7443 6f6e 74726f6c 6c65 723b 0c00 1900 1a0c 0015 00160700 470c 0048 0049 0100 176a 6176 612f6c61 6e67 2f53 7472 696e 6742 7569 6c646572 0100 1368 656c 6c6f 2c73 7563 63657373 2168 6f73 743d 0c00 4a00 4b07 004c0c00 4d00 2101 000b 2c73 6572 7669 63654964 3d0c 004e 0021 0c00 4f00 210c 00130014 0700 500c 0051 0052 0100 0668 656c6c6f 2001 0017 efbc 8c74 6869 7320 69732066 6972 7374 206d 6573 7367 6501 0036636f 6d2f 6578 616d 706c 652f 7370 72696e67 636c 6f75 642f 7072 6f76 6964 65722f68 656c 6c6f 2f48 656c 6c6f 436f 6e74726f 6c6c 6572 0700 530c 0054 0055 0100106a 6176 612f 6c61 6e67 2f4f 626a 65637401 003a 6f72 672f 7370 7269 6e67 6672616d 6577 6f72 6b2f 636c 6f75 642f 636c6965 6e74 2f64 6973 636f 7665 7279 2f446973 636f 7665 7279 436c 6965 6e74 01001767 6574 4c6f 6361 6c53 6572 7669 6365496e 7374 616e 6365 0100 3428 294c 6f72672f 7370 7269 6e67 6672 616d 6577 6f726b2f 636c 6f75 642f 636c 6965 6e74 2f536572 7669 6365 496e 7374 616e 6365 3b010006 6170 7065 6e64 0100 2d28 4c6a 6176612f 6c61 6e67 2f53 7472 696e 673b 294c6a61 7661 2f6c 616e 672f 5374 7269 6e674275 696c 6465 723b 0100 306f 7267 2f737072 696e 6766 7261 6d65 776f 726b 2f636c6f 7564 2f63 6c69 656e 742f 5365 72766963 6549 6e73 7461 6e63 6501 0007 67657448 6f73 7401 000c 6765 7453 6572 76696365 4964 0100 0874 6f53 7472 696e 67010010 6f72 672f 736c 6634 6a2f 4c6f 67676572 0100 0469 6e66 6f01 0015 284c 6a617661 2f6c 616e 672f 5374 7269 6e67 3b295601 0017 6f72 672f 736c 6634 6a2f 4c6f6767 6572 4661 6374 6f72 7901 0009 6765744c 6f67 6765 7201 0025 284c 6a61 76612f6c 616e 672f 436c 6173 733b 294c 6f72672f 736c 6634 6a2f 4c6f 6767 6572 3b002100 1000 1200 0000 0200 1a00 1300 14000000 0200 1500 1600 0100 1700 0000 06000100 1800 0000 0400 0100 1900 1a00 01001b00 0000 2f00 0100 0100 0000 052a b70001b1 0000 0002 001c 0000 0006 0001 0000000d 001d 0000 000c 0001 0000 0005 001e001f 0000 0001 0020 0021 0002 001b 00000086 0002 0003 0000 003c 2ab4 0002 b9000301 004c bb00 0459 b700 0512 06b6 00072bb9 0008 0100 b600 0712 09b6 0007 2bb9000a 0100 b600 07b6 000b 4db2 000c 2cb9000d 0200 2cb0 0000 0002 001c 0000 00120004 0000 0016 000a 0017 0031 0018 003a0019 001d 0000 0020 0003 0000 003c 001e001f 0000 000a 0032 0022 0023 0001 0031000b 0024 0025 0002 0017 0000 000e 00010026 0001 0027 5b00 0173 0028 0001 00240029 0003 001b 0000 004d 0002 0002 00000019 bb00 0459 b700 0512 0eb6 0007 2bb60007 120f b600 07b6 000b b000 0000 02001c00 0000 0600 0100 0000 1f00 1d00 00001600 0200 0000 1900 1e00 1f00 0000 00001900 2a00 2500 0100 1700 0000 0e00 01002600 0100 275b 0001 7300 2b00 2c00 00000701 0001 002d 0000 0008 002e 001a 0001001b 0000 0021 0001 0000 0000 0009 1210b800 11b3 000c b100 0000 0100 1c00 00000600 0100 0000 0e00 0200 2f00 0000 02003000 1700 0000 0600 0100 3100 00
View Code

 

3.在cmd命令行里使用javap 工具反编译test.class文件为汇编(javap命令:主要用于根据Java字节码文件反汇编为Java源代码文件)

javap -v Test.class > Test.txt

 

➜  ~ java -versionjava version "1.8.0_144"Java(TM) SE Runtime Environment (build 1.8.0_144-b01)Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)➜  ~ ➜  ~ ➜  ~ cd /Users/shiwen/IdeaProjects/springcloud/example-springcloud-provider/target/classes/com/example/springcloud/provider/hello/                     ➜  hello git:(master) ✗ lltotal 8-rw-r--r--  1 shiwen  staff   1.9K 10 11 13:06 HelloController.class➜  hello git:(master) ✗ javap -v HelloController.classClassfile /Users/shiwen/IdeaProjects/springcloud/example-springcloud-provider/target/classes/com/example/springcloud/provider/hello/HelloController.class  Last modified 2017-10-11; size 1965 bytes  MD5 checksum b2b6778d4662b520c0b210239844a73a  Compiled from "HelloController.java"public class com.example.springcloud.provider.hello.HelloController  minor version: 0  major version: 52  flags: ACC_PUBLIC, ACC_SUPERConstant pool:   #1 = Methodref          #18.#50        // java/lang/Object."
":()V #2 = Fieldref #16.#51 // com/example/springcloud/provider/hello/HelloController.client:Lorg/springframework/cloud/client/discovery/DiscoveryClient; #3 = InterfaceMethodref #52.#53 // org/springframework/cloud/client/discovery/DiscoveryClient.getLocalServiceInstance:()Lorg/springframework/cloud/client/ServiceInstance; #4 = Class #54 // java/lang/StringBuilder #5 = Methodref #4.#50 // java/lang/StringBuilder."
":()V #6 = String #55 // hello,success!host= #7 = Methodref #4.#56 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; #8 = InterfaceMethodref #57.#58 // org/springframework/cloud/client/ServiceInstance.getHost:()Ljava/lang/String; #9 = String #59 // ,serviceId= #10 = InterfaceMethodref #57.#60 // org/springframework/cloud/client/ServiceInstance.getServiceId:()Ljava/lang/String; #11 = Methodref #4.#61 // java/lang/StringBuilder.toString:()Ljava/lang/String; #12 = Fieldref #16.#62 // com/example/springcloud/provider/hello/HelloController.logger:Lorg/slf4j/Logger; #13 = InterfaceMethodref #63.#64 // org/slf4j/Logger.info:(Ljava/lang/String;)V #14 = String #65 // hello #15 = String #66 // ,this is first messge #16 = Class #67 // com/example/springcloud/provider/hello/HelloController #17 = Methodref #68.#69 // org/slf4j/LoggerFactory.getLogger:(Ljava/lang/Class;)Lorg/slf4j/Logger; #18 = Class #70 // java/lang/Object #19 = Utf8 logger #20 = Utf8 Lorg/slf4j/Logger; #21 = Utf8 client #22 = Utf8 Lorg/springframework/cloud/client/discovery/DiscoveryClient; #23 = Utf8 RuntimeVisibleAnnotations #24 = Utf8 Lorg/springframework/beans/factory/annotation/Autowired; #25 = Utf8
#26 = Utf8 ()V #27 = Utf8 Code #28 = Utf8 LineNumberTable #29 = Utf8 LocalVariableTable #30 = Utf8 this #31 = Utf8 Lcom/example/springcloud/provider/hello/HelloController; #32 = Utf8 index #33 = Utf8 ()Ljava/lang/String; #34 = Utf8 instance #35 = Utf8 Lorg/springframework/cloud/client/ServiceInstance; #36 = Utf8 hello #37 = Utf8 Ljava/lang/String; #38 = Utf8 Lorg/springframework/web/bind/annotation/RequestMapping; #39 = Utf8 value #40 = Utf8 / #41 = Utf8 (Ljava/lang/String;)Ljava/lang/String; #42 = Utf8 name #43 = Utf8 /hello #44 = Utf8 RuntimeVisibleParameterAnnotations #45 = Utf8 Lorg/springframework/web/bind/annotation/RequestParam; #46 = Utf8
#47 = Utf8 SourceFile #48 = Utf8 HelloController.java #49 = Utf8 Lorg/springframework/web/bind/annotation/RestController; #50 = NameAndType #25:#26 // "
":()V #51 = NameAndType #21:#22 // client:Lorg/springframework/cloud/client/discovery/DiscoveryClient; #52 = Class #71 // org/springframework/cloud/client/discovery/DiscoveryClient #53 = NameAndType #72:#73 // getLocalServiceInstance:()Lorg/springframework/cloud/client/ServiceInstance; #54 = Utf8 java/lang/StringBuilder #55 = Utf8 hello,success!host= #56 = NameAndType #74:#75 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder; #57 = Class #76 // org/springframework/cloud/client/ServiceInstance #58 = NameAndType #77:#33 // getHost:()Ljava/lang/String; #59 = Utf8 ,serviceId= #60 = NameAndType #78:#33 // getServiceId:()Ljava/lang/String; #61 = NameAndType #79:#33 // toString:()Ljava/lang/String; #62 = NameAndType #19:#20 // logger:Lorg/slf4j/Logger; #63 = Class #80 // org/slf4j/Logger #64 = NameAndType #81:#82 // info:(Ljava/lang/String;)V #65 = Utf8 hello #66 = Utf8 ,this is first messge #67 = Utf8 com/example/springcloud/provider/hello/HelloController #68 = Class #83 // org/slf4j/LoggerFactory #69 = NameAndType #84:#85 // getLogger:(Ljava/lang/Class;)Lorg/slf4j/Logger; #70 = Utf8 java/lang/Object #71 = Utf8 org/springframework/cloud/client/discovery/DiscoveryClient #72 = Utf8 getLocalServiceInstance #73 = Utf8 ()Lorg/springframework/cloud/client/ServiceInstance; #74 = Utf8 append #75 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder; #76 = Utf8 org/springframework/cloud/client/ServiceInstance #77 = Utf8 getHost #78 = Utf8 getServiceId #79 = Utf8 toString #80 = Utf8 org/slf4j/Logger #81 = Utf8 info #82 = Utf8 (Ljava/lang/String;)V #83 = Utf8 org/slf4j/LoggerFactory #84 = Utf8 getLogger #85 = Utf8 (Ljava/lang/Class;)Lorg/slf4j/Logger;{ public com.example.springcloud.provider.hello.HelloController(); descriptor: ()V flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method java/lang/Object."
":()V 4: return LineNumberTable: line 13: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Lcom/example/springcloud/provider/hello/HelloController; public java.lang.String index(); descriptor: ()Ljava/lang/String; flags: ACC_PUBLIC Code: stack=2, locals=3, args_size=1 0: aload_0 1: getfield #2 // Field client:Lorg/springframework/cloud/client/discovery/DiscoveryClient; 4: invokeinterface #3, 1 // InterfaceMethod org/springframework/cloud/client/discovery/DiscoveryClient.getLocalServiceInstance:()Lorg/springframework/cloud/client/ServiceInstance; 9: astore_1 10: new #4 // class java/lang/StringBuilder 13: dup 14: invokespecial #5 // Method java/lang/StringBuilder."
":()V 17: ldc #6 // String hello,success!host= 19: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 22: aload_1 23: invokeinterface #8, 1 // InterfaceMethod org/springframework/cloud/client/ServiceInstance.getHost:()Ljava/lang/String; 28: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 31: ldc #9 // String ,serviceId= 33: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 36: aload_1 37: invokeinterface #10, 1 // InterfaceMethod org/springframework/cloud/client/ServiceInstance.getServiceId:()Ljava/lang/String; 42: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 45: invokevirtual #11 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 48: astore_2 49: getstatic #12 // Field logger:Lorg/slf4j/Logger; 52: aload_2 53: invokeinterface #13, 2 // InterfaceMethod org/slf4j/Logger.info:(Ljava/lang/String;)V 58: aload_2 59: areturn LineNumberTable: line 22: 0 line 23: 10 line 24: 49 line 25: 58 LocalVariableTable: Start Length Slot Name Signature 0 60 0 this Lcom/example/springcloud/provider/hello/HelloController; 10 50 1 instance Lorg/springframework/cloud/client/ServiceInstance; 49 11 2 hello Ljava/lang/String; RuntimeVisibleAnnotations: 0: #38(#39=[s#40]) public java.lang.String hello(java.lang.String); descriptor: (Ljava/lang/String;)Ljava/lang/String; flags: ACC_PUBLIC Code: stack=2, locals=2, args_size=2 0: new #4 // class java/lang/StringBuilder 3: dup 4: invokespecial #5 // Method java/lang/StringBuilder."
":()V 7: ldc #14 // String hello 9: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 12: aload_1 13: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 16: ldc #15 // String ,this is first messge 18: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 21: invokevirtual #11 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 24: areturn LineNumberTable: line 31: 0 LocalVariableTable: Start Length Slot Name Signature 0 25 0 this Lcom/example/springcloud/provider/hello/HelloController; 0 25 1 name Ljava/lang/String; RuntimeVisibleAnnotations: 0: #38(#39=[s#43]) RuntimeVisibleParameterAnnotations: parameter 0: 0: #45() static {}; descriptor: ()V flags: ACC_STATIC Code: stack=1, locals=0, args_size=0 0: ldc #16 // class com/example/springcloud/provider/hello/HelloController 2: invokestatic #17 // Method org/slf4j/LoggerFactory.getLogger:(Ljava/lang/Class;)Lorg/slf4j/Logger; 5: putstatic #12 // Field logger:Lorg/slf4j/Logger; 8: return LineNumberTable: line 14: 0}SourceFile: "HelloController.java"RuntimeVisibleAnnotations: 0: #49()
View Code

 

转载于:https://www.cnblogs.com/zhangshiwen/p/7650120.html

你可能感兴趣的文章
ALGEBRA-3 线性映射
查看>>
C# 利用ReportViewer生成报表
查看>>
下拉菜单
查看>>
knockout.js 练习一
查看>>
Asp.Net Core SignalR 与微信小程序交互笔记
查看>>
os.linesep提取当前平台使用的换行符
查看>>
到底什么是故事点(Story Point)?
查看>>
修改用户定义的数据类型
查看>>
网络流24题10
查看>>
多域名THINKPHP利用MEMCACHE方式共享SESSION数据(转)
查看>>
C#基础 for 穷举、迭代
查看>>
2018.3.17 模拟赛——(2)删数
查看>>
视图层
查看>>
Django跨域解决方法
查看>>
冒泡排序
查看>>
Mysql字段合并
查看>>
五笔反查工具
查看>>
python 类的继承
查看>>
python 爬取<a>标签内href的方法及遇到的问题
查看>>
.Net 环境下比较各种数据库插入操作的性能
查看>>