Dalvik 可执行格式
来源:互联网 发布:怎么下载python安装包 编辑:程序博客网 时间:2024/05/29 15:34
.dex
— Dalvik Executable Format
Copyright © 2007 The Android Open Source Project
This document describes the layout and contents of .dex
files, which are used to hold a set of class definitions and their associatedadjunct data.
Guide To Types
Name Description
1
, variable-length (see below)LEB128
LEB128 ("Little-Endian Base128") is avariable-length encoding forarbitrary signed or unsigned integer quantities. The format wasborrowed from theDWARF3specification. In a.dex
file, LEB128 is only ever used toencode 32-bit quantities.
Each LEB128 encoded value consists of one to fivebytes, which together represent a single 32-bit value. Eachbyte has its most significant bit set except for the final byte in thesequence, which has its most significant bit clear. The remainingseven bits of each byte are payload, with the least significant sevenbits of the quantity in the first byte, the next seven in the secondbyte and so on. In the case of a signed LEB128 (sleb128
),the most significant payload bit of the final byte in the sequence issign-extended to produce the final value. In the unsigned case(uleb128
), any bits not explicitly represented areinterpreted as0
.
Bitwise diagram of a two-byte LEB128 value First byte Second byte
1
bit6bit5bit4bit3bit2bit1bit00
bit13bit12bit11bit10bit9bit8bit7The variant uleb128p1
is used to represent a signedvalue, where the representation is of the valueplus one encodedas auleb128
. This makes the encoding of -1
(alternatively thought of as the unsigned value0xffffffff
)— but no other negative number — a single byte, and isuseful in exactly those cases where the represented number must eitherbe non-negative or-1
(or0xffffffff
),and where no other negative values are allowed (or where large unsignedvalues are unlikely to be needed).
Here are some examples of the formats:
Encoded Sequence As sleb128
As uleb128
As uleb128p1
Overall File Layout
Name Format Description
string_id
index, and it must not contain any duplicate entries.proto_idsproto_id_item[]method prototype identifiers list. These are identifiers for all prototypes referred to by this file. This list must be sorted in return-type (bytype_id
index) major order, and then by arguments (also bytype_id
index). The list must not contain any duplicate entries.field_idsfield_id_item[]field identifiers list. These are identifiers for all fields referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (bytype_id
index) is the major order, field name (bystring_id
index) is the intermediate order, and type (bytype_id
index) is the minor order. The list must not contain any duplicate entries.method_idsmethod_id_item[]method identifiers list. These are identifiers for all methods referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (bytype_id
index) is the major order, method name (bystring_id
index) is the intermediate order, and method prototype (byproto_id
index) is the minor order. The list must not contain any duplicate entries.class_defsclass_def_item[]class definitions list. The classes must be ordered such that a given class's superclass and implemented interfaces appear in the list earlier than the referring class. Furthermore, it is invalid for a definition for the same-named class to appear more than once in the list.dataubyte[]data area, containing all the support data for the tables listed above. Different items have different alignment requirements, and padding bytes are inserted before each item if necessary to achieve proper alignment.link_dataubyte[]data used in statically linked files. The format of the data in this section is left unspecified by this document. This section is empty in unlinked files, and runtime implementations may use it as they see fit.Bitfield, String, and Constant Definitions
DEX_FILE_MAGIC
embedded in header_item
The constant array/string DEX_FILE_MAGIC
is the list ofbytes that must appear at the beginning of a.dex
filein order for it to be recognized as such. The value intentionallycontains a newline ("\n"
or0x0a
) and anull byte ("\0"
or 0x00
) in order to helpin the detection of certain forms of corruption. The value alsoencodes a format version number as three decimal digits, which isexpected to increase monotonically over time as the format evolves.
ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x35 0x00 } = "dex\n035\0"
Note: At least a couple earlier versions of the format havebeen used in widely-available public software releases. For example,version009
was used for the M3 releases of theAndroid platform (November–December 2007),and version013
was used for the M5 releases of the Androidplatform (February–March 2008). In several respects, these earlierversions of the format differ significantly from the version described in thisdocument.
ENDIAN_CONSTANT
and REVERSE_ENDIAN_CONSTANT
embedded in header_item
The constant ENDIAN_CONSTANT
is used to indicate theendianness of the file in which it is found. Although the standard.dex
format is little-endian, implementations may chooseto perform byte-swapping. Should an implementation come across aheader whose endian_tag
is REVERSE_ENDIAN_CONSTANT
instead ofENDIAN_CONSTANT
, it would know that the filehas been byte-swapped from the expected form.
uint ENDIAN_CONSTANT = 0x12345678;uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
embedded in class_def_item
anddebug_info_item
The constant NO_INDEX
is used to indicate thatan index value is absent.
Note: This value isn't defined to be0
, because that is in fact typically a valid index.
Also Note: The chosen value for NO_INDEX
isrepresentable as a single byte in theuleb128p1
encoding.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
access_flags
Definitions
embedded in class_def_item
,encoded_field
, encoded_method
, andInnerClass
Bitfields of these flags are used to indicate the accessibility andoverall properties of classes and class members.
Name Value For Classes (and InnerClass
annotations)For Fields For Methods
public
: visible everywherepublic
: visible everywherepublic
: visible everywhereACC_PRIVATE0x2* private
: only visible to defining classprivate
: only visible to defining classprivate
: only visible to defining classACC_PROTECTED0x4* protected
: visible to package and subclassesprotected
: visible to package and subclassesprotected
: visible to package and subclassesACC_STATIC0x8* static
: is not constructed with an outer this
referencestatic
: global to defining classstatic
: does not take a this
argumentACC_FINAL0x10final
: not subclassablefinal
: immutable after constructionfinal
: not overridableACC_SYNCHRONIZED0x20 synchronized
: associated lock automatically acquired around call to this method.Note: This is only valid to set whenACC_NATIVE
is also set.ACC_VOLATILE0x40 volatile
: special access rules to help with thread safety ACC_BRIDGE0x40 bridge method, added automatically by compiler as a type-safe bridgeACC_TRANSIENT0x80 transient
: not to be saved by default serialization ACC_VARARGS0x80 last argument should be treated as a "rest" argument by compilerACC_NATIVE0x100 native
: implemented in native codeACC_INTERFACE0x200interface
: multiply-implementable abstract class ACC_ABSTRACT0x400abstract
: not directly instantiable abstract
: unimplemented by this classACC_STRICT0x800 strictfp
: strict rules for floating-point arithmeticACC_SYNTHETIC0x1000not directly defined in source codenot directly defined in source codenot directly defined in source codeACC_ANNOTATION0x2000declared as an annotation class ACC_ENUM0x4000declared as an enumerated typedeclared as an enumerated value (unused)0x8000 ACC_CONSTRUCTOR0x10000 constructor method (class or instance initializer)ACC_DECLARED_SYNCHRONIZED0x20000 declared
synchronized
. Note: This has no effect on execution (other than in reflection of this flag, per se).* Only allowed on for InnerClass
annotations,and must not ever be on in aclass_def_item
.
MUTF-8 (Modified UTF-8) Encoding
As a concession to easier legacy support, the .dex
formatencodes its string data in a de facto standard modified UTF-8 form, hereafterreferred to as MUTF-8. This form is identical to standard UTF-8, except:
- Only the one-, two-, and three-byte encodings are used.
- Code points in the range
U+10000
…U+10ffff
are encoded as a surrogate pair, each of which is represented as a three-byte encoded value. - The code point
U+0000
is encoded in two-byte form. - A plain null byte (value
0
) indicates the end of a string, as is the standard C language interpretation.
The first two items above can be summarized as: MUTF-8is an encoding format for UTF-16, instead of being a more directencoding format for Unicode characters.
The final two items above make it simultaneously possible to includethe code pointU+0000
in a stringand still manipulateit as a C-style null-terminated string.
However, the special encoding of U+0000
means that, unlikenormal UTF-8, the result of calling the standard C functionstrcmp()
on a pair of MUTF-8 strings does not alwaysindicate the properly signed result of comparison ofunequal strings.When ordering (not just equality) is a concern, the most straightforwardway to compare MUTF-8 strings is to decode them character by character,and compare the decoded values. (However, more clever implementations arealso possible.)
Please refer to The UnicodeStandard for further information about character encoding.MUTF-8 is actually closer to the (relatively less well-known) encodingCESU-8 than to UTF-8per se.
encoded_value
Encoding
embedded in annotation_element
andencoded_array_item
An encoded_value
is an encoded piece of (nearly)arbitrary hierarchically structured data. The encoding is meant tobe both compact and straightforward to parse.
Name Format Description
value
along with an optional clarifying argument in the high-order three bits. See below for the variousvalue
definitions. In most cases,value_arg
encodes the length of the immediately-subsequentvalue
in bytes, as(size - 1)
, e.g., 0
means that the value requires one byte, and7
means it requires eight bytes; however, there are exceptions as noted below.valueubyte[]bytes representing the value, variable in length and interpreted differently for differentvalue_type
bytes, though always little-endian. See the various value definitions below for details.Value Formats
Type Name value_type
value_arg
Formatvalue
FormatDescription
0
)ubyte[1]signed one-byte integer valueVALUE_SHORT0x02size - 1 (0…1)ubyte[size]signed two-byte integer value, sign-extendedVALUE_CHAR0x03size - 1 (0…1)ubyte[size]unsigned two-byte integer value, zero-extendedVALUE_INT0x04size - 1 (0…3)ubyte[size]signed four-byte integer value, sign-extendedVALUE_LONG0x06size - 1 (0…7)ubyte[size]signed eight-byte integer value, sign-extendedVALUE_FLOAT0x10size - 1 (0…3)ubyte[size]four-byte bit pattern, zero-extended to the right, and interpreted as an IEEE754 32-bit floating point valueVALUE_DOUBLE0x11size - 1 (0…7)ubyte[size]eight-byte bit pattern, zero-extended to the right, and interpreted as an IEEE754 64-bit floating point valueVALUE_STRING0x17size - 1 (0…3)ubyte[size]unsigned (zero-extended) four-byte integer value, interpreted as an index into thestring_ids
section and representing a string valueVALUE_TYPE0x18size - 1 (0…3)ubyte[size]unsigned (zero-extended) four-byte integer value, interpreted as an index into thetype_ids
section and representing a reflective type/class valueVALUE_FIELD0x19size - 1 (0…3)ubyte[size]unsigned (zero-extended) four-byte integer value, interpreted as an index into thefield_ids
section and representing a reflective field valueVALUE_METHOD0x1asize - 1 (0…3)ubyte[size]unsigned (zero-extended) four-byte integer value, interpreted as an index into themethod_ids
section and representing a reflective method valueVALUE_ENUM0x1bsize - 1 (0…3)ubyte[size]unsigned (zero-extended) four-byte integer value, interpreted as an index into thefield_ids
section and representing the value of an enumerated type constantVALUE_ARRAY0x1c(none; must be 0
)encoded_arrayan array of values, in the format specified by "encoded_array
Format" below. The size of thevalue
is implicit in the encoding.VALUE_ANNOTATION0x1d(none; must be 0
)encoded_annotationa sub-annotation, in the format specified by "encoded_annotation
Format" below. The size of thevalue
is implicit in the encoding.VALUE_NULL0x1e(none; must be 0
)(none)null
reference valueVALUE_BOOLEAN0x1fboolean (0…1)(none)one-bit value; 0
for false
and 1
for true
. The bit is represented in the value_arg
.encoded_array
Format
Name Format Description
size
encoded_value
byte sequences in the format specified by this section, concatenated sequentially.encoded_annotation
Format
Name Format Description
string_id
index.annotation_element
Format
Name Format Description
string_ids
section. The string must conform to the syntax forMemberName, defined above.valueencoded_valueelement valueString Syntax
There are several kinds of item in a .dex
file whichultimately refer to a string. The following BNF-style definitionsindicate the acceptable syntax for these strings.
SimpleName
A SimpleName is the basis for the syntax of the names of otherthings. The.dex
format allows a fair amount of latitudehere (much more than most common source languages). In brief, a simplename consists of any low-ASCII alphabetic character or digit, a fewspecific low-ASCII symbols, and most non-ASCII code points that are notcontrol, space, or special characters. Note that surrogate code points(in the rangeU+d800
…U+dfff
) are notconsidered valid name characters, per se, but Unicode supplementalcharactersare valid (which are represented by the finalalternative of the rule forSimpleNameChar), and they should berepresented in a file as pairs of surrogate code points in the MUTF-8encoding.
'A'
… 'Z'
|'a'
… 'z'
|'0'
… '9'
|'$'
|'-'
|'_'
|U+00a1
… U+1fff
|U+2010
… U+2027
|U+2030
… U+d7ff
|U+e000
… U+ffef
|U+10000
… U+10ffff
MemberName
used by field_id_item
and method_id_item
A MemberName is the name of a member of a class, members beingfields, methods, and inner classes.
MemberName → SimpleName|'<'
SimpleName '>'
FullClassName
A FullClassName is a fully-qualified class name, including anoptional package specifier followed by a required name.
FullClassName → OptionalPackagePrefix SimpleNameOptionalPackagePrefix → (SimpleName'/'
)*TypeDescriptor
used by type_id_item
A TypeDescriptor is the representation of any type, includingprimitives, classes, arrays, andvoid
. See below forthe meaning of the various versions.
'V'
|FieldTypeDescriptorFieldTypeDescriptor → NonArrayFieldTypeDescriptor|('['
* 1…255) NonArrayFieldTypeDescriptorNonArrayFieldTypeDescriptor→ 'Z'
|'B'
|'S'
|'C'
|'I'
|'J'
|'F'
|'D'
|'L'
FullClassName ';'
ShortyDescriptor
used by proto_id_item
A ShortyDescriptor is the short form representation of a methodprototype, including return and parameter types, except that there isno distinction between various reference (class or array) types. Instead,all reference types are represented by a single 'L'
character.
'V'
|ShortyFieldTypeShortyFieldType → 'Z'
|'B'
|'S'
|'C'
|'I'
|'J'
|'F'
|'D'
|'L'
TypeDescriptor Semantics
This is the meaning of each of the variants of TypeDescriptor.
Syntax Meaning
void
; only valid for return typesZboolean
Bbyte
Sshort
Cchar
Iint
Jlong
Ffloat
Ddouble
Lfully/qualified/Name;the class fully.qualified.Name
[descriptorarray of descriptor
, usable recursively for arrays-of-arrays, though it is invalid to have more than 255 dimensions.Items and Related Structures
This section includes definitions for each of the top-level items thatmay appear in a.dex
file.
header_item
appears in the header
section
alignment: 4 bytes
Name Format Description
DEX_FILE_MAGIC
" for more details.checksumuintadler32 checksum of the rest of the file (everything but magic
and this field); used to detect file corruptionsignatureubyte[20]SHA-1 signature (hash) of the rest of the file (everything but magic
,checksum
, and this field); used to uniquely identify filesfile_sizeuintsize of the entire file (including the header), in bytesheader_sizeuint = 0x70size of the header (this entire section), in bytes. This allows for at least a limited amount of backwards/forwards compatibility without invalidating the format.endian_taguint = ENDIAN_CONSTANTendianness tag. See discussion above under "ENDIAN_CONSTANT
and REVERSE_ENDIAN_CONSTANT
" for more details.link_sizeuintsize of the link section, or 0
if this file isn't statically linkedlink_offuintoffset from the start of the file to the link section, or 0
if link_size == 0
. The offset, if non-zero, should be to an offset into the link_data
section. The format of the data pointed at is left unspecified by this document; this header field (and the previous) are left as hooks for use by runtime implementations.map_offuintoffset from the start of the file to the map item, or 0
if this file has no map. The offset, if non-zero, should be to an offset into thedata
section, and the data should be in the format specified by "map_list
" below.string_ids_sizeuintcount of strings in the string identifiers liststring_ids_offuintoffset from the start of the file to the string identifiers list, or 0
ifstring_ids_size == 0
(admittedly a strange edge case). The offset, if non-zero, should be to the start of thestring_ids
section.type_ids_sizeuintcount of elements in the type identifiers listtype_ids_offuintoffset from the start of the file to the type identifiers list, or 0
iftype_ids_size == 0
(admittedly a strange edge case). The offset, if non-zero, should be to the start of thetype_ids
section.proto_ids_sizeuintcount of elements in the prototype identifiers listproto_ids_offuintoffset from the start of the file to the prototype identifiers list, or 0
if proto_ids_size == 0
(admittedly a strange edge case). The offset, if non-zero, should be to the start of theproto_ids
section.field_ids_sizeuintcount of elements in the field identifiers listfield_ids_offuintoffset from the start of the file to the field identifiers list, or 0
iffield_ids_size == 0
. The offset, if non-zero, should be to the start of thefield_ids
section.method_ids_sizeuintcount of elements in the method identifiers listmethod_ids_offuintoffset from the start of the file to the method identifiers list, or 0
ifmethod_ids_size == 0
. The offset, if non-zero, should be to the start of themethod_ids
section.class_defs_sizeuintcount of elements in the class definitions listclass_defs_offuintoffset from the start of the file to the class definitions list, or 0
ifclass_defs_size == 0
(admittedly a strange edge case). The offset, if non-zero, should be to the start of theclass_defs
section.data_sizeuintSize of data
section in bytes. Must be an even multiple of sizeof(uint).data_offuintoffset from the start of the file to the start of the data
section.map_list
appears in the data
section
referenced from header_item
alignment: 4 bytes
This is a list of the entire contents of a file, in order. Itcontains some redundancy with respect to theheader_item
but is intended to be an easy form to use to iterate over an entirefile. A given type must appear at most once in a map, but there is norestriction on what order types may appear in, other than therestrictions implied by the rest of the format (e.g., aheader
section must appear first, followed by astring_ids
section, etc.). Additionally, the map entries mustbe ordered by initial offset and must not overlap.
Name Format Description
map_item
Format
Name Format Description
Type Codes
Item Type Constant Value Item Size In Bytes
string_id_item
appears in the string_ids
section
alignment: 4 bytes
Name Format Description
data
section, and the data should be in the format specified by "string_data_item
" below. There is no alignment requirement for the offset.string_data_item
appears in the data
section
alignment: none (byte-aligned)
Name Format Description
0
byte.)dataubyte[]a series of MUTF-8 code units (a.k.a. octets, a.k.a. bytes) followed by a byte of value0
. See "MUTF-8 (Modified UTF-8) Encoding" above for details and discussion about the data format.Note: It is acceptable to have a string which includes (the encoded form of) UTF-16 surrogate code units (that is,U+d800
…U+dfff
) either in isolation or out-of-order with respect to the usual encoding of Unicode into UTF-16. It is up to higher-level uses of strings to reject such invalid encodings, if appropriate.
type_id_item
appears in the type_ids
section
alignment: 4 bytes
Name Format Description
string_ids
list for the descriptor string of this type. The string must conform to the syntax forTypeDescriptor, defined above.proto_id_item
appears in the proto_ids
section
alignment: 4 bytes
Name Format Description
string_ids
list for the short-form descriptor string of this prototype. The string must conform to the syntax forShortyDescriptor, defined above, and must correspond to the return type and parameters of this item.return_type_idxuintindex into the type_ids
list for the return type of this prototypeparameters_offuintoffset from the start of the file to the list of parameter types for this prototype, or0
if this prototype has no parameters. This offset, if non-zero, should be in thedata
section, and the data there should be in the format specified by"type_list"
below. Additionally, there should be no reference to the typevoid
in the list.field_id_item
appears in the field_ids
section
alignment: 4 bytes
Name Format Description
type_ids
list for the definer of this field. This must be a class type, and not an array or primitive type.type_idxushortindex into the type_ids
list for the type of this fieldname_idxuintindex into the string_ids
list for the name of this field. The string must conform to the syntax forMemberName, defined above.method_id_item
appears in the method_ids
section
alignment: 4 bytes
Name Format Description
type_ids
list for the definer of this method. This must be a class or array type, and not a primitive type.proto_idxushortindex into the proto_ids
list for the prototype of this methodname_idxuintindex into the string_ids
list for the name of this method. The string must conform to the syntax forMemberName, defined above.class_def_item
appears in the class_defs
section
alignment: 4 bytes
Name Format Description
type_ids
list for this class. This must be a class type, and not an array or primitive type.access_flagsuintaccess flags for the class (public
, final
, etc.). See "access_flags
Definitions" for details.superclass_idxuintindex into the type_ids
list for the superclass, or the constant valueNO_INDEX
if this class has no superclass (i.e., it is a root class such asObject
). If present, this must be a class type, and not an array or primitive type.interfaces_offuintoffset from the start of the file to the list of interfaces, or 0
if there are none. This offset should be in thedata
section, and the data there should be in the format specified by "type_list
" below. 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.source_file_idxuintindex 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 valueNO_INDEX
to represent a lack of this information. Thedebug_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.annotations_offuintoffset from the start of the file to the annotations structure for this class, or0
if there are no annotations on this class. This offset, if non-zero, should be in thedata
section, and the data there should be in the format specified by "annotations_directory_item
" below, with all items referring to this class as the definer.class_data_offuintoffset from the start of the file to the associated class data for this item, or0
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 thedata
section, and the data there should be in the format specified by "class_data_item
" below, with all items referring to this class as the definer.static_values_offuintoffset from the start of the file to the list of initial values for static
fields, or0
if there are none (and allstatic
fields are to be initialized with0
or null
). This offset should be in thedata
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 ofstatic
fields declared by this class, and the elements correspond to thestatic
fields in the same order as declared in the correspondingfield_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 arestatic
fields, then the leftover fields are initialized with a type-appropriate0
or null
.class_data_item
referenced from class_def_item
appears in the data
section
alignment: none (byte-aligned)
Name Format Description
field_idx
in increasing order.instance_fieldsencoded_field[instance_fields_size]the defined instance fields, represented as a sequence of encoded elements. The fields must be sorted byfield_idx
in increasing order.direct_methodsencoded_method[direct_methods_size]the defined direct (any of static
, private
, or constructor) methods, represented as a sequence of encoded elements. The methods must be sorted bymethod_idx
in increasing order.virtual_methodsencoded_method[virtual_methods_size]the defined virtual (none of static
, private
, or constructor) methods, represented as a sequence of encoded elements. This list shouldnot include inherited methods unless overridden by the class that this item represents. The methods must be sorted bymethod_idx
in increasing order.Note: All elements' field_id
s andmethod_id
s must refer to the same defining class.
encoded_field
Format
Name Format Description
field_ids
list for the identity of this field (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.access_flagsuleb128access flags for the field (public
, final
, etc.). See "access_flags
Definitions" for details.encoded_method
Format
Name Format Description
method_ids
list for the identity of this method (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.access_flagsuleb128access flags for the method (public
, final
, etc.). See "access_flags
Definitions" for details.code_offuleb128offset from the start of the file to the code structure for this method, or 0
if this method is either abstract
or native
. The offset should be to a location in thedata
section. The format of the data is specified by "code_item
" below.type_list
referenced from class_def_item
andproto_id_item
appears in the data
section
alignment: 4 bytes
Name Format Description
type_item
Format
Name Format Description
type_ids
listcode_item
referenced from encoded_method
appears in the data
section
alignment: 4 bytes
Name Format Description
try_item
s for this instance. If non-zero, then these appear as thetries
array just after theinsns
in this instance.debug_info_offuintoffset from the start of the file to the debug info (line numbers + local variable info) sequence for this code, or0
if there simply is no information. The offset, if non-zero, should be to a location in thedata
section. The format of the data is specified by "debug_info_item
" below.insns_sizeuintsize of the instructions list, in 16-bit code unitsinsnsushort[insns_size]actual array of bytecode. The format of code in an insns
array is specified by the companion document"Bytecode for the Dalvik VM". Note that though this is defined as an array ofushort
, there are some internal structures that prefer four-byte alignment. Also, if this happens to be in an endian-swapped file, then the swapping isonly done on individualushort
s and not on the larger internal structures.paddingushort (optional) = 0two bytes of padding to make tries
four-byte aligned. This element is only present iftries_size
is non-zero andinsns_size
is odd.triestry_item[tries_size] (optional)array indicating where in the code exceptions are caught and how to handle them. Elements of the array must be non-overlapping in range and in order from low to high address. This element is only present iftries_size
is non-zero.handlersencoded_catch_handler_list (optional)bytes representing a list of lists of catch types and associated handler addresses. Eachtry_item
has a byte-wise offset into this structure. This element is only present iftries_size
is non-zero.try_item
Format
Name Format Description
start_addr + insn_count - 1
.handler_offushortoffset in bytes from the start of the associated encoded_catch_hander_list
to theencoded_catch_handler
for this entry. This must be an offset to the start of anencoded_catch_handler
.encoded_catch_handler_list
Format
Name Format Description
encoded_catch_handler
Format
Name Format Description
size
of0
means that there is a catch-all but no explicitly typed catches. Asize
of2
means that there are two explicitly typed catches and no catch-all. And asize
of-1
means that there is one typed catch along with a catch-all.handlersencoded_type_addr_pair[abs(size)]stream of abs(size)
encoded items, one for each caught type, in the order that the types should be tested.catch_all_addruleb128 (optional)bytecode address of the catch-all handler. This element is only present if size
is non-positive.encoded_type_addr_pair
Format
Name Format Description
type_ids
list for the type of the exception to catchaddruleb128bytecode address of the associated exception handlerdebug_info_item
referenced from code_item
appears in the data
section
alignment: none (byte-aligned)
Each debug_info_item
defines a DWARF3-inspired byte-codedstate machine that, when interpreted, emits the positionstable and (potentially) the local variable information for acode_item
. The sequence begins with a variable-lengthheader (the length of which depends on the number of methodparameters), is followed by the state machine bytecodes, and endswith anDBG_END_SEQUENCE
byte.
The state machine consists of five registers. Theaddress
register represents the instruction offset in theassociatedinsns_item
in 16-bit code units. Theaddress
register starts at0
at the beginning of eachdebug_info
sequence and must only monotonically increase.Theline
register represents what source line numbershould be associated with the next positions table entry emitted bythe state machine. It is initialized in the sequence header, and maychange in positive or negative directions but must never be less than1
. The source_file
register represents thesource file that the line number entries refer to. It is initialized tothe value ofsource_file_idx
inclass_def_item
.The other two variables,prologue_end
andepilogue_begin
, are boolean flags (initialized tofalse
) that indicate whether the next position emittedshould be considered a method prologue or epilogue. The state machinemust also track the name and type of the last local variable live ineach register for theDBG_RESTART_LOCAL
code.
The header is as follows:
Name Format Description
line
register. Does not represent an actual positions entry.parameters_sizeuleb128the number of parameter names that are encoded. There should be one per method parameter, excluding an instance method'sthis
, if any.parameter_namesuleb128p1[parameters_size]string index of the method parameter name. An encoded value of NO_INDEX
indicates that no name is available for the associated parameter. The type descriptor and signature are implied from the method descriptor and signature.The byte code values are as follows:
Name Value Format Arguments Description
code_item
DBG_ADVANCE_PC0x01uleb128 addr_diffaddr_diff
: amount to add to address registeradvances the address register without emitting a positions entryDBG_ADVANCE_LINE0x02sleb128 line_diffline_diff
: amount to change line register byadvances the line register without emitting a positions entryDBG_START_LOCAL0x03uleb128 register_numuleb128p1 name_idx
uleb128p1 type_idx
register_num
: register that will contain localname_idx
: string index of the nametype_idx
: type index of the typeintroduces a local variable at the current address. Either name_idx
ortype_idx
may beNO_INDEX
to indicate that that value is unknown.DBG_START_LOCAL_EXTENDED0x04uleb128 register_numuleb128p1 name_idx
uleb128p1 type_idx
uleb128p1 sig_idx
register_num
: register that will contain localname_idx
: string index of the nametype_idx
: type index of the typesig_idx
: string index of the type signatureintroduces a local with a type signature at the current address. Any of name_idx
, type_idx
, or sig_idx
may be NO_INDEX
to indicate that that value is unknown. (Ifsig_idx
is-1
, though, the same data could be represented more efficiently using the opcodeDBG_START_LOCAL
.)Note: See the discussion under "dalvik.annotation.Signature
" below for caveats about handling signatures.
register_num
: register that contained localmarks a currently-live local variable as out of scope at the current addressDBG_RESTART_LOCAL0x06uleb128 register_numregister_num
: register to restartre-introduces a local variable at the current address. The name and type are the same as the last local that was live in the specified register.DBG_SET_PROLOGUE_END0x07 (none)sets the prologue_end
state machine register, indicating that the next position entry that is added should be considered the end of a method prologue (an appropriate place for a method breakpoint). Theprologue_end
register is cleared by any special (>= 0x0a
) opcode.DBG_SET_EPILOGUE_BEGIN0x08 (none)sets the epilogue_begin
state machine register, indicating that the next position entry that is added should be considered the beginning of a method epilogue (an appropriate place to suspend execution before method exit). Theepilogue_begin
register is cleared by any special (>= 0x0a
) opcode.DBG_SET_FILE0x09uleb128p1 name_idxname_idx
: string index of source file name; NO_INDEX
if unknownindicates that all subsequent line number entries make reference to this source file name, instead of the default name specified incode_item
Special Opcodes0x0a…0xff (none)advances the line
and address
registers, emits a position entry, and clearsprologue_end
andepilogue_begin
. See below for description.Special Opcodes
Opcodes with values between 0x0a
and 0xff
(inclusive) move both theline
andaddress
registers by a small amount and then emit a new position table entry.The formula for the increments are as follows:
DBG_FIRST_SPECIAL = 0x0a // the smallest special opcodeDBG_LINE_BASE = -4 // the smallest line number incrementDBG_LINE_RANGE = 15 // the number of line increments representedadjusted_opcode = opcode - DBG_FIRST_SPECIALline += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE)address += (adjusted_opcode / DBG_LINE_RANGE)
annotations_directory_item
referenced from class_def_item
appears in the data
section
alignment: 4 bytes
Name Format Description
0
if the class has no direct annotations. The offset, if non-zero, should be to a location in thedata
section. The format of the data is specified by "annotation_set_item
" below.fields_sizeuintcount of fields annotated by this itemannotated_methods_sizeuintcount of methods annotated by this itemannotated_parameters_sizeuintcount of method parameter lists annotated by this itemfield_annotationsfield_annotation[fields_size] (optional)list of associated field annotations. The elements of the list must be sorted in increasing order, byfield_idx
.method_annotationsmethod_annotation[methods_size] (optional)list of associated method annotations. The elements of the list must be sorted in increasing order, bymethod_idx
.parameter_annotationsparameter_annotation[parameters_size] (optional)list of associated method parameter annotations. The elements of the list must be sorted in increasing order, bymethod_idx
.Note: All elements' field_id
s andmethod_id
s must refer to the same defining class.
field_annotation
Format
Name Format Description
field_ids
list for the identity of the field being annotatedannotations_offuintoffset from the start of the file to the list of annotations for the field. The offset should be to a location in thedata
section. The format of the data is specified by "annotation_set_item
" below.method_annotation
Format
Name Format Description
method_ids
list for the identity of the method being annotatedannotations_offuintoffset from the start of the file to the list of annotations for the method. The offset should be to a location in thedata
section. The format of the data is specified by "annotation_set_item
" below.parameter_annotation
Format
Name Format Description
method_ids
list for the identity of the method whose parameters are being annotatedannotations_offuintoffset from the start of the file to the list of annotations for the method parameters. The offset should be to a location in thedata
section. The format of the data is specified by "annotation_set_ref_list
" below.annotation_set_ref_list
referenced from parameter_annotations_item
appears in the data
section
alignment: 4 bytes
Name Format Description
annotation_set_ref_item
Format
Name Format Description
0
if there are no annotations for this element. The offset, if non-zero, should be to a location in thedata
section. The format of the data is specified by "annotation_set_item
" below.annotation_set_item
referenced from annotations_directory_item
,field_annotations_item
,method_annotations_item
, andannotation_set_ref_item
appears in the data
section
alignment: 4 bytes
Name Format Description
type_idx
.annotation_off_item
Format
Name Format Description
data
section, and the format of the data at that location is specified by "annotation_item
" below.annotation_item
referenced from annotation_set_item
appears in the data
section
alignment: none (byte-aligned)
Name Format Description
encoded_annotation
Format" under "encoded_value
Encoding" above.Visibility values
These are the options for the visibility
field in anannotation_item
:
Name Value Description
encoded_array_item
referenced from class_def_item
appears in the data
section
alignment: none (byte-aligned)
Name Format Description
encoded_array
Format" under "encoded_value
Encoding" above.System Annotations
System annotations are used to represent various pieces of reflectiveinformation about classes (and methods and fields). This information isgenerally only accessed indirectly by client (non-system) code.
System annotations are represented in .dex
files asannotations with visibility set toVISIBILITY_SYSTEM
.
dalvik.annotation.AnnotationDefault
appears on methods in annotation interfaces
An AnnotationDefault
annotation is attached to eachannotation interface which wishes to indicate default bindings.
Name Format Description
dalvik.annotation.EnclosingClass
appears on classes
An EnclosingClass
annotation is attached to each classwhich is either defined as a member of another class, per se, or isanonymous but not defined within a method body (e.g., a syntheticinner class). Every class that has this annotation must also have anInnerClass
annotation. Additionally, a class must not haveboth anEnclosingClass
and anEnclosingMethod
annotation.
Name Format Description
dalvik.annotation.EnclosingMethod
appears on classes
An EnclosingMethod
annotation is attached to each classwhich is defined inside a method body. Every class that has thisannotation must also have anInnerClass
annotation.Additionally, a class must not have both anEnclosingClass
and an EnclosingMethod
annotation.
Name Format Description
dalvik.annotation.InnerClass
appears on classes
An InnerClass
annotation is attached to each classwhich is defined in the lexical scope of another class's definition.Any class which has this annotation must also haveeither anEnclosingClass
annotationor anEnclosingMethod
annotation.
Name Format Description
null
.accessFlagsintthe originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine)dalvik.annotation.MemberClasses
appears on classes
A MemberClasses
annotation is attached to each classwhich declares member classes. (A member class is a direct inner classthat has a name.)
Name Format Description
dalvik.annotation.Signature
appears on classes, fields, and methods
A Signature
annotation is attached to each class,field, or method which is defined in terms of a more complicated typethan is representable by atype_id_item
. The.dex
format does not define the format for signatures; itis merely meant to be able to represent whatever signatures a sourcelanguage requires for successful implementation of that language'ssemantics. As such, signatures are not generally parsed (or verified)by virtual machine implementations. The signatures simply get handedoff to higher-level APIs and tools (such as debuggers). Any use of asignature, therefore, should be written so as not to make anyassumptions about only receiving valid signatures, explicitly guardingitself against the possibility of coming across a syntacticallyinvalid signature.
Because signature strings tend to have a lot of duplicated content,a Signature
annotation is defined as anarray ofstrings, where duplicated elements naturally refer to the sameunderlying data, and the signature is taken to be the concatenation ofall the strings in the array. There are no rules about how to pullapart a signature into separate strings; that is entirely up to thetools that generate.dex
files.
Name Format Description
dalvik.annotation.Throws
appears on methods
A Throws
annotation is attached to each method which isdeclared to throw one or more exception types.
Name Format Description
- Dalvik 可执行格式
- Dalvik虚拟机相关的可执行程序
- Dalvik虚拟机相关的可执行程序
- Dalvik虚拟机相关的可执行程序
- Dalvik虚拟机相关的可执行程序
- Dalvik虚拟机相关的可执行程序
- Dalvik虚拟机相关的可执行程序
- Dalvik指令格式
- Dalvik指令格式
- linux可执行格式
- Dalvik虚拟机的指令格式
- Framework的启动过程---Dalvik虚拟机相关的可执行程序
- Dalvik技术揭秘之四-Dalvik虚拟机的指令格式
- Dalvik方法格式的表示形式
- 操作系统学习笔记(38)--ELF可执行格式
- Dalvik
- Dalvik
- Dalvik
- cppquery 简单的数据绑定对话框
- The import android cannot be resolved问题解决
- Android通讯录导入到Iphone
- 利用JavaMail发送邮件
- Android Toast自定义 (一个textview多种颜色,或试用html多种颜色)
- Dalvik 可执行格式
- Spring的BindException设置错误信息
- 搭建hadoop cdh4.5版笔记
- 一般线性模型的最小二次方拟合方法
- 两种高效的事件处理模式 reacotr模式和proactor模式
- 简单的Silverlight+MVVM+WCF Ria Service 对数据的增删改查DEMO
- 45个JavaScript技巧和最佳实践
- JavaSE_数组_十进制转其他进制
- 程序员2014年展望未来八个小小技巧