本程序用于显示 java class 文件的结构。
1、程序先以 UE 十六进制编辑模式的显示方式显示 class 文件。
2、然后,显示各个字节对应的含义。
如,
[debug] code:03 3C 84 01 01 B1
[debug] iconst_0
[debug] istore_1
[debug] iinc
[debug] return
第一行表示程序代码的字节码,以后四行,是这些字节码对应的指令。
------------------------------------------------------
本程序改自 jclasslib_windows_3_0。
------------------------------------------------------
你可以通过如下方式使用 :
java -cp "./bin" -Djclasslib.io.debug=true org.gjt.jclasslib.io.ClassFileReader BC_pp.class
运行后,你可以看到如下信息:
00000000h: CA FE BA BE 00 00 00 31 00 16 07 00 02 01 00 0A ; .......1........
00000010h: 74 65 73 74 2F 42 43 5F 70 70 07 00 04 01 00 10 ; test/BC_pp......
00000020h: 6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 ; java/lang/Object
00000030h: 01 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56 01 ; ...<init>...()V.
00000040h: 00 04 43 6F 64 65 0A 00 03 00 09 0C 00 05 00 06 ; ..Code..........
00000050h: 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 61 62 ; ...LineNumberTab
00000060h: 6C 65 01 00 12 4C 6F 63 61 6C 56 61 72 69 61 62 ; le...LocalVariab
00000070h: 6C 65 54 61 62 6C 65 01 00 04 74 68 69 73 01 00 ; leTable...this..
00000080h: 0C 4C 74 65 73 74 2F 42 43 5F 70 70 3B 01 00 04 ; .Ltest/BC_pp;...
00000090h: 6D 61 69 6E 01 00 16 28 5B 4C 6A 61 76 61 2F 6C ; main...([Ljava/l
000000A0h: 61 6E 67 2F 53 74 72 69 6E 67 3B 29 56 01 00 04 ; ang/String;)V...
000000B0h: 61 72 67 73 01 00 13 5B 4C 6A 61 76 61 2F 6C 61 ; args...[Ljava/la
000000C0h: 6E 67 2F 53 74 72 69 6E 67 3B 01 00 01 69 01 00 ; ng/String;...i..
000000D0h: 01 49 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 ; .I...SourceFile.
000000E0h: 00 0A 42 43 5F 70 70 2E 6A 61 76 61 00 21 00 01 ; ..BC_pp.java.!..
000000F0h: 00 03 00 00 00 00 00 02 00 01 00 05 00 06 00 01 ; ................
00000100h: 00 07 00 00 00 2F 00 01 00 01 00 00 00 05 2A B7 ; ...../........*.
00000110h: 00 08 B1 00 00 00 02 00 0A 00 00 00 06 00 01 00 ; ................
00000120h: 00 00 03 00 0B 00 00 00 0C 00 01 00 00 00 05 00 ; ................
00000130h: 0C 00 0D 00 00 00 09 00 0E 00 0F 00 01 00 07 00 ; ................
00000140h: 00 00 42 00 01 00 02 00 00 00 06 03 3C 84 01 01 ; ..B.........<...
00000150h: B1 00 00 00 02 00 0A 00 00 00 0E 00 03 00 00 00 ; ................
00000160h: 06 00 02 00 07 00 05 00 08 00 0B 00 00 00 16 00 ; ................
00000170h: 02 00 00 00 06 00 10 00 11 00 00 00 02 00 04 00 ; ................
00000180h: 12 00 13 00 01 00 01 00 14 00 00 00 02 00 15 ; ...............
[debug] CAFEBABE
[debug] read magic number
[debug] 0000
[debug] read minor version 0
[debug] 0031
[debug] read major version 49
[debug] 0016
[debug] read constant pool count 22
[debug] reading constant pool entry 1
[debug] 07
[debug] 0002
[debug] read CONSTANT_Class_info with name_index 2
[debug] reading constant pool entry 2
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("test/BC_pp")
[debug] reading constant pool entry 3
[debug] 07
[debug] 0004
[debug] read CONSTANT_Class_info with name_index 4
[debug] reading constant pool entry 4
[debug] 01
[debug] read CONSTANT_Utf8_info with length 16 ("java/lang/Object")
[debug] reading constant pool entry 5
[debug] 01
[debug] read CONSTANT_Utf8_info with length 6 ("<init>")
[debug] reading constant pool entry 6
[debug] 01
[debug] read CONSTANT_Utf8_info with length 3 ("()V")
[debug] reading constant pool entry 7
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("Code")
[debug] reading constant pool entry 8
[debug] 0A
[debug] read CONSTANT_Methodref_info with class_index 3 and name_and_type_index
9
[debug] reading constant pool entry 9
[debug] 0C
[debug] read CONSTANT_NameAndType_info with name_index 5 and descriptor_index 6
[debug] reading constant pool entry 10
[debug] 01
[debug] read CONSTANT_Utf8_info with length 15 ("LineNumberTable")
[debug] reading constant pool entry 11
[debug] 01
[debug] read CONSTANT_Utf8_info with length 18 ("LocalVariableTable")
[debug] reading constant pool entry 12
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("this")
[debug] reading constant pool entry 13
[debug] 01
[debug] read CONSTANT_Utf8_info with length 12 ("Ltest/BC_pp;")
[debug] reading constant pool entry 14
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("main")
[debug] reading constant pool entry 15
[debug] 01
[debug] read CONSTANT_Utf8_info with length 22 ("([Ljava/lang/String;)V")
[debug] reading constant pool entry 16
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("args")
[debug] reading constant pool entry 17
[debug] 01
[debug] read CONSTANT_Utf8_info with length 19 ("[Ljava/lang/String;")
[debug] reading constant pool entry 18
[debug] 01
[debug] read CONSTANT_Utf8_info with length 1 ("i")
[debug] reading constant pool entry 19
[debug] 01
[debug] read CONSTANT_Utf8_info with length 1 ("I")
[debug] reading constant pool entry 20
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("SourceFile")
[debug] reading constant pool entry 21
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("BC_pp.java")
[debug] read access flags 0x0021
[debug] read this_class index 1
[debug] read super_class index 3
[debug] read interfaces count 0
[debug] read fields count 0
[debug] 0002
[debug] read methods count 2
[debug] 0001 0005 0006
[debug] 0001
[debug] attributeNameIndex:0007
[debug] attributeLength:0000002F
[debug] attributeName:Code
[debug] 0001 0001 00000005
bb.length:5
[debug] code:2A B7 00 08 B1
[debug] aload_0
[debug] invokespecial
[debug] return
[debug] 0002
[debug] attributeNameIndex:000A
[debug] attributeLength:00000006
[debug] attributeName:LineNumberTable
[debug] read LineNumberTable entry with start_pc 0, line_number 3
[debug] read LineNumberTable attribute with 1 entries
[debug] attributeNameIndex:000B
[debug] attributeLength:0000000C
[debug] attributeName:LocalVariableTable
bb.length:0
[debug] info:
[debug] read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
[debug] read LocalVariableTable entry with start_pc 0, length 5, name_index 12,
descriptor_index 13, index 0
[debug] read LocalVariableTable attribute with 1 entries
[debug] read Code attribute with max_stack 1, max_locals 1, code_length 5
[debug] read method with access flags 0x0001, name_index 5, descriptor_index 6,
1 attributes
[debug] 0009 000E 000F
[debug] 0001
[debug] attributeNameIndex:0007
[debug] attributeLength:00000042
[debug] attributeName:Code
[debug] 0001 0002 00000006
bb.length:6
[debug] code:03 3C 84 01 01 B1
[debug] iconst_0
[debug] istore_1
[debug] iinc
[debug] return
[debug] 0002
[debug] attributeNameIndex:000A
[debug] attributeLength:0000000E
[debug] attributeName:LineNumberTable
[debug] read LineNumberTable entry with start_pc 0, line_number 6
[debug] read LineNumberTable entry with start_pc 2, line_number 7
[debug] read LineNumberTable entry with start_pc 5, line_number 8
[debug] read LineNumberTable attribute with 3 entries
[debug] attributeNameIndex:000B
[debug] attributeLength:00000016
[debug] attributeName:LocalVariableTable
bb.length:0
[debug] info:
[debug] read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
[debug] read LocalVariableTable entry with start_pc 0, length 6, name_index 16,
descriptor_index 17, index 0
[debug] read LocalVariableTable entry with start_pc 2, length 4, name_index 18,
descriptor_index 19, index 1
[debug] read LocalVariableTable attribute with 2 entries
[debug] read Code attribute with max_stack 1, max_locals 2, code_length 6
[debug] read method with access flags 0x0009, name_index 14, descriptor_index 15
, 1 attributes
[debug] 0001
[debug] attributeNameIndex:0014
[debug] attributeLength:00000002
[debug] attributeName:SourceFile
[debug] read SourceFile attribute with sourcefile_index 21
[debug] read 1 attributes for the ClassFile structure
1、程序先以 UE 十六进制编辑模式的显示方式显示 class 文件。
2、然后,显示各个字节对应的含义。
如,
[debug] code:03 3C 84 01 01 B1
[debug] iconst_0
[debug] istore_1
[debug] iinc
[debug] return
第一行表示程序代码的字节码,以后四行,是这些字节码对应的指令。
------------------------------------------------------
本程序改自 jclasslib_windows_3_0。
------------------------------------------------------
你可以通过如下方式使用 :
java -cp "./bin" -Djclasslib.io.debug=true org.gjt.jclasslib.io.ClassFileReader BC_pp.class
运行后,你可以看到如下信息:
00000000h: CA FE BA BE 00 00 00 31 00 16 07 00 02 01 00 0A ; .......1........
00000010h: 74 65 73 74 2F 42 43 5F 70 70 07 00 04 01 00 10 ; test/BC_pp......
00000020h: 6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 ; java/lang/Object
00000030h: 01 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56 01 ; ...<init>...()V.
00000040h: 00 04 43 6F 64 65 0A 00 03 00 09 0C 00 05 00 06 ; ..Code..........
00000050h: 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 61 62 ; ...LineNumberTab
00000060h: 6C 65 01 00 12 4C 6F 63 61 6C 56 61 72 69 61 62 ; le...LocalVariab
00000070h: 6C 65 54 61 62 6C 65 01 00 04 74 68 69 73 01 00 ; leTable...this..
00000080h: 0C 4C 74 65 73 74 2F 42 43 5F 70 70 3B 01 00 04 ; .Ltest/BC_pp;...
00000090h: 6D 61 69 6E 01 00 16 28 5B 4C 6A 61 76 61 2F 6C ; main...([Ljava/l
000000A0h: 61 6E 67 2F 53 74 72 69 6E 67 3B 29 56 01 00 04 ; ang/String;)V...
000000B0h: 61 72 67 73 01 00 13 5B 4C 6A 61 76 61 2F 6C 61 ; args...[Ljava/la
000000C0h: 6E 67 2F 53 74 72 69 6E 67 3B 01 00 01 69 01 00 ; ng/String;...i..
000000D0h: 01 49 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 ; .I...SourceFile.
000000E0h: 00 0A 42 43 5F 70 70 2E 6A 61 76 61 00 21 00 01 ; ..BC_pp.java.!..
000000F0h: 00 03 00 00 00 00 00 02 00 01 00 05 00 06 00 01 ; ................
00000100h: 00 07 00 00 00 2F 00 01 00 01 00 00 00 05 2A B7 ; ...../........*.
00000110h: 00 08 B1 00 00 00 02 00 0A 00 00 00 06 00 01 00 ; ................
00000120h: 00 00 03 00 0B 00 00 00 0C 00 01 00 00 00 05 00 ; ................
00000130h: 0C 00 0D 00 00 00 09 00 0E 00 0F 00 01 00 07 00 ; ................
00000140h: 00 00 42 00 01 00 02 00 00 00 06 03 3C 84 01 01 ; ..B.........<...
00000150h: B1 00 00 00 02 00 0A 00 00 00 0E 00 03 00 00 00 ; ................
00000160h: 06 00 02 00 07 00 05 00 08 00 0B 00 00 00 16 00 ; ................
00000170h: 02 00 00 00 06 00 10 00 11 00 00 00 02 00 04 00 ; ................
00000180h: 12 00 13 00 01 00 01 00 14 00 00 00 02 00 15 ; ...............
[debug] CAFEBABE
[debug] read magic number
[debug] 0000
[debug] read minor version 0
[debug] 0031
[debug] read major version 49
[debug] 0016
[debug] read constant pool count 22
[debug] reading constant pool entry 1
[debug] 07
[debug] 0002
[debug] read CONSTANT_Class_info with name_index 2
[debug] reading constant pool entry 2
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("test/BC_pp")
[debug] reading constant pool entry 3
[debug] 07
[debug] 0004
[debug] read CONSTANT_Class_info with name_index 4
[debug] reading constant pool entry 4
[debug] 01
[debug] read CONSTANT_Utf8_info with length 16 ("java/lang/Object")
[debug] reading constant pool entry 5
[debug] 01
[debug] read CONSTANT_Utf8_info with length 6 ("<init>")
[debug] reading constant pool entry 6
[debug] 01
[debug] read CONSTANT_Utf8_info with length 3 ("()V")
[debug] reading constant pool entry 7
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("Code")
[debug] reading constant pool entry 8
[debug] 0A
[debug] read CONSTANT_Methodref_info with class_index 3 and name_and_type_index
9
[debug] reading constant pool entry 9
[debug] 0C
[debug] read CONSTANT_NameAndType_info with name_index 5 and descriptor_index 6
[debug] reading constant pool entry 10
[debug] 01
[debug] read CONSTANT_Utf8_info with length 15 ("LineNumberTable")
[debug] reading constant pool entry 11
[debug] 01
[debug] read CONSTANT_Utf8_info with length 18 ("LocalVariableTable")
[debug] reading constant pool entry 12
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("this")
[debug] reading constant pool entry 13
[debug] 01
[debug] read CONSTANT_Utf8_info with length 12 ("Ltest/BC_pp;")
[debug] reading constant pool entry 14
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("main")
[debug] reading constant pool entry 15
[debug] 01
[debug] read CONSTANT_Utf8_info with length 22 ("([Ljava/lang/String;)V")
[debug] reading constant pool entry 16
[debug] 01
[debug] read CONSTANT_Utf8_info with length 4 ("args")
[debug] reading constant pool entry 17
[debug] 01
[debug] read CONSTANT_Utf8_info with length 19 ("[Ljava/lang/String;")
[debug] reading constant pool entry 18
[debug] 01
[debug] read CONSTANT_Utf8_info with length 1 ("i")
[debug] reading constant pool entry 19
[debug] 01
[debug] read CONSTANT_Utf8_info with length 1 ("I")
[debug] reading constant pool entry 20
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("SourceFile")
[debug] reading constant pool entry 21
[debug] 01
[debug] read CONSTANT_Utf8_info with length 10 ("BC_pp.java")
[debug] read access flags 0x0021
[debug] read this_class index 1
[debug] read super_class index 3
[debug] read interfaces count 0
[debug] read fields count 0
[debug] 0002
[debug] read methods count 2
[debug] 0001 0005 0006
[debug] 0001
[debug] attributeNameIndex:0007
[debug] attributeLength:0000002F
[debug] attributeName:Code
[debug] 0001 0001 00000005
bb.length:5
[debug] code:2A B7 00 08 B1
[debug] aload_0
[debug] invokespecial
[debug] return
[debug] 0002
[debug] attributeNameIndex:000A
[debug] attributeLength:00000006
[debug] attributeName:LineNumberTable
[debug] read LineNumberTable entry with start_pc 0, line_number 3
[debug] read LineNumberTable attribute with 1 entries
[debug] attributeNameIndex:000B
[debug] attributeLength:0000000C
[debug] attributeName:LocalVariableTable
bb.length:0
[debug] info:
[debug] read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
[debug] read LocalVariableTable entry with start_pc 0, length 5, name_index 12,
descriptor_index 13, index 0
[debug] read LocalVariableTable attribute with 1 entries
[debug] read Code attribute with max_stack 1, max_locals 1, code_length 5
[debug] read method with access flags 0x0001, name_index 5, descriptor_index 6,
1 attributes
[debug] 0009 000E 000F
[debug] 0001
[debug] attributeNameIndex:0007
[debug] attributeLength:00000042
[debug] attributeName:Code
[debug] 0001 0002 00000006
bb.length:6
[debug] code:03 3C 84 01 01 B1
[debug] iconst_0
[debug] istore_1
[debug] iinc
[debug] return
[debug] 0002
[debug] attributeNameIndex:000A
[debug] attributeLength:0000000E
[debug] attributeName:LineNumberTable
[debug] read LineNumberTable entry with start_pc 0, line_number 6
[debug] read LineNumberTable entry with start_pc 2, line_number 7
[debug] read LineNumberTable entry with start_pc 5, line_number 8
[debug] read LineNumberTable attribute with 3 entries
[debug] attributeNameIndex:000B
[debug] attributeLength:00000016
[debug] attributeName:LocalVariableTable
bb.length:0
[debug] info:
[debug] read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
[debug] read LocalVariableTable entry with start_pc 0, length 6, name_index 16,
descriptor_index 17, index 0
[debug] read LocalVariableTable entry with start_pc 2, length 4, name_index 18,
descriptor_index 19, index 1
[debug] read LocalVariableTable attribute with 2 entries
[debug] read Code attribute with max_stack 1, max_locals 2, code_length 6
[debug] read method with access flags 0x0009, name_index 14, descriptor_index 15
, 1 attributes
[debug] 0001
[debug] attributeNameIndex:0014
[debug] attributeLength:00000002
[debug] attributeName:SourceFile
[debug] read SourceFile attribute with sourcefile_index 21
[debug] read 1 attributes for the ClassFile structure