Android DEX 文件格式

Dalvik VM Dex File Format

Dex File Format


 

文件头(File Header)


 Dex files start with a simple header with some checksums and offsets to other structures

OffsetSizeDescription
0x08'Magic' value: "dex/n009/0"
0x84Checksum
0xC20SHA-1 Signature
0x204Length of file in bytes
0x244Length of header in bytes (currently always 0x5C)
0x288Padding (reserved for future use?)
0x304Number of strings in the string table
0x344Absolute offset of the string table
0x384Not sure. String related
0x3C4Number of classes in the class list
0x404Absolute offset of the class list
0x444Number of fields in the field table
0x484Absolute offset of the field table
0x4C4Number of methods in the method table
0x504Absolute offset of the method table
0x544Number of class definitions in the class definition table
0x584Absolute offset of the class definition table


Notes: All non-string fields are stored in little-endian format. It would appear that the checksum and signature fields are assumed to be zero when calculating the checksum and signature.

 

 

字符串表(String Table)


 This table stores the length and offsets for every string in the Dex file including string constants, class names, variable names and more. Each entry has the following format:

OffsetSizeDescription
0x04Absolute offset of the string data
0x44Length of the string (not including the null-terminator)


Notes: Although the length of the string is stored in this table. All strings also have C-style null-terminators

 

 

 

类列表(Class List)


 A list of all classes referenced or conatined in this dex file. Each entry has the following format:

OffsetSizeDescription
0x04String index of the name of the class

 

 

 

字段表(Field Table)


 A table of fields of all classes defined in this dex file. Each entry has the following format:

OffsetSizeDescription
0x04Class index of the class this field belongs to
0x44String index of the field name
0x84String index of the field type descriptor

 

 

 

方法表(Method Table)


 A table of methods of all classes defined in this dex file. Each entry has the following format:

OffsetSizeDescription
0x04Class index of the class this field belongs to
0x44String index of the method name
0x84String index of the method type descriptor

 

 

 

类定义表(Class Definition Table)


 A table of class definitions for all classes either defined in this dex file or has a method or field accessed by code in this dex file. Each entry has the following format:

OffsetSizeDescription
0x04Class index
0x44Access Flags (not 100% sure what this is for, I think it has to do with private/protected/public status)
0x84Index of superclass
0xC4Absolute offset of interface list
0x104Absolute offset of static field list
0x144Absolute offset of instance field list
0x184Absolute offset of direct method list
0x1C4Absolute offset of virtual method list


Notes: Any of the list offset fields can be NULL in which case the class doesn't have any elements of that type. Not every class in the class list will necessarily have an entry in the class definition table.

 

 

 

字段列表(Field List)


 Stores data for pre-initialized fields in a class. The list is formed of a 32-bit integer containing the number of entries followed by the entries themselves. Each field has an entry with the following format:

OffsetSizeDescription
0x08Index of string or object constant or literal "primitive" constant


Notes: If the field does not have a pre-initialized value it will be filled with 0 for primitive types and -1 for object types.

 

 

 

方法列表(Method List)


 A list of methods for a particular class. Begins with a 32-bit integer that contains the number of items in the list followed by entries in the following format.

OffsetSizeDescription
0x04Method index
0x44Access flags (not 100% sure what this is for, I think it has to do with private/protected/public status)
0x84Throws list off (no idea what this is)
0xC4Absolute offset of header for code that implements the method

 

 

 

 

代码头(Code Header)


 

This header contains information about the code that implements a method.

OffsetSizeDescription
0x02Number of registers used by this method
0x22Number of inputs this method takes (includes "this" pointer for non-static methods)
0x42Output size? (presumably the size of whatever object the method returns)
0x62Padding
0x84String index of the source file name this method is implemented in
0xC4Absolute offset of the actual code that implements this method
0x104Absolute offset of the list of exceptions this method can throw (not 100% sure)
0x144Absolute offset of the list of address and line number pairs for debugging purposes
0x1C4Absolute offset of the local variable list of this method (includes arguments to the method and "this")


Notes: The code offset field actually points to a 32-bit integer that contains the number of 16-bit words in the instruction stream. The actual VM instructions follow this integer.

 

 

 

局部变量表(Local Variable List)


 A list of local variables for a particular method. Begins with a 32-bit integer that contains the number of items in the list. Each entry has the following format:

OffsetSizeDescription
0x04Start (not a clue)
0x44End (not a clue)
0x84String index of variable name
0xC4String index of variable type descriptor
0x104Register number this variable will be stored in (not 100% sure)


Notes: This list will include local variables that are arguments to the method as well as the "this" variable for non-static methods.

 

 

 

ToDo

Add documentation on Position list and constant objects for pre-initialized fields.

 

Questions

If you have any questions about this document feel free to send me an e-mail at pavone@retrodev.com.

 

转自>> http://www.retrodev.com/android/dexformat.html

 

 

 

 

相关代码 


  

 

 先计算SHA签名,再计算校验和

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值