Java Class文件结构定义如下:
u4 magic
u2 minor_version
u2 major_version
u2 contant_pool_count
cp_info contant_pool[contant_pool_count - 1] // 常量池表
u2 access_flags
u2 this_class
u2 super_class
u2 interfaces_count
u2 interfaces[interfaces_count]
u2 fields_count
field_info fields[fields_count] // 字段表
u2 methods_count
method_info methods[methods_count] // 方法表
u2 attributes_count
attribute_info attributes[attributes_count] // 属性表
常量池表项
表项名称 | 结构定义 | 备注 |
CONTANT_Class | { u1 tag; u2 class_name_index; } |
|
CONTANT_MethodRef | { u1 tag; u2 class_name_index; u2 name_and_type_index; } |
|
CONTANT_FieldRef | ||
CONTANT_InterfaceMethodRef | ||
CONTANT_NameAndType | { u1 tag; u2 name_index; u2 descriptor_index; } |
|
CONTANT_Integer | { u1 tag; u4 bytes; } |
|
CONTANT_Float | ||
CONTANT_Long | { u1 tag; u2 high_bytes; u2 low_bytes; } |
|
CONTANT_Double | ||
CONTANT_Utf8 | { u1 tag; u2 length; u1 bytes[length]; } |
|
field_info结构
{
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attribute_count];
}
method_info结构
{
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attribute_count];
}
attribute_info结构
{
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
注:
(1)以下属性用来修饰方法
Code属性
LineNumberTable属性
LocalVariableTable属性
Deprecated属性*
(2)以下属性用来修饰类
FileSource属性