1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
6 <title>.dex — Dalvik Executable Format</title>
7 <link rel=stylesheet href="dex-format.css">
12 <h1 class="title"><code>.dex</code> — Dalvik Executable Format</h1>
13 <p>Copyright © 2007 The Android Open Source Project
15 <p>This document describes the layout and contents of <code>.dex</code>
16 files, which are used to hold a set of class definitions and their associated
19 <h1>Guide To Types</h1>
31 <td>8-bit signed int</td>
35 <td>8-bit unsigned int</td>
39 <td>16-bit signed int, little-endian</td>
43 <td>16-bit unsigned int, little-endian</td>
47 <td>32-bit signed int, little-endian</td>
51 <td>32-bit unsigned int, little-endian</td>
55 <td>64-bit signed int, little-endian</td>
59 <td>64-bit unsigned int, little-endian</td>
63 <td>signed LEB128, variable-length (see below)</td>
67 <td>unsigned LEB128, variable-length (see below)</td>
71 <td>unsigned LEB128 plus <code>1</code>, variable-length (see below)</td>
78 <p>LEB128 ("<b>L</b>ittle-<b>E</b>ndian <b>B</b>ase <b>128</b>") is a
79 variable-length encoding for
80 arbitrary signed or unsigned integer quantities. The format was
81 borrowed from the <a href="http://dwarfstd.org/Dwarf3Std.php">DWARF3</a>
82 specification. In a <code>.dex</code> file, LEB128 is only ever used to
83 encode 32-bit quantities.</p>
85 <p>Each LEB128 encoded value consists of one to five
86 bytes, which together represent a single 32-bit value. Each
87 byte has its most significant bit set except for the final byte in the
88 sequence, which has its most significant bit clear. The remaining
89 seven bits of each byte are payload, with the least significant seven
90 bits of the quantity in the first byte, the next seven in the second
91 byte and so on. In the case of a signed LEB128 (<code>sleb128</code>),
92 the most significant payload bit of the final byte in the sequence is
93 sign-extended to produce the final value. In the unsigned case
94 (<code>uleb128</code>), any bits not explicitly represented are
95 interpreted as <code>0</code>.
97 <table class="leb128Bits">
99 <tr><th colspan="16">Bitwise diagram of a two-byte LEB128 value</th></tr>
101 <th colspan="8">First byte</td>
102 <th colspan="8">Second byte</td>
107 <td class="start1"><code>1</code></td>
108 <td>bit<sub>6</sub></td>
109 <td>bit<sub>5</sub></td>
110 <td>bit<sub>4</sub></td>
111 <td>bit<sub>3</sub></td>
112 <td>bit<sub>2</sub></td>
113 <td>bit<sub>1</sub></td>
114 <td>bit<sub>0</sub></td>
115 <td class="start2"><code>0</code></td>
116 <td>bit<sub>13</sub></td>
117 <td>bit<sub>12</sub></td>
118 <td>bit<sub>11</sub></td>
119 <td>bit<sub>10</sub></td>
120 <td>bit<sub>9</sub></td>
121 <td>bit<sub>8</sub></td>
122 <td class="end2">bit<sub>7</sub></td>
127 <p>The variant <code>uleb128p1</code> is used to represent a signed
128 value, where the representation is of the value <i>plus one</i> encoded
129 as a <code>uleb128</code>. This makes the encoding of <code>-1</code>
130 (alternatively thought of as the unsigned value <code>0xffffffff</code>)
131 — but no other negative number — a single byte, and is
132 useful in exactly those cases where the represented number must either
133 be non-negative or <code>-1</code> (or <code>0xffffffff</code>),
134 and where no other negative values are allowed (or where large unsigned
135 values are unlikely to be needed).</p>
137 <p>Here are some examples of the formats:</p>
139 <table class="leb128">
142 <th>Encoded Sequence</th>
143 <th>As <code>sleb128</code></th>
144 <th>As <code>uleb128</code></th>
145 <th>As <code>uleb128p1</code></th>
149 <tr><td>00</td><td>0</td><td>0</td><td>-1</td></tr>
150 <tr><td>01</td><td>1</td><td>1</td><td>0</td></tr>
151 <tr><td>7f</td><td>-1</td><td>127</td><td>126</td></tr>
152 <tr><td>80 7f</td><td>-128</td><td>16256</td><td>16255</td></tr>
156 <h1>Overall File Layout</h1>
158 <table class="format">
174 <td>string_id_item[]</td>
175 <td>string identifiers list. These are identifiers for all the strings
176 used by this file, either for internal naming (e.g., type descriptors)
177 or as constant objects referred to by code. This list must be sorted
178 by string contents, using UTF-16 code point values (not in a
179 locale-sensitive manner).
184 <td>type_id_item[]</td>
185 <td>type identifiers list. These are identifiers for all types (classes,
186 arrays, or primitive types) referred to by this file, whether defined
187 in the file or not. This list must be sorted by <code>string_id</code>
193 <td>proto_id_item[]</td>
194 <td>method prototype identifiers list. These are identifiers for all
195 prototypes referred to by this file. This list must be sorted in
196 return-type (by <code>type_id</code> index) major order, and then
197 by arguments (also by <code>type_id</code> index).
202 <td>field_id_item[]</td>
203 <td>field identifiers list. These are identifiers for all fields
204 referred to by this file, whether defined in the file or not. This
205 list must be sorted, where the defining type (by <code>type_id</code>
206 index) is the major order, field name (by <code>string_id</code> index)
207 is the intermediate order, and type (by <code>type_id</code> index)
213 <td>method_id_item[]</td>
214 <td>method identifiers list. These are identifiers for all methods
215 referred to by this file, whether defined in the file or not. This
216 list must be sorted, where the defining type (by <code>type_id</code>
217 index) is the major order, method name (by <code>string_id</code>
218 index) is the intermediate order, and method
219 prototype (by <code>proto_id</code> index) is the minor order.
224 <td>class_def_item[]</td>
225 <td>class definitions list. The classes must be ordered such that a given
226 class's superclass and implemented interfaces appear in the
227 list earlier than the referring class.
233 <td>data area, containing all the support data for the tables listed above.
234 Different items have different alignment requirements, and
235 padding bytes are inserted before each item if necessary to achieve
242 <td>data used in statically linked files. The format of the data in
243 this section is left unspecified by this document;
244 this section is empty in unlinked files, and runtime implementations
245 may use it as they see fit.
251 <h1>Bitfield, String, and Constant Definitions</h1>
253 <h2><code>DEX_FILE_MAGIC</code></h2>
254 <h4>embedded in <code>header_item</code></h4>
256 <p>The constant array/string <code>DEX_FILE_MAGIC</code> is the list of
257 bytes that must appear at the beginning of a <code>.dex</code> file
258 in order for it to be recognized as such. The value intentionally
259 contains a newline (<code>"\n"</code> or <code>0x0a</code>) and a
260 null byte (<code>"\0"</code> or <code>0x00</code>) in order to help
261 in the detection of certain forms of corruption. The value also
262 encodes a format version number as three decimal digits, which is
263 expected to increase monotonically over time as the format evolves.</p>
266 ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x35 0x00 }
270 <p><b>Note:</b> At least a couple earlier versions of the format have
271 been used in widely-available public software releases. For example,
272 version <code>009</code> was used for the M3 releases of the
273 Android platform (November-December 2007),
274 and version <code>013</code> was used for the M5 releases of the Android
275 platform (February-March 2008). In several respects, these earlier versions
276 of the format differ significantly from the version described in this
279 <h2><code>ENDIAN_CONSTANT</code> and <code>REVERSE_ENDIAN_CONSTANT</code></h2>
280 <h4>embedded in <code>header_item</code></h4>
282 <p>The constant <code>ENDIAN_CONSTANT</code> is used to indicate the
283 endianness of the file in which it is found. Although the standard
284 <code>.dex</code> format is little-endian, implementations may choose
285 to perform byte-swapping. Should an implementation come across a
286 header whose <code>endian_tag</code> is <code>REVERSE_ENDIAN_CONSTANT</code>
287 instead of <code>ENDIAN_CONSTANT</code>, it would know that the file
288 has been byte-swapped from the expected form.</p>
291 uint ENDIAN_CONSTANT = 0x12345678;
292 uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
295 <h2><code>NO_INDEX</code></h2>
296 <h4>embedded in <code>class_def_item</code> and
297 <code>debug_info_item</code></h4>
299 <p>The constant <code>NO_INDEX</code> is used to indicate that
300 an index value is absent.</p>
302 <p><b>Note:</b> This value isn't defined to be
303 <code>0</code>, because that is in fact typically a valid index.</p>
305 <p><b>Also Note:</b> The chosen value for <code>NO_INDEX</code> is
306 representable as a single byte in the <code>uleb128p1</code> encoding.</p>
309 uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
312 <h2><code>access_flags</code> Definitions</h2>
313 <h4>embedded in <code>class_def_item</code>,
314 <code>field_item</code>, <code>method_item</code>, and
315 <code>InnerClass</code></h4>
317 <p>Bitfields of these flags are used to indicate the accessibility and
318 overall properties of classes and class members.</p>
320 <table class="accessFlags">
325 <th>For Classes (and <code>InnerClass</code> annotations)</th>
334 <td><code>public</code>: visible everywhere</td>
335 <td><code>public</code>: visible everywhere</td>
336 <td><code>public</code>: visible everywhere</td>
342 <code>private</code>: only visible to defining class
344 <td><code>private</code>: only visible to defining class</td>
345 <td><code>private</code>: only visible to defining class</td>
348 <td>ACC_PROTECTED</td>
351 <code>protected</code>: visible to package and subclasses
353 <td><code>protected</code>: visible to package and subclasses</td>
354 <td><code>protected</code>: visible to package and subclasses</td>
360 <code>static</code>: is not constructed with an outer
361 <code>this</code> reference</td>
362 <td><code>static</code>: global to defining class</td>
363 <td><code>static</code>: does not take a <code>this</code> argument</td>
368 <td><code>final</code>: not subclassable</td>
369 <td><code>final</code>: immutable after construction</td>
370 <td><code>final</code>: not overridable</td>
373 <td>ACC_SYNCHRONIZED</td>
377 <td><code>synchronized</code>: associated lock automatically acquired
378 around call to this method. <b>Note:</b> This is only valid to set when
379 <code>ACC_NATIVE</code> is also set.</td>
382 <td>ACC_VOLATILE</td>
385 <td><code>volatile</code>: special access rules to help with thread
394 <td>bridge method, added automatically by compiler as a type-safe
398 <td>ACC_TRANSIENT</td>
401 <td><code>transient</code>: not to be saved by default serialization</td>
409 <td>last argument should be treated as a "rest" argument by compiler</td>
416 <td><code>native</code>: implemented in native code</td>
419 <td>ACC_INTERFACE</td>
421 <td><code>interface</code>: multiply-implementable abstract class</td>
426 <td>ACC_ABSTRACT</td>
428 <td><code>abstract</code>: not directly instantiable</td>
430 <td><code>abstract</code>: unimplemented by this class</td>
437 <td><code>strictfp</code>: strict rules for floating-point arithmetic</td>
440 <td>ACC_SYNTHETIC</td>
442 <td>not directly defined in source code</td>
443 <td>not directly defined in source code</td>
444 <td>not directly defined in source code</td>
447 <td>ACC_ANNOTATION</td>
449 <td>declared as an annotation class</td>
456 <td>declared as an enumerated type</td>
457 <td>declared as an enumerated value</td>
461 <td><i>(unused)</i></td>
468 <td>ACC_CONSTRUCTOR</td>
472 <td>constructor method (class or instance initializer)</td>
475 <td>ACC_DECLARED_<br/>SYNCHRONIZED</td>
479 <td>declared <code>synchronized</code>. <b>Note:</b> This has no effect on
480 execution (other than in reflection of this flag, per se).
486 <p><super>*</super> Only allowed on for <code>InnerClass</code> annotations,
487 and must not ever be on in a <code>class_def_item</code>.</p>
489 <h2>MUTF-8 (Modified UTF-8) Encoding</h2>
491 <p>As a concession to easier legacy support, the <code>.dex</code> format
492 encodes its string data in a de facto standard modified UTF-8 form, hereafter
493 referred to as MUTF-8. This form is identical to standard UTF-8, except:</p>
496 <li>Only the one-, two-, and three-byte encodings are used.</li>
497 <li>Code points in the range <code>U+10000</code> …
498 <code>U+10ffff</code> are encoded as a surrogate pair, each of
499 which is represented as a three-byte encoded value.</li>
500 <li>The code point <code>U+0000</code> is encoded in two-byte form.</li>
501 <li>A plain null byte (value <code>0</code>) indicates the end of
502 a string, as is the standard C language interpretation.</li>
505 <p>The first two items above can be summarized as: MUTF-8
506 is an encoding format for UTF-16, instead of being a more direct
507 encoding format for Unicode characters.</p>
509 <p>The final two items above make it simultaneously possible to include
510 the code point <code>U+0000</code> in a string <i>and</i> still manipulate
511 it as a C-style null-terminated string.</p>
513 <p>However, the special encoding of <code>U+0000</code> means that, unlike
514 normal UTF-8, the result of calling the standard C function
515 <code>strcmp()</code> on a pair of MUTF-8 strings does not always
516 indicate the properly signed result of comparison of <i>unequal</i> strings.
517 When ordering (not just equality) is a concern, the most straightforward
518 way to compare MUTF-8 strings is to decode them character by character,
519 and compare the decoded values. (However, more clever implementations are
522 <p>Please refer to <a href="http://unicode.org">The Unicode
523 Standard</a> for further information about character encoding.
524 MUTF-8 is actually closer to the (relatively less well-known) encoding
525 <a href="http://www.unicode.org/reports/tr26/">CESU-8</a> than to UTF-8
528 <h2><code>encoded_value</code> Encoding</h2>
529 <h4>embedded in <code>annotation_element</code> and
530 <code>encoded_array_item</code></h4>
532 <p>An <code>encoded_value</code> is an encoded piece of (nearly)
533 arbitrary hierarchically structured data. The encoding is meant to
534 be both compact and straightforward to parse.</p>
536 <table class="format">
546 <td>(value_arg << 5) | value_type</td>
548 <td>byte indicating the type of the immediately subsequent
549 <code>value</code> along
550 with an optional clarifying argument in the high-order three bits.
551 See below for the various <code>value</code> definitions.
552 In most cases, <code>value_arg</code> encodes the length of
553 the immediately-subsequent <code>value</code> in bytes, as
554 <code>(size - 1)</code>, e.g., <code>0</code> means that
555 the value requires one byte, and <code>7</code> means it requires
556 eight bytes; however, there are exceptions as noted below.
562 <td>bytes representing the value, variable in length and interpreted
563 differently for different <code>value_type</code> bytes, though
564 always little-endian. See the various value definitions below for
571 <h3>Value Formats</h3>
573 <table class="encodedValue">
577 <th><code>value_type</code></th>
578 <th><code>value_arg</code> Format</th>
579 <th><code>value</code> Format</th>
587 <td><i>(none; must be <code>0</code>)</i></td>
589 <td>signed one-byte integer value</td>
594 <td>size - 1 (0…1)</td>
596 <td>signed two-byte integer value, sign-extended</td>
601 <td>size - 1 (0…1)</td>
603 <td>unsigned two-byte integer value, zero-extended</td>
608 <td>size - 1 (0…3)</td>
610 <td>signed four-byte integer value, sign-extended</td>
615 <td>size - 1 (0…7)</td>
617 <td>signed eight-byte integer value, sign-extended</td>
622 <td>size - 1 (0…3)</td>
624 <td>four-byte bit pattern, zero-extended <i>to the right</i>, and
625 interpreted as an IEEE754 32-bit floating point value
629 <td>VALUE_DOUBLE</td>
631 <td>size - 1 (0…7)</td>
633 <td>eight-byte bit pattern, zero-extended <i>to the right</i>, and
634 interpreted as an IEEE754 64-bit floating point value
638 <td>VALUE_STRING</td>
640 <td>size - 1 (0…3)</td>
642 <td>unsigned (zero-extended) four-byte integer value,
643 interpreted as an index into
644 the <code>string_ids</code> section and representing a string value
650 <td>size - 1 (0…3)</td>
652 <td>unsigned (zero-extended) four-byte integer value,
653 interpreted as an index into
654 the <code>type_ids</code> section and representing a reflective
661 <td>size - 1 (0…3)</td>
663 <td>unsigned (zero-extended) four-byte integer value,
664 interpreted as an index into
665 the <code>field_ids</code> section and representing a reflective
670 <td>VALUE_METHOD</td>
672 <td>size - 1 (0…3)</td>
674 <td>unsigned (zero-extended) four-byte integer value,
675 interpreted as an index into
676 the <code>method_ids</code> section and representing a reflective
683 <td>size - 1 (0…3)</td>
685 <td>unsigned (zero-extended) four-byte integer value,
686 interpreted as an index into
687 the <code>field_ids</code> section and representing the value of
688 an enumerated type constant
694 <td><i>(none; must be <code>0</code>)</i></td>
695 <td>encoded_array</td>
696 <td>an array of values, in the format specified by
697 "<code>encoded_array</code> Format" below. The size
698 of the <code>value</code> is implicit in the encoding.
702 <td>VALUE_ANNOTATION</td>
704 <td><i>(none; must be <code>0</code>)</i></td>
705 <td>encoded_annotation</td>
706 <td>a sub-annotation, in the format specified by
707 "<code>encoded_annotation</code> Format" below. The size
708 of the <code>value</code> is implicit in the encoding.
714 <td><i>(none; must be <code>0</code>)</i></td>
715 <td><i>(none)</i></td>
716 <td><code>null</code> reference value</td>
719 <td>VALUE_BOOLEAN</td>
721 <td>boolean (0…1)</td>
722 <td><i>(none)</i></td>
723 <td>one-bit value; <code>0</code> for <code>false</code> and
724 <code>1</code> for <code>true</code>. The bit is represented in the
725 <code>value_arg</code>.
731 <h3><code>encoded_array</code> Format</h3>
733 <table class="format">
745 <td>number of elements in the array</td>
749 <td>encoded_value[size]</td>
750 <td>a series of <code>size</code> <code>encoded_value</code> byte
751 sequences in the format specified by this section, concatenated
758 <h3><code>encoded_annotation</code> Format</h3>
760 <table class="format">
772 <td>type of the annotation. This must be a class (not array or primitive)
779 <td>number of name-value mappings in this annotation</td>
783 <td>annotation_element[size]</td>
784 <td>elements of the annotataion, represented directly in-line (not as
785 offsets). Elements must be sorted in increasing order by
786 <code>string_id</code> index.
792 <h3><code>annotation_element</code> Format</h3>
794 <table class="format">
806 <td>element name, represented as an index into the
807 <code>string_ids</code> section. The string must conform to the
808 syntax for <i>MemberName</i>, defined above.
813 <td>encoded_value</td>
814 <td>element value</td>
819 <h2>String Syntax</h2>
821 <p>There are several kinds of item in a <code>.dex</code> file which
822 ultimately refer to a string. The following BNF-style definitions
823 indicate the acceptable syntax for these strings.</p>
825 <h3><i>SimpleName</i></h3>
827 <p>A <i>SimpleName</i> is the basis for the syntax of the names of other
828 things. The <code>.dex</code> format allows a fair amount of latitude
829 here (much more than most common source languages). In brief, a simple
830 name may consist of any low-ASCII alphabetic character or digit, a few
831 specific low-ASCII symbols, and most non-ASCII code points that are not
832 control, space, or special characters. Note that surrogate code points
833 (in the range <code>U+d800</code> … <code>U+dfff</code>) are not
834 considered valid name characters, per se, but Unicode supplemental
835 characters <i>are</i> valid (which are represented by the final
836 alternative of the rule for <i>SimpleNameChar</i>), and they should be
837 represented in a file as pairs of surrogate code points in the MUTF-8
841 <tr><td colspan="2" class="def"><i>SimpleName</i> →</td></tr>
844 <td><i>SimpleNameChar</i> (<i>SimpleNameChar</i>)*</td>
847 <tr><td colspan="2" class="def"><i>SimpleNameChar</i> →</td></tr>
850 <td><code>'A'</code> … <code>'Z'</code></td>
853 <td class="bar">|</td>
854 <td><code>'a'</code> … <code>'z'</code></td>
857 <td class="bar">|</td>
858 <td><code>'0'</code> … <code>'9'</code></td>
861 <td class="bar">|</td>
862 <td><code>'$'</code></td>
865 <td class="bar">|</td>
866 <td><code>'-'</code></td>
869 <td class="bar">|</td>
870 <td><code>'_'</code></td>
873 <td class="bar">|</td>
874 <td><code>U+00a1</code> … <code>U+1fff</code></td>
877 <td class="bar">|</td>
878 <td><code>U+2010</code> … <code>U+2027</code></td>
881 <td class="bar">|</td>
882 <td><code>U+2030</code> … <code>U+d7ff</code></td>
885 <td class="bar">|</td>
886 <td><code>U+e000</code> … <code>U+ffef</code></td>
889 <td class="bar">|</td>
890 <td><code>U+10000</code> … <code>U+10ffff</code></td>
894 <h3><i>MemberName</i></h3>
895 <h4>used by <code>field_id_item</code> and <code>method_id_item</code></h4>
897 <p>A <i>MemberName</i> is the name of a member of a class, members being
898 fields, methods, and inner classes.</p>
901 <tr><td colspan="2" class="def"><i>MemberName</i> →</td></tr>
904 <td><i>SimpleName</i></td>
907 <td class="bar">|</td>
908 <td><code>'<'</code> <i>SimpleName</i> <code>'>'</code></td>
912 <h3><i>FullClassName</i></h3>
914 <p>A <i>FullClassName</i> is a fully-qualified class name, including an
915 optional package specifier followed by a required name.</p>
918 <tr><td colspan="2" class="def"><i>FullClassName</i> →</td></tr>
921 <td><i>OptionalPackagePrefix</i> <i>SimpleName</i></td>
924 <tr><td colspan="2" class="def"><i>OptionalPackagePrefix</i> →</td></tr>
927 <td>(<i>SimpleName</i> <code>'/'</code>)*</td>
931 <h3><i>TypeDescriptor</i></h3>
932 <h4>used by <code>type_id_item</code></h4>
934 <p>A <i>TypeDescriptor</i> is the representation of any type, including
935 primitives, classes, arrays, and <code>void</code>. See below for
936 the meaning of the various versions.</p>
939 <tr><td colspan="2" class="def"><i>TypeDescriptor</i> →</td></tr>
942 <td><code>'V'</code></td>
945 <td class="bar">|</td>
946 <td><i>FieldTypeDescriptor</i></td>
949 <tr><td colspan="2" class="def"><i>FieldTypeDescriptor</i> →</td></tr>
952 <td><i>NonArrayFieldTypeDescriptor</i></td>
955 <td class="bar">|</td>
956 <td>(<code>'['</code> * 1…255)
957 <i>NonArrayFieldTypeDescriptor</i></td>
961 <td colspan="2" class="def"><i>NonArrayFieldTypeDescriptor</i>→</td>
965 <td><code>'Z'</code></td>
968 <td class="bar">|</td>
969 <td><code>'B'</code></td>
972 <td class="bar">|</td>
973 <td><code>'S'</code></td>
976 <td class="bar">|</td>
977 <td><code>'C'</code></td>
980 <td class="bar">|</td>
981 <td><code>'I'</code></td>
984 <td class="bar">|</td>
985 <td><code>'J'</code></td>
988 <td class="bar">|</td>
989 <td><code>'F'</code></td>
992 <td class="bar">|</td>
993 <td><code>'D'</code></td>
996 <td class="bar">|</td>
997 <td><code>'L'</code> <i>FullClassName</i> <code>';'</code></td>
1001 <h3><i>ShortyDescriptor</i></h3>
1002 <h4>used by <code>proto_id_item</code></h4>
1004 <p>A <i>ShortyDescriptor</i> is the short form representation of a method
1005 prototype, including return and parameter types, except that there is
1006 no distinction between various reference (class or array) types. Instead,
1007 all reference types are represented by a single <code>'L'</code> character.</p>
1010 <tr><td colspan="2" class="def"><i>ShortyDescriptor</i> →</td></tr>
1013 <td><i>ShortyReturnType</i> (<i>ShortyFieldType</i>)*</td>
1016 <tr><td colspan="2" class="def"><i>ShortyReturnType</i> →</td></tr>
1019 <td><code>'V'</code></td>
1022 <td class="bar">|</td>
1023 <td><i>ShortyFieldType</i></td>
1026 <tr><td colspan="2" class="def"><i>ShortyFieldType</i> →</td></tr>
1029 <td><code>'Z'</code></td>
1032 <td class="bar">|</td>
1033 <td><code>'B'</code></td>
1036 <td class="bar">|</td>
1037 <td><code>'S'</code></td>
1040 <td class="bar">|</td>
1041 <td><code>'C'</code></td>
1044 <td class="bar">|</td>
1045 <td><code>'I'</code></td>
1048 <td class="bar">|</td>
1049 <td><code>'J'</code></td>
1052 <td class="bar">|</td>
1053 <td><code>'F'</code></td>
1056 <td class="bar">|</td>
1057 <td><code>'D'</code></td>
1060 <td class="bar">|</td>
1061 <td><code>'L'</code></td>
1065 <h2><i>TypeDescriptor</i> Semantics</h2>
1067 <p>This is the meaning of each of the variants of <i>TypeDescriptor</i>.</p>
1069 <table class="descriptor">
1079 <td><code>void</code>; only valid for return types</td>
1083 <td><code>boolean</code></td>
1087 <td><code>byte</code></td>
1091 <td><code>short</code></td>
1095 <td><code>char</code></td>
1099 <td><code>int</code></td>
1103 <td><code>long</code></td>
1107 <td><code>float</code></td>
1111 <td><code>double</code></td>
1114 <td>L<i>fully/qualified/Name</i>;</td>
1115 <td>the class <code><i>fully.qualified.Name</i></code></td>
1118 <td>[<i>descriptor</i></td>
1119 <td>array of <code><i>descriptor</i></code>, usable recursively for
1120 arrays-of-arrays, though it is invalid to have more than 255
1127 <h1>Items and Related Structures</h1>
1129 <p>This section includes definitions for each of the top-level items that
1130 may appear in a <code>.dex</code> file.
1132 <h2><code>header_item</code></h2>
1133 <h4>appears in the <code>header</code> section</h4>
1134 <h4>alignment: 4 bytes</h4>
1136 <table class="format">
1141 <th>Description</th>
1147 <td>ubyte[8] = DEX_FILE_MAGIC</td>
1148 <td>magic value. See discussion above under "<code>DEX_FILE_MAGIC</code>"
1155 <td>adler32 checksum of the rest of the file (everything but
1156 <code>magic</code> and this field); used to detect file corruption
1162 <td>SHA-1 signature (hash) of the rest of the file (everything but
1163 <code>magic</code>, <code>checksum</code>, and this field); used
1164 to uniquely identify files
1170 <td>size of the entire file (including the header), in bytes
1173 <td>header_size</td>
1174 <td>uint = 0x70</td>
1175 <td>size of the header (this entire section), in bytes. This allows for at
1176 least a limited amount of backwards/forwards compatibility without
1177 invalidating the format.
1182 <td>uint = ENDIAN_CONSTANT</td>
1183 <td>endianness tag. See discussion above under "<code>ENDIAN_CONSTANT</code>
1184 and <code>REVERSE_ENDIAN_CONSTANT</code>" for more details.
1190 <td>size of the link section, or <code>0</code> if this file isn't
1191 statically linked</td>
1196 <td>offset from the start of the file to the link section, or
1197 <code>0</code> if <code>link_size == 0</code>. The offset, if non-zero,
1198 should be to an offset into the <code>link_data</code> section. The
1199 format of the data pointed at is left unspecified by this document;
1200 this header field (and the previous) are left as hooks for use by
1201 runtime implementations.
1207 <td>offset from the start of the file to the map item, or
1208 <code>0</code> if this file has no map. The offset, if non-zero,
1209 should be to an offset into the <code>data</code> section,
1210 and the data should be in the format specified by "<code>map_list</code>"
1215 <td>string_ids_size</td>
1217 <td>count of strings in the string identifiers list</td>
1220 <td>string_ids_off</td>
1222 <td>offset from the start of the file to the string identifiers list, or
1223 <code>0</code> if <code>string_ids_size == 0</code> (admittedly a
1224 strange edge case). The offset, if non-zero,
1225 should be to the start of the <code>string_ids</code> section.
1229 <td>type_ids_size</td>
1231 <td>count of elements in the type identifiers list</td>
1234 <td>type_ids_off</td>
1236 <td>offset from the start of the file to the type identifiers list, or
1237 <code>0</code> if <code>type_ids_size == 0</code> (admittedly a
1238 strange edge case). The offset, if non-zero,
1239 should be to the start of the <code>type_ids</code>
1244 <td>proto_ids_size</td>
1246 <td>count of elements in the prototype identifiers list</td>
1249 <td>proto_ids_off</td>
1251 <td>offset from the start of the file to the prototype identifiers list, or
1252 <code>0</code> if <code>proto_ids_size == 0</code> (admittedly a
1253 strange edge case). The offset, if non-zero,
1254 should be to the start of the <code>proto_ids</code>
1259 <td>field_ids_size</td>
1261 <td>count of elements in the field identifiers list</td>
1264 <td>field_ids_off</td>
1266 <td>offset from the start of the file to the field identifiers list, or
1267 <code>0</code> if <code>field_ids_size == 0</code>. The offset, if
1268 non-zero, should be to the start of the <code>field_ids</code>
1273 <td>method_ids_size</td>
1275 <td>count of elements in the method identifiers list</td>
1278 <td>method_ids_off</td>
1280 <td>offset from the start of the file to the method identifiers list, or
1281 <code>0</code> if <code>method_ids_size == 0</code>. The offset, if
1282 non-zero, should be to the start of the <code>method_ids</code>
1286 <td>class_defs_size</td>
1288 <td>count of elements in the class definitions list</td>
1291 <td>class_defs_off</td>
1293 <td>offset from the start of the file to the class definitions list, or
1294 <code>0</code> if <code>class_defs_size == 0</code> (admittedly a
1295 strange edge case). The offset, if non-zero,
1296 should be to the start of the <code>class_defs</code> section.
1302 <td>Size of <code>data</code> section in bytes. Must be an even
1303 multiple of sizeof(uint).</td>
1308 <td>offset from the start of the file to the start of the
1309 <code>data</code> section.
1315 <h2><code>map_list</code></h2>
1316 <h4>appears in the <code>data</code> section</h4>
1317 <h4>referenced from <code>header_item</code></h4>
1318 <h4>alignment: 4 bytes</h4>
1320 <p>This is a list of the entire contents of a file, in order. It
1321 contains some redundancy with respect to the <code>header_item</code>
1322 but is intended to be an easy form to use to iterate over an entire
1323 file. A given type may appear at most once in a map, but there is no
1324 restriction on what order types may appear in, other than the
1325 restrictions implied by the rest of the format (e.g., a
1326 <code>header</code> section must appear first, followed by a
1327 <code>string_ids</code> section, etc.). Additionally, the map entries must
1328 be ordered by initial offset and must not overlap.</p>
1330 <table class="format">
1335 <th>Description</th>
1342 <td>size of the list, in entries</td>
1346 <td>map_item[size]</td>
1347 <td>elements of the list</td>
1352 <h3><code>map_item</code> Format</h3>
1354 <table class="format">
1359 <th>Description</th>
1366 <td>type of the items; see table below</td>
1371 <td><i>(unused)</i></td>
1376 <td>count of the number of items to be found at the indicated offset</td>
1381 <td>offset from the start of the file to the items in question</td>
1389 <table class="typeCodes">
1395 <th>Item Size In Bytes</th>
1400 <td>header_item</td>
1401 <td>TYPE_HEADER_ITEM</td>
1406 <td>string_id_item</td>
1407 <td>TYPE_STRING_ID_ITEM</td>
1412 <td>type_id_item</td>
1413 <td>TYPE_TYPE_ID_ITEM</td>
1418 <td>proto_id_item</td>
1419 <td>TYPE_PROTO_ID_ITEM</td>
1424 <td>field_id_item</td>
1425 <td>TYPE_FIELD_ID_ITEM</td>
1430 <td>method_id_item</td>
1431 <td>TYPE_METHOD_ID_ITEM</td>
1436 <td>class_def_item</td>
1437 <td>TYPE_CLASS_DEF_ITEM</td>
1443 <td>TYPE_MAP_LIST</td>
1445 <td>4 + (item.size * 12)</td>
1449 <td>TYPE_TYPE_LIST</td>
1451 <td>4 + (item.size * 2)</td>
1454 <td>annotation_set_ref_list</td>
1455 <td>TYPE_ANNOTATION_SET_REF_LIST</td>
1457 <td>4 + (item.size * 4)</td>
1460 <td>annotation_set_item</td>
1461 <td>TYPE_ANNOTATION_SET_ITEM</td>
1463 <td>4 + (item.size * 4)</td>
1466 <td>class_data_item</td>
1467 <td>TYPE_CLASS_DATA_ITEM</td>
1469 <td><i>implicit; must parse</i></td>
1473 <td>TYPE_CODE_ITEM</td>
1475 <td><i>implicit; must parse</i></td>
1478 <td>string_data_item</td>
1479 <td>TYPE_STRING_DATA_ITEM</td>
1481 <td><i>implicit; must parse</i></td>
1484 <td>debug_info_item</td>
1485 <td>TYPE_DEBUG_INFO_ITEM</td>
1487 <td><i>implicit; must parse</i></td>
1490 <td>annotation_item</td>
1491 <td>TYPE_ANNOTATION_ITEM</td>
1493 <td><i>implicit; must parse</i></td>
1496 <td>encoded_array_item</td>
1497 <td>TYPE_ENCODED_ARRAY_ITEM</td>
1499 <td><i>implicit; must parse</i></td>
1502 <td>annotations_directory_item</td>
1503 <td>TYPE_ANNOTATIONS_DIRECTORY_ITEM</td>
1505 <td><i>implicit; must parse</i></td>
1511 <h2><code>string_id_item</code></h2>
1512 <h4>appears in the <code>string_ids</code> section</h4>
1513 <h4>alignment: 4 bytes</h4>
1515 <table class="format">
1520 <th>Description</th>
1525 <td>string_data_off</td>
1527 <td>offset from the start of the file to the string data for this
1528 item. The offset should be to a location
1529 in the <code>data</code> section, and the data should be in the
1530 format specified by "<code>string_data_item</code>" below.
1531 There is no alignment requirement for the offset.
1537 <h2><code>string_data_item</code></h2>
1538 <h4>appears in the <code>data</code> section</h4>
1539 <h4>alignment: none (byte-aligned)</h4>
1541 <table class="format">
1546 <th>Description</th>
1553 <td>size of this string, in UTF-16 code units (which is the "string
1554 length" in many systems). That is, this is the decoded length of
1555 the string. (The encoded length is implied by the position of
1556 the <code>0</code> byte.)</td>
1561 <td>a series of MUTF-8 code units (a.k.a. octets, a.k.a. bytes)
1562 followed by a byte of value <code>0</code>. See
1563 "MUTF-8 (Modified UTF-8) Encoding" above for details and
1564 discussion about the data format.
1565 <p><b>Note:</b> It is acceptable to have a string which includes
1566 (the encoded form of) UTF-16 surrogate code units (that is,
1567 <code>U+d800</code> … <code>U+dfff</code>)
1568 either in isolation or out-of-order with respect to the usual
1569 encoding of Unicode into UTF-16. It is up to higher-level uses of
1570 strings to reject such invalid encodings, if appropriate.</p>
1576 <h2><code>type_id_item</code></h2>
1577 <h4>appears in the <code>type_ids</code> section</h4>
1578 <h4>alignment: 4 bytes</h4>
1580 <table class="format">
1585 <th>Description</th>
1590 <td>descriptor_idx</td>
1592 <td>index into the <code>string_ids</code> list for the descriptor
1593 string of this type. The string must conform to the syntax for
1594 <i>TypeDescriptor</i>, defined above.
1600 <h2><code>proto_id_item</code></h2>
1601 <h4>appears in the <code>proto_ids</code> section</h4>
1602 <h4>alignment: 4 bytes</h4>
1604 <table class="format">
1609 <th>Description</th>
1616 <td>index into the <code>string_ids</code> list for the short-form
1617 descriptor string of this prototype. The string must conform to the
1618 syntax for <i>ShortyDescriptor</i>, defined above, and must correspond
1619 to the return type and parameters of this item.
1623 <td>return_type_idx</td>
1625 <td>index into the <code>type_ids</code> list for the return type
1630 <td>parameters_off</td>
1632 <td>offset from the start of the file to the list of parameter types
1633 for this prototype, or <code>0</code> if this prototype has no
1634 parameters. This offset, if non-zero, should be in the
1635 <code>data</code> section, and the data there should be in the
1636 format specified by <code>"type_list"</code> below. Additionally, there
1637 should be no reference to the type <code>void</code> in the list.
1643 <h2><code>field_id_item</code></h2>
1644 <h4>appears in the <code>field_ids</code> section</h4>
1645 <h4>alignment: 4 bytes</h4>
1647 <table class="format">
1652 <th>Description</th>
1659 <td>index into the <code>type_ids</code> list for the definer of this
1660 field. This must be a class type, and not an array or primitive type.
1666 <td>index into the <code>type_ids</code> list for the type of
1673 <td>index into the <code>string_ids</code> list for the name of this
1674 field. The string must conform to the syntax for <i>MemberName</i>,
1681 <h2><code>method_id_item</code></h2>
1682 <h4>appears in the <code>method_ids</code> section</h4>
1683 <h4>alignment: 4 bytes</h4>
1685 <table class="format">
1690 <th>Description</th>
1697 <td>index into the <code>type_ids</code> list for the definer of this
1698 method. This must be a class or array type, and not a primitive type.
1704 <td>index into the <code>proto_ids</code> list for the prototype of
1711 <td>index into the <code>string_ids</code> list for the name of this
1712 method. The string must conform to the syntax for <i>MemberName</i>,
1719 <h2><code>class_def_item</code></h2>
1720 <h4>appears in the <code>class_defs</code> section</h4>
1721 <h4>alignment: 4 bytes</h4>
1723 <table class="format">
1728 <th>Description</th>
1735 <td>index into the <code>type_ids</code> list for this class.
1736 This must be a class type, and not an array or primitive type.
1740 <td>access_flags</td>
1742 <td>access flags for the class (<code>public</code>, <code>final</code>,
1743 etc.). See "<code>access_flags</code> Definitions" for details.
1747 <td>superclass_idx</td>
1749 <td>index into the <code>type_ids</code> list for the superclass, or
1750 the constant value <code>NO_INDEX</code> if this class has no
1751 superclass (i.e., it is a root class such as <code>Object</code>).
1752 If present, this must be a class type, and not an array or primitive type.
1756 <td>interfaces_off</td>
1758 <td>offset from the start of the file to the list of interfaces, or
1759 <code>0</code> if there are none. This offset
1760 should be in the <code>data</code> section, and the data
1761 there should be in the format specified by
1762 "<code>type_list</code>" below. Each of the elements of the list
1763 must be a class type (not an array or primitive type), and there
1764 must not be any duplicates.
1768 <td>source_file_idx</td>
1770 <td>index into the <code>string_ids</code> list for the name of the
1771 file containing the original source for (at least most of) this class,
1772 or the special value <code>NO_INDEX</code> to represent a lack of
1773 this information. The <code>debug_info_item</code> of any given method
1774 may override this source file, but the expectation is that most classes
1775 will only come from one source file.
1779 <td>annotations_off</td>
1781 <td>offset from the start of the file to the annotations structure
1782 for this class, or <code>0</code> if there are no annotations on
1783 this class. This offset, if non-zero, should be in the
1784 <code>data</code> section, and the data there should be in
1785 the format specified by "<code>annotations_directory_item</code>" below,
1786 with all items referring to this class as the definer.
1790 <td>class_data_off</td>
1792 <td>offset from the start of the file to the associated
1793 class data for this item, or <code>0</code> if there is no class
1794 data for this class. (This may be the case, for example, if this class
1795 is a marker interface.) The offset, if non-zero, should be in the
1796 <code>data</code> section, and the data there should be in the
1797 format specified by "<code>class_data_item</code>" below, with all
1798 items referring to this class as the definer.
1802 <td>static_values_off</td>
1804 <td>offset from the start of the file to the list of initial
1805 values for <code>static</code> fields, or <code>0</code> if there
1806 are none (and all <code>static</code> fields are to be initialized with
1807 <code>0</code> or <code>null</code>). This offset should be in the
1808 <code>data</code> section, and the data there should be in the
1809 format specified by "<code>encoded_array_item</code>" below. The size
1810 of the array must be no larger than the number of <code>static</code>
1811 fields declared by this class, and the elements correspond to the
1812 <code>static</code> fields in the same order as declared in the
1813 corresponding <code>field_list</code>. The type of each array
1814 element must match the declared type of its corresponding field.
1815 If there are fewer elements in the array than there are
1816 <code>static</code> fields, then the leftover fields are initialized
1817 with a type-appropriate <code>0</code> or <code>null</code>.
1823 <h2><code>class_data_item</code></h2>
1824 <h4>referenced from <code>class_def_item</code></h4>
1825 <h4>appears in the <code>data</code> section</h4>
1826 <h4>alignment: none (byte-aligned)</h4>
1828 <table class="format">
1833 <th>Description</th>
1838 <td>static_fields_size</td>
1840 <td>the number of static fields defined in this item</td>
1843 <td>instance_fields_size</td>
1845 <td>the number of instance fields defined in this item</td>
1848 <td>direct_methods_size</td>
1850 <td>the number of direct methods defined in this item</td>
1853 <td>virtual_methods_size</td>
1855 <td>the number of virtual methods defined in this item</td>
1858 <td>static_fields</td>
1859 <td>encoded_field[static_fields_size]</td>
1860 <td>the defined static fields, represented as a sequence of
1861 encoded elements. The fields must be sorted by
1862 <code>field_idx</code> in increasing order.
1866 <td>instance_fields</td>
1867 <td>encoded_field[instance_fields_size]</td>
1868 <td>the defined instance fields, represented as a sequence of
1869 encoded elements. The fields must be sorted by
1870 <code>field_idx</code> in increasing order.
1874 <td>direct_methods</td>
1875 <td>encoded_method[direct_methods_size]</td>
1876 <td>the defined direct (any of <code>static</code>, <code>private</code>,
1877 or constructor) methods, represented as a sequence of
1878 encoded elements. The methods must be sorted by
1879 <code>method_idx</code> in increasing order.
1883 <td>virtual_methods</td>
1884 <td>encoded_method[virtual_methods_size]</td>
1885 <td>the defined virtual (none of <code>static</code>, <code>private</code>,
1886 or constructor) methods, represented as a sequence of
1887 encoded elements. This list should <i>not</i> include inherited
1888 methods unless overridden by the class that this item represents. The
1889 methods must be sorted by <code>method_idx</code> in increasing order.
1895 <p><b>Note:</b> All elements' <code>field_id</code>s and
1896 <code>method_id</code>s must refer to the same defining class.</p>
1898 <h3><code>encoded_field</code> Format</h3>
1900 <table class="format">
1905 <th>Description</th>
1910 <td>field_idx_diff</td>
1912 <td>index into the <code>field_ids</code> list for the identity of this
1913 field (includes the name and descriptor), represented as a difference
1914 from the index of previous element in the list. The index of the
1915 first element in a list is represented directly.
1919 <td>access_flags</td>
1921 <td>access flags for the field (<code>public</code>, <code>final</code>,
1922 etc.). See "<code>access_flags</code> Definitions" for details.
1928 <h3><code>encoded_method</code> Format</h3>
1930 <table class="format">
1935 <th>Description</th>
1940 <td>method_idx_diff</td>
1942 <td>index into the <code>method_ids</code> list for the identity of this
1943 method (includes the name and descriptor), represented as a difference
1944 from the index of previous element in the list. The index of the
1945 first element in a list is represented directly.
1949 <td>access_flags</td>
1951 <td>access flags for the method (<code>public</code>, <code>final</code>,
1952 etc.). See "<code>access_flags</code> Definitions" for details.
1958 <td>offset from the start of the file to the code structure for this
1959 method, or <code>0</code> if this method is either <code>abstract</code>
1960 or <code>native</code>. The offset should be to a location in the
1961 <code>data</code> section. The format of the data is specified by
1962 "<code>code_item</code>" below.
1968 <h2><code>type_list</code></h2>
1969 <h4>referenced from <code>class_def_item</code> and
1970 <code>proto_id_item</code></h4>
1971 <h4>appears in the <code>data</code> section</h4>
1972 <h4>alignment: 4 bytes</h4>
1974 <table class="format">
1979 <th>Description</th>
1986 <td>size of the list, in entries</td>
1990 <td>type_item[size]</td>
1991 <td>elements of the list</td>
1996 <h3><code>type_item</code> Format</h3>
1998 <table class="format">
2003 <th>Description</th>
2010 <td>index into the <code>type_ids</code> list</td>
2015 <h2><code>code_item</code></h2>
2016 <h4>referenced from <code>method_item</code></h4>
2017 <h4>appears in the <code>data</code> section</h4>
2018 <h4>alignment: 4 bytes</h4>
2020 <table class="format">
2025 <th>Description</th>
2030 <td>registers_size</td>
2032 <td>the number of registers used by this code</td>
2037 <td>the number of words of incoming arguments to the method that this
2043 <td>the number of words of outgoing argument space required by this
2044 code for method invocation
2050 <td>the number of <code>try_item</code>s for this instance. If non-zero,
2051 then these appear as the <code>tries</code> array just after the
2052 <code>insns</code> in this instance.
2056 <td>debug_info_off</td>
2058 <td>offset from the start of the file to the debug info (line numbers +
2059 local variable info) sequence for this code, or <code>0</code> if
2060 there simply is no information. The offset, if non-zero, should be
2061 to a location in the <code>data</code> section. The format of
2062 the data is specified by "<code>debug_info_item</code>" below.
2068 <td>size of the instructions list, in 16-bit code units</td>
2072 <td>ushort[insns_size]</td>
2073 <td>actual array of bytecode. The format of code in an <code>insns</code>
2074 array is specified by the companion document
2075 <a href="dalvik-bytecode.html">"Bytecode for the Dalvik VM"</a>. Note
2076 that though this is defined as an array of <code>ushort</code>, there
2077 are some internal structures that prefer four-byte alignment. Also,
2078 if this happens to be in an endian-swapped file, then the swapping is
2079 <i>only</i> done on individual <code>ushort</code>s and not on the
2080 larger internal structures.
2085 <td>ushort <i>(optional)</i> = 0</td>
2086 <td>two bytes of padding to make <code>tries</code> four-byte aligned.
2087 This element is only present if <code>tries_size</code> is non-zero
2088 and <code>insns_size</code> is odd.
2093 <td>try_item[tries_size] <i>(optional)</i></td>
2094 <td>array indicating where in the code exceptions may be caught and
2095 how to handle them. Elements of the array must be non-overlapping in
2096 range and in order from low to high address. This element is only
2097 present if <code>tries_size</code> is non-zero.
2102 <td>encoded_catch_handler_list <i>(optional)</i></td>
2103 <td>bytes representing a list of lists of catch types and associated
2104 handler addresses. Each <code>try_item</code> has a byte-wise offset
2105 into this structure. This element is only present if
2106 <code>tries_size</code> is non-zero.
2112 <h3><code>try_item</code> Format </h3>
2114 <table class="format">
2119 <th>Description</th>
2126 <td>start address of the block of code covered by this entry. The address
2127 is a count of 16-bit code units to the start of the first covered
2134 <td>number of 16-bit code units covered by this entry. The last code
2135 unit covered (inclusive) is <code>start_addr + insn_count - 1</code>.
2139 <td>handler_off</td>
2141 <td>offset in bytes from the start of the associated encoded handler data
2142 to the <code>catch_handler_item</code> for this entry
2148 <h3><code>encoded_catch_handler_list</code> Format</h3>
2150 <table class="format">
2155 <th>Description</th>
2162 <td>size of this list, in entries</td>
2166 <td>encoded_catch_handler[handlers_size]</td>
2167 <td>actual list of handler lists, represented directly (not as offsets),
2168 and concatenated sequentially</td>
2173 <h3><code>encoded_catch_handler</code> Format</h3>
2175 <table class="format">
2180 <th>Description</th>
2187 <td>number of catch types in this list. If non-positive, then this is
2188 the negative of the number of catch types, and the catches are followed
2189 by a catch-all handler. For example: A <code>size</code> of <code>0</code>
2190 means that there is a catch-all but no explicitly typed catches.
2191 A <code>size</code> of <code>2</code> means that there are two explicitly
2192 typed catches and no catch-all. And a <code>size</code> of <code>-1</code>
2193 means that there is one typed catch along with a catch-all.
2198 <td>encoded_type_addr_pair[abs(size)]</td>
2199 <td>stream of <code>abs(size)</code> encoded items, one for each caught
2200 type, in the order that the types should be tested.
2204 <td>catch_all_addr</td>
2205 <td>uleb128 <i>(optional)</i></td>
2206 <td>bytecode address of the catch-all handler. This element is only
2207 present if <code>size</code> is non-positive.
2213 <h3><code>encoded_type_addr_pair</code> Format</h3>
2215 <table class="format">
2220 <th>Description</th>
2227 <td>index into the <code>type_ids</code> list for the type of the
2234 <td>bytecode address of the associated exception handler</td>
2239 <h2><code>debug_info_item</code></h2>
2240 <h4>referenced from <code>code_item</code></h4>
2241 <h4>appears in the <code>data</code> section</h4>
2242 <h4>alignment: none (byte-aligned)</h4>
2244 <p>Each <code>debug_info_item</code> defines a DWARF3-inspired byte-coded
2245 state machine that, when interpreted, emits the positions
2246 table and (potentially) the local variable information for a
2247 <code>code_item</code>. The sequence begins with a variable-length
2248 header (the length of which depends on the number of method
2249 parameters), is followed by the state machine bytecodes, and ends
2250 with an <code>DBG_END_SEQUENCE</code> byte.</p>
2252 <p>The state machine consists of five registers. The
2253 <code>address</code> register represents the instruction offset in the
2254 associated <code>insns_item</code> in 16-bit code units. The
2255 <code>address</code> register starts at <code>0</code> at the beginning of each
2256 <code>debug_info</code> sequence and may only monotonically increase.
2257 The <code>line</code> register represents what source line number
2258 should be associated with the next positions table entry emitted by
2259 the state machine. It is initialized in the sequence header, and may
2260 change in positive or negative directions but must never be less than
2261 <code>1</code>. The <code>source_file</code> register represents the
2262 source file that the line number entries refer to. It is initialized to
2263 the value of <code>source_file_idx</code> in <code>class_def_item</code>.
2264 The other two variables, <code>prologue_end</code> and
2265 <code>epilogue_begin</code>, are boolean flags (initialized to
2266 <code>false</code>) that indicate whether the next position emitted
2267 should be considered a method prologue or epilogue. The state machine
2268 must also track the name and type of the last local variable live in
2269 each register for the <code>DBG_RESTART_LOCAL</code> code.</p>
2271 <p>The header is as follows:</p>
2273 <table class="format">
2278 <th>Description</th>
2285 <td>the initial value for the state machine's <code>line</code> register.
2286 Does not represent an actual positions entry.
2290 <td>parameters_size</td>
2292 <td>the number of parameter names that are encoded. There should be
2293 one per method parameter, excluding an instance method's <code>this</code>,
2298 <td>parameter_names</td>
2299 <td>uleb128p1[parameters_size]</td>
2300 <td>string index of the method parameter name. An encoded value of
2301 <code>NO_INDEX</code> indicates that no name
2302 is available for the associated parameter. The type descriptor
2303 and signature are implied from the method descriptor and signature.
2309 <p>The byte code values are as follows:</p>
2311 <table class="debugByteCode">
2318 <th>Description</th>
2323 <td>DBG_END_SEQUENCE</td>
2326 <td><i>(none)</i></td>
2327 <td>terminates a debug info sequence for a <code>code_item</code></td>
2330 <td>DBG_ADVANCE_PC</td>
2332 <td>uleb128 addr_diff</td>
2333 <td><code>addr_diff</code>: amount to add to address register</td>
2334 <td>advances the address register without emitting a positions entry</td>
2337 <td>DBG_ADVANCE_LINE</td>
2339 <td>sleb128 line_diff</td>
2340 <td><code>line_diff</code>: amount to change line register by</td>
2341 <td>advances the line register without emitting a positions entry</td>
2344 <td>DBG_START_LOCAL</td>
2346 <td>uleb128 register_num<br/>
2347 uleb128p1 name_idx<br/>
2348 uleb128p1 type_idx
2350 <td><code>register_num</code>: register that will contain local<br/>
2351 <code>name_idx</code>: string index of the name<br/>
2352 <code>type_idx</code>: type index of the type
2354 <td>introduces a local variable at the current address. Either
2355 <code>name_idx</code> or <code>type_idx</code> may be
2356 <code>NO_INDEX</code> to indicate that that value is unknown.
2360 <td>DBG_START_LOCAL_EXTENDED</td>
2362 <td>uleb128 register_num<br/>
2363 uleb128p1 name_idx<br/>
2364 uleb128p1 type_idx<br/>
2365 uleb128p1 sig_idx
2367 <td><code>register_num</code>: register that will contain local<br/>
2368 <code>name_idx</code>: string index of the name<br/>
2369 <code>type_idx</code>: type index of the type<br/>
2370 <code>sig_idx</code>: string index of the type signature
2372 <td>introduces a local with a type signature at the current address.
2373 Any of <code>name_idx</code>, <code>type_idx</code>, or
2374 <code>sig_idx</code> may be <code>NO_INDEX</code>
2375 to indicate that that value is unknown. (If <code>sig_idx</code> is
2376 <code>-1</code>, though, the same data could be represented more
2377 efficiently using the opcode <code>DBG_START_LOCAL</code>.)
2378 <p><b>Note:</b> See the discussion under
2379 "<code>dalvik.annotation.Signature</code>" below for caveats about
2380 handling signatures.</p>
2384 <td>DBG_END_LOCAL</td>
2386 <td>uleb128 register_num</td>
2387 <td><code>register_num</code>: register that contained local</td>
2388 <td>marks a currently-live local variable as out of scope at the current
2393 <td>DBG_RESTART_LOCAL</td>
2395 <td>uleb128 register_num</td>
2396 <td><code>register_num</code>: register to restart</td>
2397 <td>re-introduces a local variable at the current address. The name
2398 and type are the same as the last local that was live in the specified
2403 <td>DBG_SET_PROLOGUE_END</td>
2406 <td><i>(none)</i></td>
2407 <td>sets the <code>prologue_end</code> state machine register,
2408 indicating that the next position entry that is added should be
2409 considered the end of a method prologue (an appropriate place for
2410 a method breakpoint). The <code>prologue_end</code> register is
2411 cleared by any special (<code>>= 0x0a</code>) opcode.
2415 <td>DBG_SET_EPILOGUE_BEGIN</td>
2418 <td><i>(none)</i></td>
2419 <td>sets the <code>epilogue_begin</code> state machine register,
2420 indicating that the next position entry that is added should be
2421 considered the beginning of a method epilogue (an appropriate place
2422 to suspend execution before method exit).
2423 The <code>epilogue_begin</code> register is cleared by any special
2424 (<code>>= 0x0a</code>) opcode.
2428 <td>DBG_SET_FILE</td>
2430 <td>uleb128p1 name_idx</td>
2431 <td><code>name_idx</code>: string index of source file name;
2432 <code>NO_INDEX</code> if unknown
2434 <td>indicates that all subsequent line number entries make reference to this
2435 source file name, instead of the default name specified in
2436 <code>code_item</code>
2440 <td><i>Special Opcodes</i></td>
2441 <!-- When updating the range below, make sure to search for other
2442 instances of 0x0a in this section. -->
2443 <td>0x0a…0xff</td>
2445 <td><i>(none)</i></td>
2446 <td>advances the <code>line</code> and <code>address</code> registers,
2447 emits a position entry, and clears <code>prologue_end</code> and
2448 <code>epilogue_begin</code>. See below for description.
2454 <h3>Special Opcodes</h3>
2456 <p>Opcodes with values between <code>0x0a</code> and <code>0xff</code>
2457 (inclusive) move both the <code>line</code> and <code>address</code>
2458 registers by a small amount and then emit a new position table entry.
2459 The formula for the increments are as follows:</p>
2462 DBG_FIRST_SPECIAL = 0x0a // the smallest special opcode
2463 DBG_LINE_BASE = -4 // the smallest line number increment
2464 DBG_LINE_RANGE = 15 // the number of line increments represented
2466 adjusted_opcode = opcode - DBG_FIRST_SPECIAL
2468 line += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE)
2469 address += (adjusted_opcode / DBG_LINE_RANGE)
2472 <h2><code>annotations_directory_item</code></h2>
2473 <h4>referenced from <code>class_def_item</code></h4>
2474 <h4>appears in the <code>data</code> section</h4>
2475 <h4>alignment: 4 bytes</h4>
2477 <table class="format">
2482 <th>Description</th>
2487 <td>class_annotations_off</td>
2489 <td>offset from the start of the file to the annotations made directly
2490 on the class, or <code>0</code> if the class has no direct annotations.
2491 The offset, if non-zero, should be to a location in the
2492 <code>data</code> section. The format of the data is specified
2493 by "<code>annotation_set_item</code>" below.
2497 <td>fields_size</td>
2499 <td>count of fields annotated by this item</td>
2502 <td>annotated_methods_size</td>
2504 <td>count of methods annotated by this item</td>
2507 <td>annotated_parameters_size</td>
2509 <td>count of method parameter lists annotated by this item</td>
2512 <td>field_annotations</td>
2513 <td>field_annotation[fields_size] <i>(optional)</i></td>
2514 <td>list of associated field annotations. The elements of the list must
2515 be sorted in increasing order, by <code>field_idx</code>.
2519 <td>method_annotations</td>
2520 <td>method_annotation[methods_size] <i>(optional)</i></td>
2521 <td>list of associated method annotations. The elements of the list must
2522 be sorted in increasing order, by <code>method_idx</code>.
2526 <td>parameter_annotations</td>
2527 <td>parameter_annotation[parameters_size] <i>(optional)</i></td>
2528 <td>list of associated method parameter annotations. The elements of the
2529 list must be sorted in increasing order, by <code>method_idx</code>.
2535 <p><b>Note:</b> All elements' <code>field_id</code>s and
2536 <code>method_id</code>s must refer to the same defining class.</p>
2538 <h3><code>field_annotation</code> Format</h3>
2540 <table class="format">
2545 <th>Description</th>
2552 <td>index into the <code>field_ids</code> list for the identity of the
2553 field being annotated
2557 <td>annotations_off</td>
2559 <td>offset from the start of the file to the list of annotations for
2560 the field. The offset should be to a location in the <code>data</code>
2561 section. The format of the data is specified by
2562 "<code>annotation_set_item</code>" below.
2568 <h3><code>method_annotation</code> Format</h3>
2570 <table class="format">
2575 <th>Description</th>
2582 <td>index into the <code>method_ids</code> list for the identity of the
2583 method being annotated
2587 <td>annotations_off</td>
2589 <td>offset from the start of the file to the list of annotations for
2590 the method. The offset should be to a location in the
2591 <code>data</code> section. The format of the data is specified by
2592 "<code>annotation_set_item</code>" below.
2598 <h3><code>parameter_annotation</code> Format</h2>
2600 <table class="format">
2605 <th>Description</th>
2612 <td>index into the <code>method_ids</code> list for the identity of the
2613 method whose parameters are being annotated
2617 <td>annotations_off</td>
2619 <td>offset from the start of the file to the list of annotations for
2620 the method parameters. The offset should be to a location in the
2621 <code>data</code> section. The format of the data is specified by
2622 "<code>annotation_set_ref_list</code>" below.
2628 <h2><code>annotation_set_ref_list</code></h2>
2629 <h4>referenced from <code>parameter_annotations_item</code></h4>
2630 <h4>appears in the <code>data</code> section</h4>
2631 <h4>alignment: 4 bytes</h4>
2633 <table class="format">
2638 <th>Description</th>
2645 <td>size of the list, in entries</td>
2649 <td>annotation_set_ref_item[size]</td>
2650 <td>elements of the list</td>
2655 <h3><code>annotation_set_ref_item</code> Format</h3>
2657 <table class="format">
2662 <th>Description</th>
2667 <td>annotations_off</td>
2669 <td>offset from the start of the file to the referenced annotation set
2670 or <code>0</code> if there are no annotations for this element.
2671 The offset, if non-zero, should be to a location in the <code>data</code>
2672 section. The format of the data is specified by
2673 "<code>annotation_set_item</code>" below.
2679 <h2><code>annotation_set_item</code></h2>
2680 <h4>referenced from <code>annotations_directory_item</code>,
2681 <code>field_annotations_item</code>,
2682 <code>method_annotations_item</code>, and
2683 <code>annotation_set_ref_item</code></h4>
2684 <h4>appears in the <code>data</code> section</h4>
2685 <h4>alignment: 4 bytes</h4>
2687 <table class="format">
2692 <th>Description</th>
2699 <td>size of the set, in entries</td>
2703 <td>annotation_off_item[size]</td>
2704 <td>elements of the set. The elements must be sorted in increasing order,
2705 by <code>type_idx</code>.
2711 <h3><code>annotation_off_item</code> Format</h3>
2713 <table class="format">
2718 <th>Description</th>
2723 <td>annotation_off</td>
2725 <td>offset from the start of the file to an annotation.
2726 The offset should be to a location in the <code>data</code> section,
2727 and the format of the data at that location is specified by
2728 "<code>annotation_item</code>" below.
2735 <h2><code>annotation_item</code></h2>
2736 <h4>referenced from <code>annotation_set_item</code></h4>
2737 <h4>appears in the <code>data</code> section</h4>
2738 <h4>alignment: none (byte-aligned)</h4>
2740 <table class="format">
2745 <th>Description</th>
2752 <td>intended visibility of this annotation (see below)</td>
2756 <td>encoded_annotation</td>
2757 <td>encoded annotation contents, in the format described by
2758 "<code>encoded_annotation</code> Format" under
2759 "<code>encoded_value</code> Encoding" above.
2765 <h3>Visibility values</h3>
2767 <p>These are the options for the <code>visibility</code> field in an
2768 <code>annotation_item</code>:</p>
2770 <table class="format">
2775 <th>Description</th>
2780 <td>VISIBILITY_BUILD</td>
2782 <td>intended only to be visible at build time (e.g., during compilation
2787 <td>VISIBILITY_RUNTIME</td>
2789 <td>intended to visible at runtime</td>
2792 <td>VISIBILITY_SYSTEM</td>
2794 <td>intended to visible at runtime, but only to the underlying system
2795 (and not to regular user code)
2801 <h2><code>encoded_array_item</code></h2>
2802 <h4>referenced from <code>class_def_item</code></h4>
2803 <h4>appears in the <code>data</code> section</h4>
2804 <h4>alignment: none (byte-aligned)</h4>
2806 <table class="format">
2811 <th>Description</th>
2817 <td>encoded_array</td>
2818 <td>bytes representing the encoded array value, in the format specified
2819 by "<code>encoded_array</code> Format" under "<code>encoded_value</code>
2826 <h1>System Annotations</h1>
2828 <p>System annotations are used to represent various pieces of reflective
2829 information about classes (and methods and fields). This information is
2830 generally only accessed indirectly by client (non-system) code.</p>
2832 <p>System annotations are represented in <code>.dex</code> files as
2833 annotations with visibility set to <code>VISIBILITY_SYSTEM</code>.
2835 <h2><code>dalvik.annotation.AnnotationDefault</code></h2>
2836 <h4>appears on methods in annotation interfaces</h4>
2838 <p>An <code>AnnotationDefault</code> annotation is attached to each
2839 annotation interface which wishes to indicate default bindings.</p>
2841 <table class="format">
2846 <th>Description</th>
2853 <td>the default bindings for this annotation, represented as an annotation
2854 of this type. The annotation need not include all names defined by the
2855 annotation; missing names simply do not have defaults.
2861 <h2><code>dalvik.annotation.EnclosingClass</code></h2>
2862 <h4>appears on classes</h4>
2864 <p>An <code>EnclosingClass</code> annotation is attached to each class
2865 which is either defined as a member of another class, per se, or is
2866 anonymous but not defined within a method body (e.g., a synthetic
2867 inner class). Every class that has this annotation must also have an
2868 <code>InnerClass</code> annotation. Additionally, a class may not have
2869 both an <code>EnclosingClass</code> and an
2870 <code>EnclosingMethod</code> annotation.</p>
2872 <table class="format">
2877 <th>Description</th>
2884 <td>the class which most closely lexically scopes this class</td>
2889 <h2><code>dalvik.annotation.EnclosingMethod</code></h2>
2890 <h4>appears on classes</h4>
2892 <p>An <code>EnclosingMethod</code> annotation is attached to each class
2893 which is defined inside a method body. Every class that has this
2894 annotation must also have an <code>InnerClass</code> annotation.
2895 Additionally, a class may not have both an <code>EnclosingClass</code>
2896 and an <code>EnclosingMethod</code> annotation.</p>
2898 <table class="format">
2903 <th>Description</th>
2910 <td>the method which most closely lexically scopes this class</td>
2915 <h2><code>dalvik.annotation.InnerClass</code></h2>
2916 <h4>appears on classes</h4>
2918 <p>An <code>InnerClass</code> annotation is attached to each class
2919 which is defined in the lexical scope of another class's definition.
2920 Any class which has this annotation must also have <i>either</i> an
2921 <code>EnclosingClass</code> annotation <i>or</i> an
2922 <code>EnclosingMethod</code> annotation.</p>
2924 <table class="format">
2929 <th>Description</th>
2936 <td>the originally declared simple name of this class (not including any
2937 package prefix). If this class is anonymous, then the name is
2942 <td>accessFlags</td>
2944 <td>the originally declared access flags of the class (which may differ
2945 from the effective flags because of a mismatch between the execution
2946 models of the source language and target virtual machine)
2952 <h2><code>dalvik.annotation.MemberClasses</code></h2>
2953 <h4>appears on classes</h4>
2955 <p>A <code>MemberClasses</code> annotation is attached to each class
2956 which declares member classes. (A member class is a direct inner class
2957 that has a name.)</p>
2959 <table class="format">
2964 <th>Description</th>
2971 <td>array of the member classes</td>
2976 <h2><code>dalvik.annotation.Signature</code></h2>
2977 <h4>appears on classes, fields, and methods</h4>
2979 <p>A <code>Signature</code> annotation is attached to each class,
2980 field, or method which is defined in terms of a more complicated type
2981 than is representable by a <code>type_id_item</code>. The
2982 <code>.dex</code> format does not define the format for signatures; it
2983 is merely meant to be able to represent whatever signatures a source
2984 language requires for successful implementation of that language's
2985 semantics. As such, signatures are not generally parsed (or verified)
2986 by virtual machine implementations. The signatures simply get handed
2987 off to higher-level APIs and tools (such as debuggers). Any use of a
2988 signature, therefore, should be written so as not to make any
2989 assumptions about only receiving valid signatures, explicitly guarding
2990 itself against the possibility of coming across a syntactically
2991 invalid signature.</p>
2993 <p>Because signature strings tend to have a lot of duplicated content,
2994 a <code>Signature</code> annotation is defined as an <i>array</i> of
2995 strings, where duplicated elements naturally refer to the same
2996 underlying data, and the signature is taken to be the concatenation of
2997 all the strings in the array. There are no rules about how to pull
2998 apart a signature into separate strings; that is entirely up to the
2999 tools that generate <code>.dex</code> files.</p>
3001 <table class="format">
3006 <th>Description</th>
3013 <td>the signature of this class or member, as an array of strings that
3014 is to be concatenated together</td>
3019 <h2><code>dalvik.annotation.Throws</code></h2>
3020 <h4>appears on methods</h4>
3022 <p>A <code>Throws</code> annotation is attached to each method which is
3023 declared to throw one or more exception types.</p>
3025 <table class="format">
3030 <th>Description</th>
3037 <td>the array of exception types thrown</td>