zwhc 发表于 2013-1-29 23:02:29

发布新程序:java 字节码查看器

本程序用于显示 java class 文件的结构。
1、程序先以 UE 十六进制编辑模式的显示方式显示 class 文件。
2、然后,显示各个字节对应的含义。

如,
code:03 3C 84 01 01 B1
iconst_0
istore_1
iinc
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    ; ...............

CAFEBABE
read magic number
0000
read minor version 0
0031
read major version 49
0016
read constant pool count 22
reading constant pool entry 1
07
0002
read CONSTANT_Class_info with name_index 2
reading constant pool entry 2
01
read CONSTANT_Utf8_info with length 10 ("test/BC_pp")
reading constant pool entry 3
07
0004
read CONSTANT_Class_info with name_index 4
reading constant pool entry 4
01
read CONSTANT_Utf8_info with length 16 ("java/lang/Object")
reading constant pool entry 5
01
read CONSTANT_Utf8_info with length 6 ("<init>")
reading constant pool entry 6
01
read CONSTANT_Utf8_info with length 3 ("()V")
reading constant pool entry 7
01
read CONSTANT_Utf8_info with length 4 ("Code")
reading constant pool entry 8
0A
read CONSTANT_Methodref_info with class_index 3 and name_and_type_index
9
reading constant pool entry 9
0C
read CONSTANT_NameAndType_info with name_index 5 and descriptor_index 6
reading constant pool entry 10
01
read CONSTANT_Utf8_info with length 15 ("LineNumberTable")
reading constant pool entry 11
01
read CONSTANT_Utf8_info with length 18 ("LocalVariableTable")
reading constant pool entry 12
01
read CONSTANT_Utf8_info with length 4 ("this")
reading constant pool entry 13
01
read CONSTANT_Utf8_info with length 12 ("Ltest/BC_pp;")
reading constant pool entry 14
01
read CONSTANT_Utf8_info with length 4 ("main")
reading constant pool entry 15
01
read CONSTANT_Utf8_info with length 22 ("([Ljava/lang/String;)V")
reading constant pool entry 16
01
read CONSTANT_Utf8_info with length 4 ("args")
reading constant pool entry 17
01
read CONSTANT_Utf8_info with length 19 ("[Ljava/lang/String;")
reading constant pool entry 18
01
read CONSTANT_Utf8_info with length 1 ("i")
reading constant pool entry 19
01
read CONSTANT_Utf8_info with length 1 ("I")
reading constant pool entry 20
01
read CONSTANT_Utf8_info with length 10 ("SourceFile")
reading constant pool entry 21
01
read CONSTANT_Utf8_info with length 10 ("BC_pp.java")
read access flags 0x0021
read this_class index 1
read super_class index 3
read interfaces count 0
read fields count 0
0002
read methods count 2
0001 0005 0006
0001
attributeNameIndex:0007
attributeLength:0000002F
attributeName:Code
0001 0001 00000005
bb.length:5
code:2A B7 00 08 B1
aload_0
invokespecial
return
0002
attributeNameIndex:000A
attributeLength:00000006
attributeName:LineNumberTable
read LineNumberTable entry with start_pc 0, line_number 3
read LineNumberTable attribute with 1 entries
attributeNameIndex:000B
attributeLength:0000000C
attributeName:LocalVariableTable
bb.length:0
info:
read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
read LocalVariableTable entry with start_pc 0, length 5, name_index 12,
descriptor_index 13, index 0
read LocalVariableTable attribute with 1 entries
read Code attribute with max_stack 1, max_locals 1, code_length 5
read method with access flags 0x0001, name_index 5, descriptor_index 6,
1 attributes
0009 000E 000F
0001
attributeNameIndex:0007
attributeLength:00000042
attributeName:Code
0001 0002 00000006
bb.length:6
code:03 3C 84 01 01 B1
iconst_0
istore_1
iinc
return
0002
attributeNameIndex:000A
attributeLength:0000000E
attributeName:LineNumberTable
read LineNumberTable entry with start_pc 0, line_number 6
read LineNumberTable entry with start_pc 2, line_number 7
read LineNumberTable entry with start_pc 5, line_number 8
read LineNumberTable attribute with 3 entries
attributeNameIndex:000B
attributeLength:00000016
attributeName:LocalVariableTable
bb.length:0
info:
read uninterpreted attribute of reported type LocalVariableTableLocalVar
iableTable attribute with 0 entries
read LocalVariableTable entry with start_pc 0, length 6, name_index 16,
descriptor_index 17, index 0
read LocalVariableTable entry with start_pc 2, length 4, name_index 18,
descriptor_index 19, index 1
read LocalVariableTable attribute with 2 entries
read Code attribute with max_stack 1, max_locals 2, code_length 6
read method with access flags 0x0009, name_index 14, descriptor_index 15
, 1 attributes
0001
attributeNameIndex:0014
attributeLength:00000002
attributeName:SourceFile
read SourceFile attribute with sourcefile_index 21
read 1 attributes for the ClassFile structure
页: [1]
查看完整版本: 发布新程序:java 字节码查看器