進制轉換
這個是必須要會的,會一點點就行,就是什麼逢2進1,逢16進1。不難,不過解析的時候要注意都是16進制,看到10之類的,并不是10而是16
大小端轉換
大小端百度百科解釋:
大端模式,是指資料的高位元組儲存在記憶體的低位址中,而資料的低位元組儲存在記憶體的高位址中,這樣的存儲模式有點兒類似于把資料當作字元串順序處理:位址由小向大增加,而資料從高位往低位放;這和我們的閱讀習慣一緻。
小端模式,是指資料的高位元組儲存在記憶體的高位址中,而資料的低位元組儲存在記憶體的低位址中,這種存儲模式将位址的高低和資料位權有效地結合起來,高位址部分權值高,低位址部分權值低。
個人解釋:大小端其實就是兩種存儲方式,我們java預設是大端存儲的,而有一些單片機還有計算機都是小端存儲的,而如果我們要做物聯網,那麼硬體工程師銅火鍋網絡傳輸過來的資料是小端存儲的,那麼你用大端讀出來的資料肯定是不對的嘛,因為大小端是相反的。是以我們肯定是需要轉換一下。轉換方法百度一大堆,就不貼了。
圖檔解釋:0x11223344:這是16進制,11是高位,不是數字大是高位,從左往右的
需要的工具
ultraedit:檢視class位元組碼工具
jclassjib:idea的插件,可以對照看自己解析是否正确
jvm虛拟機規範:一本書,需要檢視對應的解析資訊,最好用工具看
熟悉解析位元組碼檔案的組成!!!!!!
其實解析位元組碼就想摩斯密碼一樣,有一個對應的密碼本。對照着就可以解析了。具體可以看書《JVM虛拟機規範》
位元組碼檔案組成圖:
u1的意思是: 占1個位元組 (16進制的 01
這種算一個)
u2的意思是: 占2個位元組
u4的意思是: 占4個位元組
!的意思是:不确定,看動态生成的
這些組成的圖又有對應的屬性圖:每個屬性占多少位元組都有标記的。
魔數其實就是ca fe ba be 這四個位元組數,jvm中就是這麼規定的,記住就好了。
為什麼會有魔數?魔數有什麼用?
其實就是JVM判斷是不是一個合格的class檔案,如果是就繼續往下面讀。
次版本号和主版本号是指java版本的版本号,看圖:
constant pool常量池圖,constant_pool_count是常量池大小,也這個類有多少個常量池。
常量池選項屬性圖:
字段描述符圖
類和屬性通路修飾符圖,這個數可以相加,比如0x0009就是public static
下面是一些解析的時候一些屬性集合
field_info
field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
method_info
method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
attribute_info
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
Code_attribute
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[code_length];
u2 exception_table_length;
{ u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} exception_table[exception_table_length];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
LineNumberTable_attribute
LineNumberTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 line_number_table_length;
{ u2 start_pc;
u2 line_number;
} line_number_table[line_number_table_length];
}
LocalVariableTable
LocalVariableTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
} local_variable_table[local_variable_table_length];
}
SourceFile_attribute
SourceFile_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 sourcefile_index;
}
Java虛拟機規範pdf帶目錄位址
Java虛拟機規範pdf帶目錄