1.首先拿到javac文件 例如:test.class
2.可以使用文本编辑器用二进制的方式打开()
cafe babe 0000 0034 0056 0a00 1200 3209 0010 0033 0b00 3400 3507 0036 0a00 0400 3208 0037 0a00 0400 380b 0039 003a 0800 3b0b 0039 003c 0a00 0400 3d09 0010 003e 0b00 3f00 4008 0041 0800 4207 0043 0a00 4400 4507 0046 0100 066c 6f67 6765 7201 0012 4c6f 7267 2f73 6c66 346a 2f4c 6f67 6765 723b 0100 0663 6c69 656e 7401 003c 4c6f 7267 2f73 7072 696e 6766 7261 6d65 776f 726b 2f63 6c6f 7564 2f63 6c69 656e 742f 6469 7363 6f76 6572 792f 4469 7363 6f76 6572 7943 6c69 656e 743b 0100 1952 756e 7469 6d65 5669 7369 626c 6541 6e6e 6f74 6174 696f 6e73 0100 384c 6f72 672f 7370 7269 6e67 6672 616d 6577 6f72 6b2f 6265 616e 732f 6661 6374 6f72 792f 616e 6e6f 7461 7469 6f6e 2f41 7574 6f77 6972 6564 3b01 0006 3c69 6e69 743e 0100 0328 2956 0100 0443 6f64 6501 000f 4c69 6e65 4e75 6d62 6572 5461 626c 6501 0012 4c6f 6361 6c56 6172 6961 626c 6554 6162 6c65 0100 0474 6869 7301 0038 4c63 6f6d 2f65 7861 6d70 6c65 2f73 7072 696e 6763 6c6f 7564 2f70 726f 7669 6465 722f 6865 6c6c 6f2f 4865 6c6c 6f43 6f6e 7472 6f6c 6c65 723b 0100 0569 6e64 6578 0100 1428 294c 6a61 7661 2f6c 616e 672f 5374 7269 6e67 3b01 0008 696e 7374 616e 6365 0100 324c 6f72 672f 7370 7269 6e67 6672 616d 6577 6f72 6b2f 636c 6f75 642f 636c 6965 6e74 2f53 6572 7669 6365 496e 7374 616e 6365 3b01 0005 6865 6c6c 6f01 0012 4c6a 6176 612f 6c61 6e67 2f53 7472 696e 673b 0100 384c 6f72 672f 7370 7269 6e67 6672 616d 6577 6f72 6b2f 7765 622f 6269 6e64 2f61 6e6e 6f74 6174 696f 6e2f 5265 7175 6573 744d 6170 7069 6e67 3b01 0005 7661 6c75 6501 0001 2f01 0026 284c 6a61 7661 2f6c 616e 672f 5374 7269 6e67 3b29 4c6a 6176 612f 6c61 6e67 2f53 7472 696e 673b 0100 046e 616d 6501 0006 2f68 656c 6c6f 0100 2252 756e 7469 6d65 5669 7369 626c 6550 6172 616d 6574 6572 416e 6e6f 7461 7469 6f6e 7301 0036 4c6f 7267 2f73 7072 696e 6766 7261 6d65 776f 726b 2f77 6562 2f62 696e 642f 616e 6e6f 7461 7469 6f6e 2f52 6571 7565 7374 5061 7261 6d3b 0100 083c 636c 696e 6974 3e01 000a 536f 7572 6365 4669 6c65 0100 1448 656c 6c6f 436f 6e74 726f 6c6c 6572 2e6a 6176 6101 0038 4c6f 7267 2f73 7072 696e 6766 7261 6d65 776f 726b 2f77 6562 2f62 696e 642f 616e 6e6f 7461 7469 6f6e 2f52 6573 7443 6f6e 7472 6f6c 6c65 723b 0c00 1900 1a0c 0015 0016 0700 470c 0048 0049 0100 176a 6176 612f 6c61 6e67 2f53 7472 696e 6742 7569 6c64 6572 0100 1368 656c 6c6f 2c73 7563 6365 7373 2168 6f73 743d 0c00 4a00 4b07 004c 0c00 4d00 2101 000b 2c73 6572 7669 6365 4964 3d0c 004e 0021 0c00 4f00 210c 0013 0014 0700 500c 0051 0052 0100 0668 656c 6c6f 2001 0017 efbc 8c74 6869 7320 6973 2066 6972 7374 206d 6573 7367 6501 0036 636f 6d2f 6578 616d 706c 652f 7370 7269 6e67 636c 6f75 642f 7072 6f76 6964 6572 2f68 656c 6c6f 2f48 656c 6c6f 436f 6e74 726f 6c6c 6572 0700 530c 0054 0055 0100 106a 6176 612f 6c61 6e67 2f4f 626a 6563 7401 003a 6f72 672f 7370 7269 6e67 6672 616d 6577 6f72 6b2f 636c 6f75 642f 636c 6965 6e74 2f64 6973 636f 7665 7279 2f44 6973 636f 7665 7279 436c 6965 6e74 0100 1767 6574 4c6f 6361 6c53 6572 7669 6365 496e 7374 616e 6365 0100 3428 294c 6f72 672f 7370 7269 6e67 6672 616d 6577 6f72 6b2f 636c 6f75 642f 636c 6965 6e74 2f53 6572 7669 6365 496e 7374 616e 6365 3b01 0006 6170 7065 6e64 0100 2d28 4c6a 6176 612f 6c61 6e67 2f53 7472 696e 673b 294c 6a61 7661 2f6c 616e 672f 5374 7269 6e67 4275 696c 6465 723b 0100 306f 7267 2f73 7072 696e 6766 7261 6d65 776f 726b 2f63 6c6f 7564 2f63 6c69 656e 742f 5365 7276 6963 6549 6e73 7461 6e63 6501 0007 6765 7448 6f73 7401 000c 6765 7453 6572 7669 6365 4964 0100 0874 6f53 7472 696e 6701 0010 6f72 672f 736c 6634 6a2f 4c6f 6767 6572 0100 0469 6e66 6f01 0015 284c 6a61 7661 2f6c 616e 672f 5374 7269 6e67 3b29 5601 0017 6f72 672f 736c 6634 6a2f 4c6f 6767 6572 4661 6374 6f72 7901 0009 6765 744c 6f67 6765 7201 0025 284c 6a61 7661 2f6c 616e 672f 436c 6173 733b 294c 6f72 672f 736c 6634 6a2f 4c6f 6767 6572 3b00 2100 1000 1200 0000 0200 1a00 1300 1400 0000 0200 1500 1600 0100 1700 0000 0600 0100 1800 0000 0400 0100 1900 1a00 0100 1b00 0000 2f00 0100 0100 0000 052a b700 01b1 0000 0002 001c 0000 0006 0001 0000 000d 001d 0000 000c 0001 0000 0005 001e 001f 0000 0001 0020 0021 0002 001b 0000 0086 0002 0003 0000 003c 2ab4 0002 b900 0301 004c bb00 0459 b700 0512 06b6 0007 2bb9 0008 0100 b600 0712 09b6 0007 2bb9 000a 0100 b600 07b6 000b 4db2 000c 2cb9 000d 0200 2cb0 0000 0002 001c 0000 0012 0004 0000 0016 000a 0017 0031 0018 003a 0019 001d 0000 0020 0003 0000 003c 001e 001f 0000 000a 0032 0022 0023 0001 0031 000b 0024 0025 0002 0017 0000 000e 0001 0026 0001 0027 5b00 0173 0028 0001 0024 0029 0003 001b 0000 004d 0002 0002 0000 0019 bb00 0459 b700 0512 0eb6 0007 2bb6 0007 120f b600 07b6 000b b000 0000 0200 1c00 0000 0600 0100 0000 1f00 1d00 0000 1600 0200 0000 1900 1e00 1f00 0000 0000 1900 2a00 2500 0100 1700 0000 0e00 0100 2600 0100 275b 0001 7300 2b00 2c00 0000 0701 0001 002d 0000 0008 002e 001a 0001 001b 0000 0021 0001 0000 0000 0009 1210 b800 11b3 000c b100 0000 0100 1c00 0000 0600 0100 0000 0e00 0200 2f00 0000 0200 3000 1700 0000 0600 0100 3100 00
3.在cmd命令行里使用javap 工具反编译test.class文件为汇编(javap命令:主要用于根据Java字节码文件反汇编为Java源代码文件)
javap -v Test.class > Test.txt
➜ ~ java -version java 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) ✗ ll total 8 -rw-r--r-- 1 shiwen staff 1.9K 10 11 13:06 HelloController.class ➜ hello git:(master) ✗ javap -v HelloController.class Classfile /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_SUPER Constant pool: #1 = Methodref #18.#50 // java/lang/Object."<init>":()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."<init>":()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 <init> #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 <clinit> #47 = Utf8 SourceFile #48 = Utf8 HelloController.java #49 = Utf8 Lorg/springframework/web/bind/annotation/RestController; #50 = NameAndType #25:#26 // "<init>":()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."<init>":()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."<init>":()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."<init>":()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()