Android - DEX - 文件格式详解(2)

2019-03-27 17:56

return_type_idx uint index into the type_ids list for the return type of this prototype offset from the start of the file to the list of parameter types for this prototype, or 0 if this prototype has no parameters. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by \below. Additionally, there should be no reference to the type void in the list. parameters_off uint shorty_idx为String Id列表的索引,return_type_idx为Type Id列表的索引,parameters_off指向type_list。type_list结构如下: Name Format Description size uint size of the list, in entries list type_item[size] elements of the list type_item结构入下: Name Format Description type_idx ushort index into the type_ids list type_idx为type id列表的索引。

从文件的0xc4得到prototype id列表如下,共有3个proto_id_item。 1) 0006 0000 0005 0000 0000 0000

string_id_list[0x6]代表V,返回类型type_id_list[0x5]代表V,没有参数。 2) 0007 0000 0005 0000 0168 0000

string_id_list[0x7]代表VL,返回类型type_id_list[0x5]代表V,参数从0x168处的值为: 0001 0000 0002 一个参数,索引为0x2,type_id_list[0x2]代表Ljava/lang/String; 3) 0007 0000 0005 0000 0170 0000

string_id_list[0x7]代表VL,返回类型type_id_list[0x5]代表V,参数从0x170处的值为: 0001 0000 0006 一个参数,索引为0x6,type_id_list[0x6]代表[Ljava/lang/String; 注:字段和方法描述符参见附录2。

5. field_id_item

批注16得出field id列表的位置为0xe8,批注15的处field id列表中field_id_item的数量为0x1。Field id的结构为field_id_item: Name Format Description class_idx ushort type_idx name_idx index into the type_ids list for the definer of this field. This must be a class type, and not an array or primitive type. ushort index into the type_ids list for the type of this field uint index into the string_ids list for the name of this field. The string must conform to the syntax for MemberName, defined above. class_idx 为类的类型,即该字段所属的类。 type_idx 为此字段的类型。 name_idx 为此字段的名字。

从文件的0xe8得到filed id列表如下,共有1个field_id_item。

0003 0000 000a 0000

该字段所属的类为:Ljava/lang/System; 此字段的类型为:Ljava/io/PrintStream; 此字段的名字为:out

6. method_id_item

批注18得出method id列表的位置为0xf0,批注17的处method id列表中method_id_item的数量为0x4。Method id的结构为method_id_item: Name Format Description class_idx proto_idx name_idx ushort ushort uint index into the type_ids list for the definer of this method. This must be a class or array type, and not a primitive type. index into the proto_ids list for the prototype of this method index into the string_ids list for the name of this method. The string must conform to the syntax for MemberName, defined above. class_idx 为类的类型,即该方法所属的类。 proto_idx 此方法原型。 name_idx 此方法名字。

从文件的0xf0得到method id列表如下,共有4个method_id_item。

0000 0001 000b 0000 类:Ljava/io/PrintStream; 原型:VL 名字:println 0001 0000 0000 0000 类:Ljava/lang/Object; 原型:V 名字: 0004 0000 0000 0000 类:Ljava/lang/System; 原型:V 名字: 0004 0002 0009 0000 类:Ljava/lang/System; 原型:VL 名字: main

7. class_def_item

批注20得出class definitions列表的位置为0x110,批注19的处class definitions列表中 class_def__item的数量为0x1。class definitions的结构为class_def_item:

Name Format Description class_idx access_flags uint uint index into the type_ids list for this class. This must be a class type, and not an array or primitive type. access flags for the class (public, final, etc.). See \access_flags Definitions\index into the type_ids list for the superclass, or the constant value NO_INDEX if this class has no superclass (i.e., it is a root class such as Object). If present, this must be a class type, and not an array or primitive type. superclass_idx uint interfaces_off uint

source_file_idx uint

annotations_off uint

class_data_off uint

offset from the start of the file to the list of interfaces, or 0 if there are none. This offset should be in the data section, and the data there should be in the format specified by \Each of the elements of the list must be a class type (not an array or primitive type), and there must not be any duplicates.

接口列表的偏移,如果为0表示没有接口。此偏移量应该在数据段中,并且类型详细说明在\中。表中的每一个元素都必须是类类型(而不能是一个数组或基本类型),并且不能有任何重复。

index into the string_ids list for the name of the file containing the original source for (at least most of) this class, or the special value NO_INDEX to represent a lack of this information. The debug_info_item of any given method may override this source file, but the expectation is that most classes will only come from one source file.

类源码所在的文件的名称索引(至少大部分是这样的),此索引对应string_ids数组中的索引。或者是一个特殊值NO_INDEX表示缺少这种文件的信息。

offset from the start of the file to the annotations structure for this class, or 0 if there are no

annotations on this class. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by

\annotations_directory_item\referring to this class as the definer.

注释结构的偏移,如果为0,则表示此类没有注解。如果不为零,应在数据段,该数据应在规定的“

annotations_directory_item”下面的格式,所有项目指的是这个类的定义者。

offset from the start of the file to the associated class data for this item, or 0 if there is no class data for this class. (This may be the case, for example, if this class is a marker interface.) The offset, if non-zero, should be in the data section, and the data there should be in the format specified by

\class_data_item\this class as the definer.

与此类相关的类数据的偏移,如果为0,这说明没有此类的类数据(例如:此类是一个标记接口)。如果不为零,应在数据段,该数据应在规定的“class_data_item”下面的格式,所有项目指的是这个类的定义者。

static_values_off uint

offset from the start of the file to the list of initial values for static fields, or 0 if there are none (and all static fields are to be initialized with 0 or null). This offset should be in the data section, and the data there should be in the format specified by

\encoded_array_item\below. The size of the array must be no larger than the number of static fields declared by this class, and the elements correspond to the static fields in the same order as declared in the

corresponding field_list. The type of each array element must match the declared type of its corresponding field. If there are fewer elements in the array than there are static fields, then the leftover fields are initialized with a type-appropriate 0 or null.

静态字段初始值的偏移,如果为0,则说明没有静态数据(所有的静态数据都初始化为0或null)。这个偏移位置在数据段中,数据保存在encoded_array_item的格式中。数组中元素的个数不能大于类中静态字段的个数,元素的排序对应field_list中的排序。每个数组元素的类型必须匹配与之对应的字段声明的类型。如果有比有静态字段的数组中的元素少,那么剩下的字段都被初始化一个适合不同类型的0或null。

0004 0000 0000 0000 0001 0000 0000 0000 000d 0000 0000 0000 0227 0000 0000 0000

class_idx 类的类型:Ltest; access_flags 访问权限:

superclass_idx 父类:Ljava/lang/Object; interfaces_off 没有接口

source_file_idx 文件名test.java annotations_off 没有注释

class_data_off 指向class_data_item,机构如下。 static_values_off 暂时无

class_data_item Name Format Description the number of static fields defined in static_fields_size uleb128 this item the number of instance fields defined instance_fields_size uleb128 in this item the number of direct methods defined direct_methods_size uleb128 in this item the number of virtual methods defined virtual_methods_size uleb128 in this item static_fields encoded_field[static_fields_size] the defined static fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order. the defined instance fields, encoded_field[instancrepresented as a sequence of encoded instance_fields e_fields_size] elements. The fields must be sorted by field_idx in increasing order. the defined direct (any of static, private, or constructor) methods, represented as a sequence of encoded elements. The methods must be sorted encoded_method[directdirect_methods by method_idx in increasing order. _methods_size] 所定义的直接方法(任何静态的,私有的,或构造函数),表示为一个序列编码的元素。该方法必须按method_idx的递增的顺序。 the defined virtual (none of static, private, or constructor) methods, represented as a sequence of encoded elements. This list should not include inherited methods unless overridden by the class that this item encoded_method[virtuavirtual_methods represents. The methods must be sorted l_methods_size] by method_idx in increasing order. 定义的虚拟方法(不是静态的,私有的,或构造函数),表示为一个序列编码的元素。该列表不应包括继承的方法,除非覆盖的类,这个项目代表。方法必须按method_idx的递增的顺序 文件的0x227处为class_data_item结构。从0x227处得来的字节序为: 00 00 02 00 02 80 80 04 b0 02 01 09 c8 02 00 00 00 static_fields_size 为0 instance_fields_size 为0 direct_methods_size 为2 virtual_methods_size 为0

因为前两个为0,所以下一个字节开始就是direct_methods,encoded_method和encoded_field机构如下,两个direct_method为: 1) 02 80 80 04 b0 02

method_idx_diff 为0x2

access_flags 为0x10000 (80 80 04) 代表constructor method code_off 为0x130 (b0 02) 指向 code_item 从0x130解析code_item:

registers_size(u2) 0x1 ins_size(u2) 0x1 outs_size(u2) 0x1 tries_size(u2) 0


Android - DEX - 文件格式详解(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:政法综治责任状汇编

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: