blob: e78d18b68bc264644f2cc59a1f61591854b28cca [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=Dalvik Executable Format
2@jd:body
Dan Bornstein25705bc2011-04-12 16:23:13 -07003
Robert Ly35f2fda2013-01-29 16:27:05 -08004<!--
5 Copyright 2010 The Android Open Source Project
Dan Bornstein25705bc2011-04-12 16:23:13 -07006
Robert Ly35f2fda2013-01-29 16:27:05 -08007 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
Dan Bornstein25705bc2011-04-12 16:23:13 -070010
Robert Ly35f2fda2013-01-29 16:27:05 -080011 http://www.apache.org/licenses/LICENSE-2.0
Dan Bornstein25705bc2011-04-12 16:23:13 -070012
Robert Ly35f2fda2013-01-29 16:27:05 -080013 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
Dan Bornstein25705bc2011-04-12 16:23:13 -070019<p>Copyright &copy; 2007 The Android Open Source Project
20
21<p>This document describes the layout and contents of <code>.dex</code>
22files, which are used to hold a set of class definitions and their associated
23adjunct data.</p>
24
Clay Murphy414d4712013-06-03 18:44:16 -070025<h2>Guide To Types</h2>
Dan Bornstein25705bc2011-04-12 16:23:13 -070026
27<table class="guide">
28<thead>
29<tr>
30 <th>Name</th>
31 <th>Description</th>
32</tr>
33</thead>
34<tbody>
35<tr>
36 <td>byte</td>
37 <td>8-bit signed int</td>
38</tr>
39<tr>
40 <td>ubyte</td>
41 <td>8-bit unsigned int</td>
42</tr>
43<tr>
44 <td>short</td>
45 <td>16-bit signed int, little-endian</td>
46</tr>
47<tr>
48 <td>ushort</td>
49 <td>16-bit unsigned int, little-endian</td>
50</tr>
51<tr>
52 <td>int</td>
53 <td>32-bit signed int, little-endian</td>
54</tr>
55<tr>
56 <td>uint</td>
57 <td>32-bit unsigned int, little-endian</td>
58</tr>
59<tr>
60 <td>long</td>
61 <td>64-bit signed int, little-endian</td>
62</tr>
63<tr>
64 <td>ulong</td>
65 <td>64-bit unsigned int, little-endian</td>
66</tr>
67<tr>
68 <td>sleb128</td>
69 <td>signed LEB128, variable-length (see below)</td>
70</tr>
71<tr>
72 <td>uleb128</td>
73 <td>unsigned LEB128, variable-length (see below)</td>
74</tr>
75<tr>
76 <td>uleb128p1</td>
77 <td>unsigned LEB128 plus <code>1</code>, variable-length (see below)</td>
78</tr>
79</tbody>
80</table>
81
82<h3>LEB128</h3>
83
84<p>LEB128 ("<b>L</b>ittle-<b>E</b>ndian <b>B</b>ase <b>128</b>") is a
85variable-length encoding for
86arbitrary signed or unsigned integer quantities. The format was
87borrowed from the <a href="http://dwarfstd.org/Dwarf3Std.php">DWARF3</a>
88specification. In a <code>.dex</code> file, LEB128 is only ever used to
89encode 32-bit quantities.</p>
90
91<p>Each LEB128 encoded value consists of one to five
92bytes, which together represent a single 32-bit value. Each
93byte has its most significant bit set except for the final byte in the
94sequence, which has its most significant bit clear. The remaining
95seven bits of each byte are payload, with the least significant seven
96bits of the quantity in the first byte, the next seven in the second
97byte and so on. In the case of a signed LEB128 (<code>sleb128</code>),
98the most significant payload bit of the final byte in the sequence is
99sign-extended to produce the final value. In the unsigned case
100(<code>uleb128</code>), any bits not explicitly represented are
101interpreted as <code>0</code>.
102
103<table class="leb128Bits">
104<thead>
105<tr><th colspan="16">Bitwise diagram of a two-byte LEB128 value</th></tr>
106<tr>
107 <th colspan="8">First byte</td>
108 <th colspan="8">Second byte</td>
109</tr>
110</thead>
111<tbody>
112<tr>
113 <td class="start1"><code>1</code></td>
114 <td>bit<sub>6</sub></td>
115 <td>bit<sub>5</sub></td>
116 <td>bit<sub>4</sub></td>
117 <td>bit<sub>3</sub></td>
118 <td>bit<sub>2</sub></td>
119 <td>bit<sub>1</sub></td>
120 <td>bit<sub>0</sub></td>
121 <td class="start2"><code>0</code></td>
122 <td>bit<sub>13</sub></td>
123 <td>bit<sub>12</sub></td>
124 <td>bit<sub>11</sub></td>
125 <td>bit<sub>10</sub></td>
126 <td>bit<sub>9</sub></td>
127 <td>bit<sub>8</sub></td>
128 <td class="end2">bit<sub>7</sub></td>
129</tr>
130</tbody>
131</table>
132
133<p>The variant <code>uleb128p1</code> is used to represent a signed
134value, where the representation is of the value <i>plus one</i> encoded
135as a <code>uleb128</code>. This makes the encoding of <code>-1</code>
136(alternatively thought of as the unsigned value <code>0xffffffff</code>)
137&mdash; but no other negative number &mdash; a single byte, and is
138useful in exactly those cases where the represented number must either
139be non-negative or <code>-1</code> (or <code>0xffffffff</code>),
140and where no other negative values are allowed (or where large unsigned
141values are unlikely to be needed).</p>
142
143<p>Here are some examples of the formats:</p>
144
145<table class="leb128">
146<thead>
147<tr>
148 <th>Encoded Sequence</th>
149 <th>As <code>sleb128</code></th>
150 <th>As <code>uleb128</code></th>
151 <th>As <code>uleb128p1</code></th>
152</tr>
153</thead>
154<tbody>
155 <tr><td>00</td><td>0</td><td>0</td><td>-1</td></tr>
156 <tr><td>01</td><td>1</td><td>1</td><td>0</td></tr>
157 <tr><td>7f</td><td>-1</td><td>127</td><td>126</td></tr>
158 <tr><td>80 7f</td><td>-128</td><td>16256</td><td>16255</td></tr>
159</tbody>
160</table>
161
Clay Murphy414d4712013-06-03 18:44:16 -0700162<h2>Overall File Layout</h2>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700163
164<table class="format">
165<thead>
166<tr>
167 <th>Name</th>
168 <th>Format</th>
169 <th>Description</th>
170</tr>
171</thead>
172<tbody>
173<tr>
174 <td>header</td>
175 <td>header_item</td>
176 <td>the header</td>
177</tr>
178<tr>
179 <td>string_ids</td>
180 <td>string_id_item[]</td>
181 <td>string identifiers list. These are identifiers for all the strings
182 used by this file, either for internal naming (e.g., type descriptors)
183 or as constant objects referred to by code. This list must be sorted
184 by string contents, using UTF-16 code point values (not in a
Elliott Hughes8d777942012-01-05 17:27:02 -0800185 locale-sensitive manner), and it must not contain any duplicate entries.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700186 </td>
187</tr>
188<tr>
189 <td>type_ids</td>
190 <td>type_id_item[]</td>
191 <td>type identifiers list. These are identifiers for all types (classes,
192 arrays, or primitive types) referred to by this file, whether defined
193 in the file or not. This list must be sorted by <code>string_id</code>
Elliott Hughes8d777942012-01-05 17:27:02 -0800194 index, and it must not contain any duplicate entries.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700195 </td>
196</tr>
197<tr>
198 <td>proto_ids</td>
199 <td>proto_id_item[]</td>
200 <td>method prototype identifiers list. These are identifiers for all
201 prototypes referred to by this file. This list must be sorted in
202 return-type (by <code>type_id</code> index) major order, and then
Elliott Hughes8d777942012-01-05 17:27:02 -0800203 by arguments (also by <code>type_id</code> index). The list must not
204 contain any duplicate entries.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700205 </td>
206</tr>
207<tr>
208 <td>field_ids</td>
209 <td>field_id_item[]</td>
210 <td>field identifiers list. These are identifiers for all fields
211 referred to by this file, whether defined in the file or not. This
212 list must be sorted, where the defining type (by <code>type_id</code>
213 index) is the major order, field name (by <code>string_id</code> index)
214 is the intermediate order, and type (by <code>type_id</code> index)
Elliott Hughes8d777942012-01-05 17:27:02 -0800215 is the minor order. The list must not contain any duplicate entries.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700216 </td>
217</tr>
218<tr>
219 <td>method_ids</td>
220 <td>method_id_item[]</td>
221 <td>method identifiers list. These are identifiers for all methods
222 referred to by this file, whether defined in the file or not. This
223 list must be sorted, where the defining type (by <code>type_id</code>
224 index) is the major order, method name (by <code>string_id</code>
Elliott Hughes8d777942012-01-05 17:27:02 -0800225 index) is the intermediate order, and method prototype (by
226 <code>proto_id</code> index) is the minor order. The list must not
227 contain any duplicate entries.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700228 </td>
229</tr>
230<tr>
231 <td>class_defs</td>
232 <td>class_def_item[]</td>
233 <td>class definitions list. The classes must be ordered such that a given
234 class's superclass and implemented interfaces appear in the
Elliott Hughes8d777942012-01-05 17:27:02 -0800235 list earlier than the referring class. Furthermore, it is invalid for
236 a definition for the same-named class to appear more than once in
237 the list.
Dan Bornstein25705bc2011-04-12 16:23:13 -0700238 </td>
239</tr>
240<tr>
241 <td>data</td>
242 <td>ubyte[]</td>
243 <td>data area, containing all the support data for the tables listed above.
244 Different items have different alignment requirements, and
245 padding bytes are inserted before each item if necessary to achieve
246 proper alignment.
247 </td>
248</tr>
249<tr>
250 <td>link_data</td>
251 <td>ubyte[]</td>
252 <td>data used in statically linked files. The format of the data in
Elliott Hughes8d777942012-01-05 17:27:02 -0800253 this section is left unspecified by this document.
254 This section is empty in unlinked files, and runtime implementations
Dan Bornstein25705bc2011-04-12 16:23:13 -0700255 may use it as they see fit.
256 </td>
257</tr>
258</tbody>
259</table>
260
Clay Murphy414d4712013-06-03 18:44:16 -0700261<h2>Bitfield, String, and Constant Definitions</h2>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700262
Clay Murphy945af1a2013-07-01 17:31:13 -0700263<h3>DEX_FILE_MAGIC</h3>
264<h4>embedded in header_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700265
266<p>The constant array/string <code>DEX_FILE_MAGIC</code> is the list of
267bytes that must appear at the beginning of a <code>.dex</code> file
268in order for it to be recognized as such. The value intentionally
269contains a newline (<code>"\n"</code> or <code>0x0a</code>) and a
270null byte (<code>"\0"</code> or <code>0x00</code>) in order to help
271in the detection of certain forms of corruption. The value also
272encodes a format version number as three decimal digits, which is
273expected to increase monotonically over time as the format evolves.</p>
274
275<pre>
276ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x35 0x00 }
277 = "dex\n035\0"
278</pre>
279
280<p><b>Note:</b> At least a couple earlier versions of the format have
281been used in widely-available public software releases. For example,
282version <code>009</code> was used for the M3 releases of the
Elliott Hughes8d777942012-01-05 17:27:02 -0800283Android platform (November&ndash;December 2007),
Dan Bornstein25705bc2011-04-12 16:23:13 -0700284and version <code>013</code> was used for the M5 releases of the Android
Elliott Hughes8d777942012-01-05 17:27:02 -0800285platform (February&ndash;March 2008). In several respects, these earlier
286versions of the format differ significantly from the version described in this
Dan Bornstein25705bc2011-04-12 16:23:13 -0700287document.</p>
288
Clay Murphy945af1a2013-07-01 17:31:13 -0700289<h3>ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT</h3>
290<h4>embedded in header_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700291
292<p>The constant <code>ENDIAN_CONSTANT</code> is used to indicate the
293endianness of the file in which it is found. Although the standard
294<code>.dex</code> format is little-endian, implementations may choose
295to perform byte-swapping. Should an implementation come across a
296header whose <code>endian_tag</code> is <code>REVERSE_ENDIAN_CONSTANT</code>
297instead of <code>ENDIAN_CONSTANT</code>, it would know that the file
298has been byte-swapped from the expected form.</p>
299
300<pre>
301uint ENDIAN_CONSTANT = 0x12345678;
302uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
303</pre>
304
Clay Murphy945af1a2013-07-01 17:31:13 -0700305<h3>NO_INDEX</h3>
306<h4>embedded in class_def_item and debug_info_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700307
308<p>The constant <code>NO_INDEX</code> is used to indicate that
309an index value is absent.</p>
310
311<p><b>Note:</b> This value isn't defined to be
312<code>0</code>, because that is in fact typically a valid index.</p>
313
314<p><b>Also Note:</b> The chosen value for <code>NO_INDEX</code> is
315representable as a single byte in the <code>uleb128p1</code> encoding.</p>
316
317<pre>
318uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
319</pre>
320
Clay Murphy945af1a2013-07-01 17:31:13 -0700321<h3>access_flags Definitions</h3>
322<h4>embedded in class_def_item, encoded_field, encoded_method, and
323InnerClass</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700324
325<p>Bitfields of these flags are used to indicate the accessibility and
326overall properties of classes and class members.</p>
327
328<table class="accessFlags">
329<thead>
330<tr>
331 <th>Name</th>
332 <th>Value</th>
333 <th>For Classes (and <code>InnerClass</code> annotations)</th>
334 <th>For Fields</th>
335 <th>For Methods</th>
336</tr>
337</thead>
338<tbody>
339<tr>
340 <td>ACC_PUBLIC</td>
341 <td>0x1</td>
342 <td><code>public</code>: visible everywhere</td>
343 <td><code>public</code>: visible everywhere</td>
344 <td><code>public</code>: visible everywhere</td>
345</tr>
346<tr>
347 <td>ACC_PRIVATE</td>
348 <td>0x2</td>
349 <td><super>*</super>
350 <code>private</code>: only visible to defining class
351 </td>
352 <td><code>private</code>: only visible to defining class</td>
353 <td><code>private</code>: only visible to defining class</td>
354</tr>
355<tr>
356 <td>ACC_PROTECTED</td>
357 <td>0x4</td>
358 <td><super>*</super>
359 <code>protected</code>: visible to package and subclasses
360 </td>
361 <td><code>protected</code>: visible to package and subclasses</td>
362 <td><code>protected</code>: visible to package and subclasses</td>
363</tr>
364<tr>
365 <td>ACC_STATIC</td>
366 <td>0x8</td>
367 <td><super>*</super>
368 <code>static</code>: is not constructed with an outer
369 <code>this</code> reference</td>
370 <td><code>static</code>: global to defining class</td>
371 <td><code>static</code>: does not take a <code>this</code> argument</td>
372</tr>
373<tr>
374 <td>ACC_FINAL</td>
375 <td>0x10</td>
376 <td><code>final</code>: not subclassable</td>
377 <td><code>final</code>: immutable after construction</td>
378 <td><code>final</code>: not overridable</td>
379</tr>
380<tr>
381 <td>ACC_SYNCHRONIZED</td>
382 <td>0x20</td>
383 <td>&nbsp;</td>
384 <td>&nbsp;</td>
385 <td><code>synchronized</code>: associated lock automatically acquired
386 around call to this method. <b>Note:</b> This is only valid to set when
387 <code>ACC_NATIVE</code> is also set.</td>
388</tr>
389<tr>
390 <td>ACC_VOLATILE</td>
391 <td>0x40</td>
392 <td>&nbsp;</td>
393 <td><code>volatile</code>: special access rules to help with thread
394 safety</td>
395 <td>&nbsp;</td>
396</tr>
397<tr>
398 <td>ACC_BRIDGE</td>
399 <td>0x40</td>
400 <td>&nbsp;</td>
401 <td>&nbsp;</td>
402 <td>bridge method, added automatically by compiler as a type-safe
403 bridge</td>
404</tr>
405<tr>
406 <td>ACC_TRANSIENT</td>
407 <td>0x80</td>
408 <td>&nbsp;</td>
409 <td><code>transient</code>: not to be saved by default serialization</td>
410 <td>&nbsp;</td>
411</tr>
412<tr>
413 <td>ACC_VARARGS</td>
414 <td>0x80</td>
415 <td>&nbsp;</td>
416 <td>&nbsp;</td>
417 <td>last argument should be treated as a "rest" argument by compiler</td>
418</tr>
419<tr>
420 <td>ACC_NATIVE</td>
421 <td>0x100</td>
422 <td>&nbsp;</td>
423 <td>&nbsp;</td>
424 <td><code>native</code>: implemented in native code</td>
425</tr>
426<tr>
427 <td>ACC_INTERFACE</td>
428 <td>0x200</td>
429 <td><code>interface</code>: multiply-implementable abstract class</td>
430 <td>&nbsp;</td>
431 <td>&nbsp;</td>
432</tr>
433<tr>
434 <td>ACC_ABSTRACT</td>
435 <td>0x400</td>
436 <td><code>abstract</code>: not directly instantiable</td>
437 <td>&nbsp;</td>
438 <td><code>abstract</code>: unimplemented by this class</td>
439</tr>
440<tr>
441 <td>ACC_STRICT</td>
442 <td>0x800</td>
443 <td>&nbsp;</td>
444 <td>&nbsp;</td>
445 <td><code>strictfp</code>: strict rules for floating-point arithmetic</td>
446</tr>
447<tr>
448 <td>ACC_SYNTHETIC</td>
449 <td>0x1000</td>
450 <td>not directly defined in source code</td>
451 <td>not directly defined in source code</td>
452 <td>not directly defined in source code</td>
453</tr>
454<tr>
455 <td>ACC_ANNOTATION</td>
456 <td>0x2000</td>
457 <td>declared as an annotation class</td>
458 <td>&nbsp;</td>
459 <td>&nbsp;</td>
460</tr>
461<tr>
462 <td>ACC_ENUM</td>
463 <td>0x4000</td>
464 <td>declared as an enumerated type</td>
465 <td>declared as an enumerated value</td>
466 <td>&nbsp;</td>
467</tr>
468<tr>
469 <td><i>(unused)</i></td>
470 <td>0x8000</td>
471 <td>&nbsp;</td>
472 <td>&nbsp;</td>
473 <td>&nbsp;</td>
474</tr>
475<tr>
476 <td>ACC_CONSTRUCTOR</td>
477 <td>0x10000</td>
478 <td>&nbsp;</td>
479 <td>&nbsp;</td>
480 <td>constructor method (class or instance initializer)</td>
481</tr>
482<tr>
483 <td>ACC_DECLARED_<br/>SYNCHRONIZED</td>
484 <td>0x20000</td>
485 <td>&nbsp;</td>
486 <td>&nbsp;</td>
487 <td>declared <code>synchronized</code>. <b>Note:</b> This has no effect on
488 execution (other than in reflection of this flag, per se).
489 </td>
490</tr>
491</tbody>
492</table>
493
494<p><super>*</super> Only allowed on for <code>InnerClass</code> annotations,
495and must not ever be on in a <code>class_def_item</code>.</p>
496
Clay Murphy414d4712013-06-03 18:44:16 -0700497<h3>MUTF-8 (Modified UTF-8) Encoding</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700498
499<p>As a concession to easier legacy support, the <code>.dex</code> format
500encodes its string data in a de facto standard modified UTF-8 form, hereafter
501referred to as MUTF-8. This form is identical to standard UTF-8, except:</p>
502
503<ul>
504 <li>Only the one-, two-, and three-byte encodings are used.</li>
505 <li>Code points in the range <code>U+10000</code> &hellip;
506 <code>U+10ffff</code> are encoded as a surrogate pair, each of
507 which is represented as a three-byte encoded value.</li>
508 <li>The code point <code>U+0000</code> is encoded in two-byte form.</li>
509 <li>A plain null byte (value <code>0</code>) indicates the end of
510 a string, as is the standard C language interpretation.</li>
511</ul>
512
513<p>The first two items above can be summarized as: MUTF-8
514is an encoding format for UTF-16, instead of being a more direct
515encoding format for Unicode characters.</p>
516
517<p>The final two items above make it simultaneously possible to include
518the code point <code>U+0000</code> in a string <i>and</i> still manipulate
519it as a C-style null-terminated string.</p>
520
521<p>However, the special encoding of <code>U+0000</code> means that, unlike
522normal UTF-8, the result of calling the standard C function
523<code>strcmp()</code> on a pair of MUTF-8 strings does not always
524indicate the properly signed result of comparison of <i>unequal</i> strings.
525When ordering (not just equality) is a concern, the most straightforward
526way to compare MUTF-8 strings is to decode them character by character,
527and compare the decoded values. (However, more clever implementations are
528also possible.)</p>
529
530<p>Please refer to <a href="http://unicode.org">The Unicode
531Standard</a> for further information about character encoding.
532MUTF-8 is actually closer to the (relatively less well-known) encoding
533<a href="http://www.unicode.org/reports/tr26/">CESU-8</a> than to UTF-8
534per se.</p>
535
Clay Murphy945af1a2013-07-01 17:31:13 -0700536<h3>encoded_value Encoding</h3>
537<h4>embedded in annotation_element and encoded_array_item </h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700538
539<p>An <code>encoded_value</code> is an encoded piece of (nearly)
540arbitrary hierarchically structured data. The encoding is meant to
541be both compact and straightforward to parse.</p>
542
543<table class="format">
544<thead>
545<tr>
546 <th>Name</th>
547 <th>Format</th>
548 <th>Description</th>
549</tr>
550</thead>
551<tbody>
552<tr>
553 <td>(value_arg &lt;&lt; 5) | value_type</td>
554 <td>ubyte</td>
555 <td>byte indicating the type of the immediately subsequent
556 <code>value</code> along
557 with an optional clarifying argument in the high-order three bits.
558 See below for the various <code>value</code> definitions.
559 In most cases, <code>value_arg</code> encodes the length of
560 the immediately-subsequent <code>value</code> in bytes, as
561 <code>(size - 1)</code>, e.g., <code>0</code> means that
562 the value requires one byte, and <code>7</code> means it requires
563 eight bytes; however, there are exceptions as noted below.
564 </td>
565</tr>
566<tr>
567 <td>value</td>
568 <td>ubyte[]</td>
569 <td>bytes representing the value, variable in length and interpreted
570 differently for different <code>value_type</code> bytes, though
571 always little-endian. See the various value definitions below for
572 details.
573 </td>
574</tr>
575</tbody>
576</table>
577
578<h3>Value Formats</h3>
579
580<table class="encodedValue">
581<thead>
582<tr>
583 <th>Type Name</th>
584 <th><code>value_type</code></th>
585 <th><code>value_arg</code> Format</th>
586 <th><code>value</code> Format</th>
587 <th>Description</th>
588</tr>
589</thead>
590<tbody>
591<tr>
592 <td>VALUE_BYTE</td>
593 <td>0x00</td>
594 <td><i>(none; must be <code>0</code>)</i></td>
595 <td>ubyte[1]</td>
596 <td>signed one-byte integer value</td>
597</tr>
598<tr>
599 <td>VALUE_SHORT</td>
600 <td>0x02</td>
601 <td>size - 1 (0&hellip;1)</td>
602 <td>ubyte[size]</td>
603 <td>signed two-byte integer value, sign-extended</td>
604</tr>
605<tr>
606 <td>VALUE_CHAR</td>
607 <td>0x03</td>
608 <td>size - 1 (0&hellip;1)</td>
609 <td>ubyte[size]</td>
610 <td>unsigned two-byte integer value, zero-extended</td>
611</tr>
612<tr>
613 <td>VALUE_INT</td>
614 <td>0x04</td>
615 <td>size - 1 (0&hellip;3)</td>
616 <td>ubyte[size]</td>
617 <td>signed four-byte integer value, sign-extended</td>
618</tr>
619<tr>
620 <td>VALUE_LONG</td>
621 <td>0x06</td>
622 <td>size - 1 (0&hellip;7)</td>
623 <td>ubyte[size]</td>
624 <td>signed eight-byte integer value, sign-extended</td>
625</tr>
626<tr>
627 <td>VALUE_FLOAT</td>
628 <td>0x10</td>
629 <td>size - 1 (0&hellip;3)</td>
630 <td>ubyte[size]</td>
631 <td>four-byte bit pattern, zero-extended <i>to the right</i>, and
632 interpreted as an IEEE754 32-bit floating point value
633 </td>
634</tr>
635<tr>
636 <td>VALUE_DOUBLE</td>
637 <td>0x11</td>
638 <td>size - 1 (0&hellip;7)</td>
639 <td>ubyte[size]</td>
640 <td>eight-byte bit pattern, zero-extended <i>to the right</i>, and
641 interpreted as an IEEE754 64-bit floating point value
642 </td>
643</tr>
644<tr>
645 <td>VALUE_STRING</td>
646 <td>0x17</td>
647 <td>size - 1 (0&hellip;3)</td>
648 <td>ubyte[size]</td>
649 <td>unsigned (zero-extended) four-byte integer value,
650 interpreted as an index into
651 the <code>string_ids</code> section and representing a string value
652 </td>
653</tr>
654<tr>
655 <td>VALUE_TYPE</td>
656 <td>0x18</td>
657 <td>size - 1 (0&hellip;3)</td>
658 <td>ubyte[size]</td>
659 <td>unsigned (zero-extended) four-byte integer value,
660 interpreted as an index into
661 the <code>type_ids</code> section and representing a reflective
662 type/class value
663 </td>
664</tr>
665<tr>
666 <td>VALUE_FIELD</td>
667 <td>0x19</td>
668 <td>size - 1 (0&hellip;3)</td>
669 <td>ubyte[size]</td>
670 <td>unsigned (zero-extended) four-byte integer value,
671 interpreted as an index into
672 the <code>field_ids</code> section and representing a reflective
673 field value
674 </td>
675</tr>
676<tr>
677 <td>VALUE_METHOD</td>
678 <td>0x1a</td>
679 <td>size - 1 (0&hellip;3)</td>
680 <td>ubyte[size]</td>
681 <td>unsigned (zero-extended) four-byte integer value,
682 interpreted as an index into
683 the <code>method_ids</code> section and representing a reflective
684 method value
685 </td>
686</tr>
687<tr>
688 <td>VALUE_ENUM</td>
689 <td>0x1b</td>
690 <td>size - 1 (0&hellip;3)</td>
691 <td>ubyte[size]</td>
692 <td>unsigned (zero-extended) four-byte integer value,
693 interpreted as an index into
694 the <code>field_ids</code> section and representing the value of
695 an enumerated type constant
696 </td>
697</tr>
698<tr>
699 <td>VALUE_ARRAY</td>
700 <td>0x1c</td>
701 <td><i>(none; must be <code>0</code>)</i></td>
702 <td>encoded_array</td>
703 <td>an array of values, in the format specified by
704 "<code>encoded_array</code> Format" below. The size
705 of the <code>value</code> is implicit in the encoding.
706 </td>
707</tr>
708<tr>
709 <td>VALUE_ANNOTATION</td>
710 <td>0x1d</td>
711 <td><i>(none; must be <code>0</code>)</i></td>
712 <td>encoded_annotation</td>
713 <td>a sub-annotation, in the format specified by
714 "<code>encoded_annotation</code> Format" below. The size
715 of the <code>value</code> is implicit in the encoding.
716 </td>
717</tr>
718<tr>
719 <td>VALUE_NULL</td>
720 <td>0x1e</td>
721 <td><i>(none; must be <code>0</code>)</i></td>
722 <td><i>(none)</i></td>
723 <td><code>null</code> reference value</td>
724</tr>
725<tr>
726 <td>VALUE_BOOLEAN</td>
727 <td>0x1f</td>
728 <td>boolean (0&hellip;1)</td>
729 <td><i>(none)</i></td>
730 <td>one-bit value; <code>0</code> for <code>false</code> and
731 <code>1</code> for <code>true</code>. The bit is represented in the
732 <code>value_arg</code>.
733 </td>
734</tr>
735</tbody>
736</table>
737
Clay Murphy945af1a2013-07-01 17:31:13 -0700738<h3>encoded_array Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700739
740<table class="format">
741<thead>
742<tr>
743 <th>Name</th>
744 <th>Format</th>
745 <th>Description</th>
746</tr>
747</thead>
748<tbody>
749<tr>
750 <td>size</td>
751 <td>uleb128</td>
752 <td>number of elements in the array</td>
753</tr>
754<tr>
755 <td>values</td>
756 <td>encoded_value[size]</td>
757 <td>a series of <code>size</code> <code>encoded_value</code> byte
758 sequences in the format specified by this section, concatenated
759 sequentially.
760 </td>
761</tr>
762</tbody>
763</table>
764
Clay Murphy945af1a2013-07-01 17:31:13 -0700765<h3>encoded_annotation Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700766
767<table class="format">
768<thead>
769<tr>
770 <th>Name</th>
771 <th>Format</th>
772 <th>Description</th>
773</tr>
774</thead>
775<tbody>
776<tr>
777 <td>type_idx</td>
778 <td>uleb128</td>
779 <td>type of the annotation. This must be a class (not array or primitive)
780 type.
781 </td>
782</tr>
783<tr>
784 <td>size</td>
785 <td>uleb128</td>
786 <td>number of name-value mappings in this annotation</td>
787</tr>
788<tr>
789 <td>elements</td>
790 <td>annotation_element[size]</td>
791 <td>elements of the annotataion, represented directly in-line (not as
792 offsets). Elements must be sorted in increasing order by
793 <code>string_id</code> index.
794 </td>
795</tr>
796</tbody>
797</table>
798
Clay Murphy945af1a2013-07-01 17:31:13 -0700799<h3>annotation_element Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700800
801<table class="format">
802<thead>
803<tr>
804 <th>Name</th>
805 <th>Format</th>
806 <th>Description</th>
807</tr>
808</thead>
809<tbody>
810<tr>
811 <td>name_idx</td>
812 <td>uleb128</td>
813 <td>element name, represented as an index into the
814 <code>string_ids</code> section. The string must conform to the
815 syntax for <i>MemberName</i>, defined above.
816 </td>
817</tr>
818<tr>
819 <td>value</td>
820 <td>encoded_value</td>
821 <td>element value</td>
822</tr>
823</tbody>
824</table>
825
826<h2>String Syntax</h2>
827
828<p>There are several kinds of item in a <code>.dex</code> file which
829ultimately refer to a string. The following BNF-style definitions
830indicate the acceptable syntax for these strings.</p>
831
832<h3><i>SimpleName</i></h3>
833
834<p>A <i>SimpleName</i> is the basis for the syntax of the names of other
835things. The <code>.dex</code> format allows a fair amount of latitude
836here (much more than most common source languages). In brief, a simple
Elliott Hughes8d777942012-01-05 17:27:02 -0800837name consists of any low-ASCII alphabetic character or digit, a few
Dan Bornstein25705bc2011-04-12 16:23:13 -0700838specific low-ASCII symbols, and most non-ASCII code points that are not
839control, space, or special characters. Note that surrogate code points
840(in the range <code>U+d800</code> &hellip; <code>U+dfff</code>) are not
841considered valid name characters, per se, but Unicode supplemental
842characters <i>are</i> valid (which are represented by the final
843alternative of the rule for <i>SimpleNameChar</i>), and they should be
844represented in a file as pairs of surrogate code points in the MUTF-8
845encoding.</p>
846
847<table class="bnf">
848 <tr><td colspan="2" class="def"><i>SimpleName</i> &rarr;</td></tr>
849 <tr>
850 <td/>
851 <td><i>SimpleNameChar</i> (<i>SimpleNameChar</i>)*</td>
852 </tr>
853
854 <tr><td colspan="2" class="def"><i>SimpleNameChar</i> &rarr;</td></tr>
855 <tr>
856 <td/>
857 <td><code>'A'</code> &hellip; <code>'Z'</code></td>
858 </tr>
859 <tr>
860 <td class="bar">|</td>
861 <td><code>'a'</code> &hellip; <code>'z'</code></td>
862 </tr>
863 <tr>
864 <td class="bar">|</td>
865 <td><code>'0'</code> &hellip; <code>'9'</code></td>
866 </tr>
867 <tr>
868 <td class="bar">|</td>
869 <td><code>'$'</code></td>
870 </tr>
871 <tr>
872 <td class="bar">|</td>
873 <td><code>'-'</code></td>
874 </tr>
875 <tr>
876 <td class="bar">|</td>
877 <td><code>'_'</code></td>
878 </tr>
879 <tr>
880 <td class="bar">|</td>
881 <td><code>U+00a1</code> &hellip; <code>U+1fff</code></td>
882 </tr>
883 <tr>
884 <td class="bar">|</td>
885 <td><code>U+2010</code> &hellip; <code>U+2027</code></td>
886 </tr>
887 <tr>
888 <td class="bar">|</td>
889 <td><code>U+2030</code> &hellip; <code>U+d7ff</code></td>
890 </tr>
891 <tr>
892 <td class="bar">|</td>
893 <td><code>U+e000</code> &hellip; <code>U+ffef</code></td>
894 </tr>
895 <tr>
896 <td class="bar">|</td>
897 <td><code>U+10000</code> &hellip; <code>U+10ffff</code></td>
898 </tr>
899</table>
900
901<h3><i>MemberName</i></h3>
Clay Murphy945af1a2013-07-01 17:31:13 -0700902<h4>used by field_id_item and method_id_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700903
904<p>A <i>MemberName</i> is the name of a member of a class, members being
905fields, methods, and inner classes.</p>
906
907<table class="bnf">
908 <tr><td colspan="2" class="def"><i>MemberName</i> &rarr;</td></tr>
909 <tr>
910 <td/>
911 <td><i>SimpleName</i></td>
912 </tr>
913 <tr>
914 <td class="bar">|</td>
915 <td><code>'&lt;'</code> <i>SimpleName</i> <code>'&gt;'</code></td>
916 </tr>
917</table>
918
919<h3><i>FullClassName</i></h3>
920
921<p>A <i>FullClassName</i> is a fully-qualified class name, including an
922optional package specifier followed by a required name.</p>
923
924<table class="bnf">
925 <tr><td colspan="2" class="def"><i>FullClassName</i> &rarr;</td></tr>
926 <tr>
927 <td/>
928 <td><i>OptionalPackagePrefix</i> <i>SimpleName</i></td>
929 </tr>
930
931 <tr><td colspan="2" class="def"><i>OptionalPackagePrefix</i> &rarr;</td></tr>
932 <tr>
933 <td/>
934 <td>(<i>SimpleName</i> <code>'/'</code>)*</td>
935 </tr>
936</table>
937
938<h3><i>TypeDescriptor</i></h3>
Clay Murphy945af1a2013-07-01 17:31:13 -0700939<h4>used by type_id_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -0700940
941<p>A <i>TypeDescriptor</i> is the representation of any type, including
942primitives, classes, arrays, and <code>void</code>. See below for
943the meaning of the various versions.</p>
944
945<table class="bnf">
946 <tr><td colspan="2" class="def"><i>TypeDescriptor</i> &rarr;</td></tr>
947 <tr>
948 <td/>
949 <td><code>'V'</code></td>
950 </tr>
951 <tr>
952 <td class="bar">|</td>
953 <td><i>FieldTypeDescriptor</i></td>
954 </tr>
955
956 <tr><td colspan="2" class="def"><i>FieldTypeDescriptor</i> &rarr;</td></tr>
957 <tr>
958 <td/>
959 <td><i>NonArrayFieldTypeDescriptor</i></td>
960 </tr>
961 <tr>
962 <td class="bar">|</td>
963 <td>(<code>'['</code> * 1&hellip;255)
964 <i>NonArrayFieldTypeDescriptor</i></td>
965 </tr>
966
967 <tr>
968 <td colspan="2" class="def"><i>NonArrayFieldTypeDescriptor</i>&rarr;</td>
969 </tr>
970 <tr>
971 <td/>
972 <td><code>'Z'</code></td>
973 </tr>
974 <tr>
975 <td class="bar">|</td>
976 <td><code>'B'</code></td>
977 </tr>
978 <tr>
979 <td class="bar">|</td>
980 <td><code>'S'</code></td>
981 </tr>
982 <tr>
983 <td class="bar">|</td>
984 <td><code>'C'</code></td>
985 </tr>
986 <tr>
987 <td class="bar">|</td>
988 <td><code>'I'</code></td>
989 </tr>
990 <tr>
991 <td class="bar">|</td>
992 <td><code>'J'</code></td>
993 </tr>
994 <tr>
995 <td class="bar">|</td>
996 <td><code>'F'</code></td>
997 </tr>
998 <tr>
999 <td class="bar">|</td>
1000 <td><code>'D'</code></td>
1001 </tr>
1002 <tr>
1003 <td class="bar">|</td>
1004 <td><code>'L'</code> <i>FullClassName</i> <code>';'</code></td>
1005 </tr>
1006</table>
1007
1008<h3><i>ShortyDescriptor</i></h3>
Clay Murphy945af1a2013-07-01 17:31:13 -07001009<h4>used by proto_id_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001010
1011<p>A <i>ShortyDescriptor</i> is the short form representation of a method
1012prototype, including return and parameter types, except that there is
1013no distinction between various reference (class or array) types. Instead,
1014all reference types are represented by a single <code>'L'</code> character.</p>
1015
1016<table class="bnf">
1017 <tr><td colspan="2" class="def"><i>ShortyDescriptor</i> &rarr;</td></tr>
1018 <tr>
1019 <td/>
1020 <td><i>ShortyReturnType</i> (<i>ShortyFieldType</i>)*</td>
1021 </tr>
1022
1023 <tr><td colspan="2" class="def"><i>ShortyReturnType</i> &rarr;</td></tr>
1024 <tr>
1025 <td/>
1026 <td><code>'V'</code></td>
1027 </tr>
1028 <tr>
1029 <td class="bar">|</td>
1030 <td><i>ShortyFieldType</i></td>
1031 </tr>
1032
1033 <tr><td colspan="2" class="def"><i>ShortyFieldType</i> &rarr;</td></tr>
1034 <tr>
1035 <td/>
1036 <td><code>'Z'</code></td>
1037 </tr>
1038 <tr>
1039 <td class="bar">|</td>
1040 <td><code>'B'</code></td>
1041 </tr>
1042 <tr>
1043 <td class="bar">|</td>
1044 <td><code>'S'</code></td>
1045 </tr>
1046 <tr>
1047 <td class="bar">|</td>
1048 <td><code>'C'</code></td>
1049 </tr>
1050 <tr>
1051 <td class="bar">|</td>
1052 <td><code>'I'</code></td>
1053 </tr>
1054 <tr>
1055 <td class="bar">|</td>
1056 <td><code>'J'</code></td>
1057 </tr>
1058 <tr>
1059 <td class="bar">|</td>
1060 <td><code>'F'</code></td>
1061 </tr>
1062 <tr>
1063 <td class="bar">|</td>
1064 <td><code>'D'</code></td>
1065 </tr>
1066 <tr>
1067 <td class="bar">|</td>
1068 <td><code>'L'</code></td>
1069 </tr>
1070</table>
1071
Clay Murphy414d4712013-06-03 18:44:16 -07001072<h3><i>TypeDescriptor</i> Semantics</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001073
1074<p>This is the meaning of each of the variants of <i>TypeDescriptor</i>.</p>
1075
1076<table class="descriptor">
1077<thead>
1078<tr>
1079 <th>Syntax</th>
1080 <th>Meaning</th>
1081</tr>
1082</thead>
1083<tbody>
1084<tr>
1085 <td>V</td>
1086 <td><code>void</code>; only valid for return types</td>
1087</tr>
1088<tr>
1089 <td>Z</td>
1090 <td><code>boolean</code></td>
1091</tr>
1092<tr>
1093 <td>B</td>
1094 <td><code>byte</code></td>
1095</tr>
1096<tr>
1097 <td>S</td>
1098 <td><code>short</code></td>
1099</tr>
1100<tr>
1101 <td>C</td>
1102 <td><code>char</code></td>
1103</tr>
1104<tr>
1105 <td>I</td>
1106 <td><code>int</code></td>
1107</tr>
1108<tr>
1109 <td>J</td>
1110 <td><code>long</code></td>
1111</tr>
1112<tr>
1113 <td>F</td>
1114 <td><code>float</code></td>
1115</tr>
1116<tr>
1117 <td>D</td>
1118 <td><code>double</code></td>
1119</tr>
1120<tr>
1121 <td>L<i>fully/qualified/Name</i>;</td>
1122 <td>the class <code><i>fully.qualified.Name</i></code></td>
1123</tr>
1124<tr>
1125 <td>[<i>descriptor</i></td>
1126 <td>array of <code><i>descriptor</i></code>, usable recursively for
1127 arrays-of-arrays, though it is invalid to have more than 255
1128 dimensions.
1129 </td>
1130</tr>
1131</tbody>
1132</table>
1133
Clay Murphy414d4712013-06-03 18:44:16 -07001134<h2>Items and Related Structures</h2>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001135
1136<p>This section includes definitions for each of the top-level items that
1137may appear in a <code>.dex</code> file.
1138
Clay Murphy945af1a2013-07-01 17:31:13 -07001139<h3>header_item</h3>
1140<h4>appears in the header section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001141<h4>alignment: 4 bytes</h4>
1142
1143<table class="format">
1144<thead>
1145<tr>
1146 <th>Name</th>
1147 <th>Format</th>
1148 <th>Description</th>
1149</tr>
1150</thead>
1151<tbody>
1152<tr>
1153 <td>magic</td>
1154 <td>ubyte[8] = DEX_FILE_MAGIC</td>
1155 <td>magic value. See discussion above under "<code>DEX_FILE_MAGIC</code>"
1156 for more details.
1157 </td>
1158</tr>
1159<tr>
1160 <td>checksum</td>
1161 <td>uint</td>
1162 <td>adler32 checksum of the rest of the file (everything but
1163 <code>magic</code> and this field); used to detect file corruption
1164 </td>
1165</tr>
1166<tr>
1167 <td>signature</td>
1168 <td>ubyte[20]</td>
1169 <td>SHA-1 signature (hash) of the rest of the file (everything but
1170 <code>magic</code>, <code>checksum</code>, and this field); used
1171 to uniquely identify files
1172 </td>
1173</tr>
1174<tr>
1175 <td>file_size</td>
1176 <td>uint</td>
1177 <td>size of the entire file (including the header), in bytes
1178</tr>
1179<tr>
1180 <td>header_size</td>
1181 <td>uint = 0x70</td>
1182 <td>size of the header (this entire section), in bytes. This allows for at
1183 least a limited amount of backwards/forwards compatibility without
1184 invalidating the format.
1185 </td>
1186</tr>
1187<tr>
1188 <td>endian_tag</td>
1189 <td>uint = ENDIAN_CONSTANT</td>
1190 <td>endianness tag. See discussion above under "<code>ENDIAN_CONSTANT</code>
1191 and <code>REVERSE_ENDIAN_CONSTANT</code>" for more details.
1192 </td>
1193</tr>
1194<tr>
1195 <td>link_size</td>
1196 <td>uint</td>
1197 <td>size of the link section, or <code>0</code> if this file isn't
1198 statically linked</td>
1199</tr>
1200<tr>
1201 <td>link_off</td>
1202 <td>uint</td>
1203 <td>offset from the start of the file to the link section, or
1204 <code>0</code> if <code>link_size == 0</code>. The offset, if non-zero,
1205 should be to an offset into the <code>link_data</code> section. The
1206 format of the data pointed at is left unspecified by this document;
1207 this header field (and the previous) are left as hooks for use by
1208 runtime implementations.
1209 </td>
1210</tr>
1211<tr>
1212 <td>map_off</td>
1213 <td>uint</td>
1214 <td>offset from the start of the file to the map item, or
1215 <code>0</code> if this file has no map. The offset, if non-zero,
1216 should be to an offset into the <code>data</code> section,
1217 and the data should be in the format specified by "<code>map_list</code>"
1218 below.
1219 </td>
1220</tr>
1221<tr>
1222 <td>string_ids_size</td>
1223 <td>uint</td>
1224 <td>count of strings in the string identifiers list</td>
1225</tr>
1226<tr>
1227 <td>string_ids_off</td>
1228 <td>uint</td>
1229 <td>offset from the start of the file to the string identifiers list, or
1230 <code>0</code> if <code>string_ids_size == 0</code> (admittedly a
1231 strange edge case). The offset, if non-zero,
1232 should be to the start of the <code>string_ids</code> section.
1233 </td>
1234</tr>
1235<tr>
1236 <td>type_ids_size</td>
1237 <td>uint</td>
1238 <td>count of elements in the type identifiers list</td>
1239</tr>
1240<tr>
1241 <td>type_ids_off</td>
1242 <td>uint</td>
1243 <td>offset from the start of the file to the type identifiers list, or
1244 <code>0</code> if <code>type_ids_size == 0</code> (admittedly a
1245 strange edge case). The offset, if non-zero,
1246 should be to the start of the <code>type_ids</code>
1247 section.
1248 </td>
1249</tr>
1250<tr>
1251 <td>proto_ids_size</td>
1252 <td>uint</td>
1253 <td>count of elements in the prototype identifiers list</td>
1254</tr>
1255<tr>
1256 <td>proto_ids_off</td>
1257 <td>uint</td>
1258 <td>offset from the start of the file to the prototype identifiers list, or
1259 <code>0</code> if <code>proto_ids_size == 0</code> (admittedly a
1260 strange edge case). The offset, if non-zero,
1261 should be to the start of the <code>proto_ids</code>
1262 section.
1263 </td>
1264</tr>
1265<tr>
1266 <td>field_ids_size</td>
1267 <td>uint</td>
1268 <td>count of elements in the field identifiers list</td>
1269</tr>
1270<tr>
1271 <td>field_ids_off</td>
1272 <td>uint</td>
1273 <td>offset from the start of the file to the field identifiers list, or
1274 <code>0</code> if <code>field_ids_size == 0</code>. The offset, if
1275 non-zero, should be to the start of the <code>field_ids</code>
1276 section.</td>
1277</td>
1278</tr>
1279<tr>
1280 <td>method_ids_size</td>
1281 <td>uint</td>
1282 <td>count of elements in the method identifiers list</td>
1283</tr>
1284<tr>
1285 <td>method_ids_off</td>
1286 <td>uint</td>
1287 <td>offset from the start of the file to the method identifiers list, or
1288 <code>0</code> if <code>method_ids_size == 0</code>. The offset, if
1289 non-zero, should be to the start of the <code>method_ids</code>
1290 section.</td>
1291</tr>
1292<tr>
1293 <td>class_defs_size</td>
1294 <td>uint</td>
1295 <td>count of elements in the class definitions list</td>
1296</tr>
1297<tr>
1298 <td>class_defs_off</td>
1299 <td>uint</td>
1300 <td>offset from the start of the file to the class definitions list, or
1301 <code>0</code> if <code>class_defs_size == 0</code> (admittedly a
1302 strange edge case). The offset, if non-zero,
1303 should be to the start of the <code>class_defs</code> section.
1304 </td>
1305</tr>
1306<tr>
1307 <td>data_size</td>
1308 <td>uint</td>
1309 <td>Size of <code>data</code> section in bytes. Must be an even
1310 multiple of sizeof(uint).</td>
1311</tr>
1312<tr>
1313 <td>data_off</td>
1314 <td>uint</td>
1315 <td>offset from the start of the file to the start of the
1316 <code>data</code> section.
1317 </td>
1318</tr>
1319</tbody>
1320</table>
1321
Clay Murphy945af1a2013-07-01 17:31:13 -07001322<h3>map_list</h3>
1323<h4>appears in the data section</h4>
1324<h4>referenced from header_item</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001325<h4>alignment: 4 bytes</h4>
1326
1327<p>This is a list of the entire contents of a file, in order. It
1328contains some redundancy with respect to the <code>header_item</code>
1329but is intended to be an easy form to use to iterate over an entire
Elliott Hughes8d777942012-01-05 17:27:02 -08001330file. A given type must appear at most once in a map, but there is no
Dan Bornstein25705bc2011-04-12 16:23:13 -07001331restriction on what order types may appear in, other than the
1332restrictions implied by the rest of the format (e.g., a
1333<code>header</code> section must appear first, followed by a
1334<code>string_ids</code> section, etc.). Additionally, the map entries must
1335be ordered by initial offset and must not overlap.</p>
1336
1337<table class="format">
1338<thead>
1339<tr>
1340 <th>Name</th>
1341 <th>Format</th>
1342 <th>Description</th>
1343</tr>
1344</thead>
1345<tbody>
1346<tr>
1347 <td>size</td>
1348 <td>uint</td>
1349 <td>size of the list, in entries</td>
1350</tr>
1351<tr>
1352 <td>list</td>
1353 <td>map_item[size]</td>
1354 <td>elements of the list</td>
1355</tr>
1356</tbody>
1357</table>
1358
Clay Murphy945af1a2013-07-01 17:31:13 -07001359<h3>map_item Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001360
1361<table class="format">
1362<thead>
1363<tr>
1364 <th>Name</th>
1365 <th>Format</th>
1366 <th>Description</th>
1367</tr>
1368</thead>
1369<tbody>
1370<tr>
1371 <td>type</td>
1372 <td>ushort</td>
1373 <td>type of the items; see table below</td>
1374</tr>
1375<tr>
1376 <td>unused</td>
1377 <td>ushort</td>
1378 <td><i>(unused)</i></td>
1379</tr>
1380<tr>
1381 <td>size</td>
1382 <td>uint</td>
1383 <td>count of the number of items to be found at the indicated offset</td>
1384</tr>
1385<tr>
1386 <td>offset</td>
1387 <td>uint</td>
1388 <td>offset from the start of the file to the items in question</td>
1389</tr>
1390</tbody>
1391</table>
1392
1393
1394<h3>Type Codes</h3>
1395
1396<table class="typeCodes">
1397<thead>
1398<tr>
1399 <th>Item Type</th>
1400 <th>Constant</th>
1401 <th>Value</th>
1402 <th>Item Size In Bytes</th>
1403</tr>
1404</thead>
1405<tbody>
1406<tr>
1407 <td>header_item</td>
1408 <td>TYPE_HEADER_ITEM</td>
1409 <td>0x0000</td>
1410 <td>0x70</td>
1411</tr>
1412<tr>
1413 <td>string_id_item</td>
1414 <td>TYPE_STRING_ID_ITEM</td>
1415 <td>0x0001</td>
1416 <td>0x04</td>
1417</tr>
1418<tr>
1419 <td>type_id_item</td>
1420 <td>TYPE_TYPE_ID_ITEM</td>
1421 <td>0x0002</td>
1422 <td>0x04</td>
1423</tr>
1424<tr>
1425 <td>proto_id_item</td>
1426 <td>TYPE_PROTO_ID_ITEM</td>
1427 <td>0x0003</td>
1428 <td>0x0c</td>
1429</tr>
1430<tr>
1431 <td>field_id_item</td>
1432 <td>TYPE_FIELD_ID_ITEM</td>
1433 <td>0x0004</td>
1434 <td>0x08</td>
1435</tr>
1436<tr>
1437 <td>method_id_item</td>
1438 <td>TYPE_METHOD_ID_ITEM</td>
1439 <td>0x0005</td>
1440 <td>0x08</td>
1441</tr>
1442<tr>
1443 <td>class_def_item</td>
1444 <td>TYPE_CLASS_DEF_ITEM</td>
1445 <td>0x0006</td>
1446 <td>0x20</td>
1447</tr>
1448<tr>
1449 <td>map_list</td>
1450 <td>TYPE_MAP_LIST</td>
1451 <td>0x1000</td>
1452 <td>4 + (item.size * 12)</td>
1453</tr>
1454<tr>
1455 <td>type_list</td>
1456 <td>TYPE_TYPE_LIST</td>
1457 <td>0x1001</td>
1458 <td>4 + (item.size * 2)</td>
1459</tr>
1460<tr>
1461 <td>annotation_set_ref_list</td>
1462 <td>TYPE_ANNOTATION_SET_REF_LIST</td>
1463 <td>0x1002</td>
1464 <td>4 + (item.size * 4)</td>
1465</tr>
1466<tr>
1467 <td>annotation_set_item</td>
1468 <td>TYPE_ANNOTATION_SET_ITEM</td>
1469 <td>0x1003</td>
1470 <td>4 + (item.size * 4)</td>
1471</tr>
1472<tr>
1473 <td>class_data_item</td>
1474 <td>TYPE_CLASS_DATA_ITEM</td>
1475 <td>0x2000</td>
1476 <td><i>implicit; must parse</i></td>
1477</tr>
1478<tr>
1479 <td>code_item</td>
1480 <td>TYPE_CODE_ITEM</td>
1481 <td>0x2001</td>
1482 <td><i>implicit; must parse</i></td>
1483</tr>
1484<tr>
1485 <td>string_data_item</td>
1486 <td>TYPE_STRING_DATA_ITEM</td>
1487 <td>0x2002</td>
1488 <td><i>implicit; must parse</i></td>
1489</tr>
1490<tr>
1491 <td>debug_info_item</td>
1492 <td>TYPE_DEBUG_INFO_ITEM</td>
1493 <td>0x2003</td>
1494 <td><i>implicit; must parse</i></td>
1495</tr>
1496<tr>
1497 <td>annotation_item</td>
1498 <td>TYPE_ANNOTATION_ITEM</td>
1499 <td>0x2004</td>
1500 <td><i>implicit; must parse</i></td>
1501</tr>
1502<tr>
1503 <td>encoded_array_item</td>
1504 <td>TYPE_ENCODED_ARRAY_ITEM</td>
1505 <td>0x2005</td>
1506 <td><i>implicit; must parse</i></td>
1507</tr>
1508<tr>
1509 <td>annotations_directory_item</td>
1510 <td>TYPE_ANNOTATIONS_DIRECTORY_ITEM</td>
1511 <td>0x2006</td>
1512 <td><i>implicit; must parse</i></td>
1513</tr>
1514</tbody>
1515</table>
1516
1517
Clay Murphy945af1a2013-07-01 17:31:13 -07001518<h3>string_id_item</h3>
1519<h4>appears in the string_ids section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001520<h4>alignment: 4 bytes</h4>
1521
1522<table class="format">
1523<thead>
1524<tr>
1525 <th>Name</th>
1526 <th>Format</th>
1527 <th>Description</th>
1528</tr>
1529</thead>
1530<tbody>
1531<tr>
1532 <td>string_data_off</td>
1533 <td>uint</td>
1534 <td>offset from the start of the file to the string data for this
1535 item. The offset should be to a location
1536 in the <code>data</code> section, and the data should be in the
1537 format specified by "<code>string_data_item</code>" below.
1538 There is no alignment requirement for the offset.
1539 </td>
1540</tr>
1541</tbody>
1542</table>
1543
Clay Murphy945af1a2013-07-01 17:31:13 -07001544<h3>string_data_item</h3>
1545<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001546<h4>alignment: none (byte-aligned)</h4>
1547
1548<table class="format">
1549<thead>
1550<tr>
1551 <th>Name</th>
1552 <th>Format</th>
1553 <th>Description</th>
1554</tr>
1555</thead>
1556<tbody>
1557<tr>
1558 <td>utf16_size</td>
1559 <td>uleb128</td>
1560 <td>size of this string, in UTF-16 code units (which is the "string
1561 length" in many systems). That is, this is the decoded length of
1562 the string. (The encoded length is implied by the position of
1563 the <code>0</code> byte.)</td>
1564</tr>
1565<tr>
1566 <td>data</td>
1567 <td>ubyte[]</td>
1568 <td>a series of MUTF-8 code units (a.k.a. octets, a.k.a. bytes)
1569 followed by a byte of value <code>0</code>. See
1570 "MUTF-8 (Modified UTF-8) Encoding" above for details and
1571 discussion about the data format.
1572 <p><b>Note:</b> It is acceptable to have a string which includes
1573 (the encoded form of) UTF-16 surrogate code units (that is,
1574 <code>U+d800</code> &hellip; <code>U+dfff</code>)
1575 either in isolation or out-of-order with respect to the usual
1576 encoding of Unicode into UTF-16. It is up to higher-level uses of
1577 strings to reject such invalid encodings, if appropriate.</p>
1578 </td>
1579</tr>
1580</tbody>
1581</table>
1582
Clay Murphy945af1a2013-07-01 17:31:13 -07001583<h3>type_id_item</h3>
1584<h4>appears in the type_ids section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001585<h4>alignment: 4 bytes</h4>
1586
1587<table class="format">
1588<thead>
1589<tr>
1590 <th>Name</th>
1591 <th>Format</th>
1592 <th>Description</th>
1593</tr>
1594</thead>
1595<tbody>
1596<tr>
1597 <td>descriptor_idx</td>
1598 <td>uint</td>
1599 <td>index into the <code>string_ids</code> list for the descriptor
1600 string of this type. The string must conform to the syntax for
1601 <i>TypeDescriptor</i>, defined above.
1602 </td>
1603</tr>
1604</tbody>
1605</table>
1606
Clay Murphy945af1a2013-07-01 17:31:13 -07001607<h3>proto_id_item</h3>
1608<h4>appears in the proto_ids section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001609<h4>alignment: 4 bytes</h4>
1610
1611<table class="format">
1612<thead>
1613<tr>
1614 <th>Name</th>
1615 <th>Format</th>
1616 <th>Description</th>
1617</tr>
1618</thead>
1619<tbody>
1620<tr>
1621 <td>shorty_idx</td>
1622 <td>uint</td>
1623 <td>index into the <code>string_ids</code> list for the short-form
1624 descriptor string of this prototype. The string must conform to the
1625 syntax for <i>ShortyDescriptor</i>, defined above, and must correspond
1626 to the return type and parameters of this item.
1627 </td>
1628</tr>
1629<tr>
1630 <td>return_type_idx</td>
1631 <td>uint</td>
1632 <td>index into the <code>type_ids</code> list for the return type
1633 of this prototype
1634 </td>
1635</tr>
1636<tr>
1637 <td>parameters_off</td>
1638 <td>uint</td>
1639 <td>offset from the start of the file to the list of parameter types
1640 for this prototype, or <code>0</code> if this prototype has no
1641 parameters. This offset, if non-zero, should be in the
1642 <code>data</code> section, and the data there should be in the
1643 format specified by <code>"type_list"</code> below. Additionally, there
1644 should be no reference to the type <code>void</code> in the list.
1645 </td>
1646</tr>
1647</tbody>
1648</table>
1649
Clay Murphy945af1a2013-07-01 17:31:13 -07001650<h3>field_id_item</h3>
1651<h4>appears in the field_ids section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001652<h4>alignment: 4 bytes</h4>
1653
1654<table class="format">
1655<thead>
1656<tr>
1657 <th>Name</th>
1658 <th>Format</th>
1659 <th>Description</th>
1660</tr>
1661</thead>
1662<tbody>
1663<tr>
1664 <td>class_idx</td>
1665 <td>ushort</td>
1666 <td>index into the <code>type_ids</code> list for the definer of this
1667 field. This must be a class type, and not an array or primitive type.
1668 </td>
1669</tr>
1670<tr>
1671 <td>type_idx</td>
1672 <td>ushort</td>
1673 <td>index into the <code>type_ids</code> list for the type of
1674 this field
1675 </td>
1676</tr>
1677<tr>
1678 <td>name_idx</td>
1679 <td>uint</td>
1680 <td>index into the <code>string_ids</code> list for the name of this
1681 field. The string must conform to the syntax for <i>MemberName</i>,
1682 defined above.
1683 </td>
1684</tr>
1685</tbody>
1686</table>
1687
Clay Murphy945af1a2013-07-01 17:31:13 -07001688<h3>method_id_item</h3>
1689<h4>appears in the method_ids section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001690<h4>alignment: 4 bytes</h4>
1691
1692<table class="format">
1693<thead>
1694<tr>
1695 <th>Name</th>
1696 <th>Format</th>
1697 <th>Description</th>
1698</tr>
1699</thead>
1700<tbody>
1701<tr>
1702 <td>class_idx</td>
1703 <td>ushort</td>
1704 <td>index into the <code>type_ids</code> list for the definer of this
1705 method. This must be a class or array type, and not a primitive type.
1706 </td>
1707</tr>
1708<tr>
1709 <td>proto_idx</td>
1710 <td>ushort</td>
1711 <td>index into the <code>proto_ids</code> list for the prototype of
1712 this method
1713 </td>
1714</tr>
1715<tr>
1716 <td>name_idx</td>
1717 <td>uint</td>
1718 <td>index into the <code>string_ids</code> list for the name of this
1719 method. The string must conform to the syntax for <i>MemberName</i>,
1720 defined above.
1721 </td>
1722</tr>
1723</tbody>
1724</table>
1725
Clay Murphy945af1a2013-07-01 17:31:13 -07001726<h3>class_def_item</h3>
1727<h4>appears in the class_defs section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001728<h4>alignment: 4 bytes</h4>
1729
1730<table class="format">
1731<thead>
1732<tr>
1733 <th>Name</th>
1734 <th>Format</th>
1735 <th>Description</th>
1736</tr>
1737</thead>
1738<tbody>
1739<tr>
1740 <td>class_idx</td>
1741 <td>uint</td>
1742 <td>index into the <code>type_ids</code> list for this class.
1743 This must be a class type, and not an array or primitive type.
1744 </td>
1745</tr>
1746<tr>
1747 <td>access_flags</td>
1748 <td>uint</td>
1749 <td>access flags for the class (<code>public</code>, <code>final</code>,
1750 etc.). See "<code>access_flags</code> Definitions" for details.
1751 </td>
1752</tr>
1753<tr>
1754 <td>superclass_idx</td>
1755 <td>uint</td>
1756 <td>index into the <code>type_ids</code> list for the superclass, or
1757 the constant value <code>NO_INDEX</code> if this class has no
1758 superclass (i.e., it is a root class such as <code>Object</code>).
1759 If present, this must be a class type, and not an array or primitive type.
1760 </td>
1761</tr>
1762<tr>
1763 <td>interfaces_off</td>
1764 <td>uint</td>
1765 <td>offset from the start of the file to the list of interfaces, or
1766 <code>0</code> if there are none. This offset
1767 should be in the <code>data</code> section, and the data
1768 there should be in the format specified by
1769 "<code>type_list</code>" below. Each of the elements of the list
1770 must be a class type (not an array or primitive type), and there
1771 must not be any duplicates.
1772 </td>
1773</tr>
1774<tr>
1775 <td>source_file_idx</td>
1776 <td>uint</td>
1777 <td>index into the <code>string_ids</code> list for the name of the
1778 file containing the original source for (at least most of) this class,
1779 or the special value <code>NO_INDEX</code> to represent a lack of
1780 this information. The <code>debug_info_item</code> of any given method
1781 may override this source file, but the expectation is that most classes
1782 will only come from one source file.
1783 </td>
1784</tr>
1785<tr>
1786 <td>annotations_off</td>
1787 <td>uint</td>
1788 <td>offset from the start of the file to the annotations structure
1789 for this class, or <code>0</code> if there are no annotations on
1790 this class. This offset, if non-zero, should be in the
1791 <code>data</code> section, and the data there should be in
1792 the format specified by "<code>annotations_directory_item</code>" below,
1793 with all items referring to this class as the definer.
1794 </td>
1795</tr>
1796<tr>
1797 <td>class_data_off</td>
1798 <td>uint</td>
1799 <td>offset from the start of the file to the associated
1800 class data for this item, or <code>0</code> if there is no class
1801 data for this class. (This may be the case, for example, if this class
1802 is a marker interface.) The offset, if non-zero, should be in the
1803 <code>data</code> section, and the data there should be in the
1804 format specified by "<code>class_data_item</code>" below, with all
1805 items referring to this class as the definer.
1806 </td>
1807</tr>
1808<tr>
1809 <td>static_values_off</td>
1810 <td>uint</td>
1811 <td>offset from the start of the file to the list of initial
1812 values for <code>static</code> fields, or <code>0</code> if there
1813 are none (and all <code>static</code> fields are to be initialized with
1814 <code>0</code> or <code>null</code>). This offset should be in the
1815 <code>data</code> section, and the data there should be in the
1816 format specified by "<code>encoded_array_item</code>" below. The size
1817 of the array must be no larger than the number of <code>static</code>
1818 fields declared by this class, and the elements correspond to the
1819 <code>static</code> fields in the same order as declared in the
1820 corresponding <code>field_list</code>. The type of each array
1821 element must match the declared type of its corresponding field.
1822 If there are fewer elements in the array than there are
1823 <code>static</code> fields, then the leftover fields are initialized
1824 with a type-appropriate <code>0</code> or <code>null</code>.
1825 </td>
1826</tr>
1827</tbody>
1828</table>
1829
Clay Murphy945af1a2013-07-01 17:31:13 -07001830<h3>class_data_item</h3>
1831<h4>referenced from class_def_item</h4>
1832<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001833<h4>alignment: none (byte-aligned)</h4>
1834
1835<table class="format">
1836<thead>
1837<tr>
1838 <th>Name</th>
1839 <th>Format</th>
1840 <th>Description</th>
1841</tr>
1842</thead>
1843<tbody>
1844<tr>
1845 <td>static_fields_size</td>
1846 <td>uleb128</td>
1847 <td>the number of static fields defined in this item</td>
1848</tr>
1849<tr>
1850 <td>instance_fields_size</td>
1851 <td>uleb128</td>
1852 <td>the number of instance fields defined in this item</td>
1853</tr>
1854<tr>
1855 <td>direct_methods_size</td>
1856 <td>uleb128</td>
1857 <td>the number of direct methods defined in this item</td>
1858</tr>
1859<tr>
1860 <td>virtual_methods_size</td>
1861 <td>uleb128</td>
1862 <td>the number of virtual methods defined in this item</td>
1863</tr>
1864<tr>
1865 <td>static_fields</td>
1866 <td>encoded_field[static_fields_size]</td>
1867 <td>the defined static fields, represented as a sequence of
1868 encoded elements. The fields must be sorted by
1869 <code>field_idx</code> in increasing order.
1870 </td>
1871</tr>
1872<tr>
1873 <td>instance_fields</td>
1874 <td>encoded_field[instance_fields_size]</td>
1875 <td>the defined instance fields, represented as a sequence of
1876 encoded elements. The fields must be sorted by
1877 <code>field_idx</code> in increasing order.
1878 </td>
1879</tr>
1880<tr>
1881 <td>direct_methods</td>
1882 <td>encoded_method[direct_methods_size]</td>
1883 <td>the defined direct (any of <code>static</code>, <code>private</code>,
1884 or constructor) methods, represented as a sequence of
1885 encoded elements. The methods must be sorted by
1886 <code>method_idx</code> in increasing order.
1887 </td>
1888</tr>
1889<tr>
1890 <td>virtual_methods</td>
1891 <td>encoded_method[virtual_methods_size]</td>
1892 <td>the defined virtual (none of <code>static</code>, <code>private</code>,
1893 or constructor) methods, represented as a sequence of
1894 encoded elements. This list should <i>not</i> include inherited
1895 methods unless overridden by the class that this item represents. The
1896 methods must be sorted by <code>method_idx</code> in increasing order.
1897 </td>
1898</tr>
1899</tbody>
1900</table>
1901
1902<p><b>Note:</b> All elements' <code>field_id</code>s and
1903<code>method_id</code>s must refer to the same defining class.</p>
1904
Clay Murphy945af1a2013-07-01 17:31:13 -07001905<h3>encoded_field Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001906
1907<table class="format">
1908<thead>
1909<tr>
1910 <th>Name</th>
1911 <th>Format</th>
1912 <th>Description</th>
1913</tr>
1914</thead>
1915<tbody>
1916<tr>
1917 <td>field_idx_diff</td>
1918 <td>uleb128</td>
1919 <td>index into the <code>field_ids</code> list for the identity of this
1920 field (includes the name and descriptor), represented as a difference
1921 from the index of previous element in the list. The index of the
1922 first element in a list is represented directly.
1923 </td>
1924</tr>
1925<tr>
1926 <td>access_flags</td>
1927 <td>uleb128</td>
1928 <td>access flags for the field (<code>public</code>, <code>final</code>,
1929 etc.). See "<code>access_flags</code> Definitions" for details.
1930 </td>
1931</tr>
1932</tbody>
1933</table>
1934
Clay Murphy945af1a2013-07-01 17:31:13 -07001935<h3>encoded_method Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001936
1937<table class="format">
1938<thead>
1939<tr>
1940 <th>Name</th>
1941 <th>Format</th>
1942 <th>Description</th>
1943</tr>
1944</thead>
1945<tbody>
1946<tr>
1947 <td>method_idx_diff</td>
1948 <td>uleb128</td>
1949 <td>index into the <code>method_ids</code> list for the identity of this
1950 method (includes the name and descriptor), represented as a difference
1951 from the index of previous element in the list. The index of the
1952 first element in a list is represented directly.
1953 </td>
1954</tr>
1955<tr>
1956 <td>access_flags</td>
1957 <td>uleb128</td>
1958 <td>access flags for the method (<code>public</code>, <code>final</code>,
1959 etc.). See "<code>access_flags</code> Definitions" for details.
1960 </td>
1961</tr>
1962<tr>
1963 <td>code_off</td>
1964 <td>uleb128</td>
1965 <td>offset from the start of the file to the code structure for this
1966 method, or <code>0</code> if this method is either <code>abstract</code>
1967 or <code>native</code>. The offset should be to a location in the
1968 <code>data</code> section. The format of the data is specified by
1969 "<code>code_item</code>" below.
1970 </td>
1971</tr>
1972</tbody>
1973</table>
1974
Clay Murphy945af1a2013-07-01 17:31:13 -07001975<h3>type_list</h3>
1976<h4>referenced from class_def_item and proto_id_item</h4>
1977<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07001978<h4>alignment: 4 bytes</h4>
1979
1980<table class="format">
1981<thead>
1982<tr>
1983 <th>Name</th>
1984 <th>Format</th>
1985 <th>Description</th>
1986</tr>
1987</thead>
1988<tbody>
1989<tr>
1990 <td>size</td>
1991 <td>uint</td>
1992 <td>size of the list, in entries</td>
1993</tr>
1994<tr>
1995 <td>list</td>
1996 <td>type_item[size]</td>
1997 <td>elements of the list</td>
1998</tr>
1999</tbody>
2000</table>
2001
Clay Murphy945af1a2013-07-01 17:31:13 -07002002<h3>type_item Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002003
2004<table class="format">
2005<thead>
2006<tr>
2007 <th>Name</th>
2008 <th>Format</th>
2009 <th>Description</th>
2010</tr>
2011</thead>
2012<tbody>
2013<tr>
2014 <td>type_idx</td>
2015 <td>ushort</td>
2016 <td>index into the <code>type_ids</code> list</td>
2017</tr>
2018</tbody>
2019</table>
2020
Clay Murphy945af1a2013-07-01 17:31:13 -07002021<h3>code_item</h3>
2022<h4>referenced from encoded_method</h4>
2023<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002024<h4>alignment: 4 bytes</h4>
2025
2026<table class="format">
2027<thead>
2028<tr>
2029 <th>Name</th>
2030 <th>Format</th>
2031 <th>Description</th>
2032</tr>
2033</thead>
2034<tbody>
2035<tr>
2036 <td>registers_size</td>
2037 <td>ushort</td>
2038 <td>the number of registers used by this code</td>
2039</tr>
2040<tr>
2041 <td>ins_size</td>
2042 <td>ushort</td>
2043 <td>the number of words of incoming arguments to the method that this
2044 code is for</td>
2045</tr>
2046<tr>
2047 <td>outs_size</td>
2048 <td>ushort</td>
2049 <td>the number of words of outgoing argument space required by this
2050 code for method invocation
2051 </td>
2052</tr>
2053<tr>
2054 <td>tries_size</td>
2055 <td>ushort</td>
2056 <td>the number of <code>try_item</code>s for this instance. If non-zero,
2057 then these appear as the <code>tries</code> array just after the
2058 <code>insns</code> in this instance.
2059 </td>
2060</tr>
2061<tr>
2062 <td>debug_info_off</td>
2063 <td>uint</td>
2064 <td>offset from the start of the file to the debug info (line numbers +
2065 local variable info) sequence for this code, or <code>0</code> if
2066 there simply is no information. The offset, if non-zero, should be
2067 to a location in the <code>data</code> section. The format of
2068 the data is specified by "<code>debug_info_item</code>" below.
2069 </td>
2070</tr>
2071<tr>
2072 <td>insns_size</td>
2073 <td>uint</td>
2074 <td>size of the instructions list, in 16-bit code units</td>
2075</tr>
2076<tr>
2077 <td>insns</td>
2078 <td>ushort[insns_size]</td>
2079 <td>actual array of bytecode. The format of code in an <code>insns</code>
2080 array is specified by the companion document
2081 <a href="dalvik-bytecode.html">"Bytecode for the Dalvik VM"</a>. Note
2082 that though this is defined as an array of <code>ushort</code>, there
2083 are some internal structures that prefer four-byte alignment. Also,
2084 if this happens to be in an endian-swapped file, then the swapping is
2085 <i>only</i> done on individual <code>ushort</code>s and not on the
2086 larger internal structures.
2087 </td>
2088</tr>
2089<tr>
2090 <td>padding</td>
2091 <td>ushort <i>(optional)</i> = 0</td>
2092 <td>two bytes of padding to make <code>tries</code> four-byte aligned.
2093 This element is only present if <code>tries_size</code> is non-zero
2094 and <code>insns_size</code> is odd.
2095 </td>
2096</tr>
2097<tr>
2098 <td>tries</td>
2099 <td>try_item[tries_size] <i>(optional)</i></td>
Elliott Hughes8d777942012-01-05 17:27:02 -08002100 <td>array indicating where in the code exceptions are caught and
Dan Bornstein25705bc2011-04-12 16:23:13 -07002101 how to handle them. Elements of the array must be non-overlapping in
2102 range and in order from low to high address. This element is only
2103 present if <code>tries_size</code> is non-zero.
2104 </td>
2105</tr>
2106<tr>
2107 <td>handlers</td>
2108 <td>encoded_catch_handler_list <i>(optional)</i></td>
2109 <td>bytes representing a list of lists of catch types and associated
2110 handler addresses. Each <code>try_item</code> has a byte-wise offset
2111 into this structure. This element is only present if
2112 <code>tries_size</code> is non-zero.
2113 </td>
2114</tr>
2115</tbody>
2116</table>
2117
Clay Murphy945af1a2013-07-01 17:31:13 -07002118<h3>try_item Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002119
2120<table class="format">
2121<thead>
2122<tr>
2123 <th>Name</th>
2124 <th>Format</th>
2125 <th>Description</th>
2126</tr>
2127</thead>
2128<tbody>
2129<tr>
2130 <td>start_addr</td>
2131 <td>uint</td>
2132 <td>start address of the block of code covered by this entry. The address
2133 is a count of 16-bit code units to the start of the first covered
2134 instruction.
2135 </td>
2136</tr>
2137<tr>
2138 <td>insn_count</td>
2139 <td>ushort</td>
2140 <td>number of 16-bit code units covered by this entry. The last code
2141 unit covered (inclusive) is <code>start_addr + insn_count - 1</code>.
2142 </td>
2143</tr>
2144<tr>
2145 <td>handler_off</td>
2146 <td>ushort</td>
Elliott Hughes8d777942012-01-05 17:27:02 -08002147 <td>offset in bytes from the start of the associated
2148 <code>encoded_catch_hander_list</code> to the
2149 <code>encoded_catch_handler</code> for this entry. This must be an
2150 offset to the start of an <code>encoded_catch_handler</code>.
Dan Bornstein25705bc2011-04-12 16:23:13 -07002151 </td>
2152</tr>
2153</tbody>
2154</table>
2155
Clay Murphy945af1a2013-07-01 17:31:13 -07002156<h3>encoded_catch_handler_list Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002157
2158<table class="format">
2159<thead>
2160<tr>
2161 <th>Name</th>
2162 <th>Format</th>
2163 <th>Description</th>
2164</tr>
2165</thead>
2166<tbody>
2167<tr>
2168 <td>size</td>
2169 <td>uleb128</td>
2170 <td>size of this list, in entries</td>
2171</tr>
2172<tr>
2173 <td>list</td>
2174 <td>encoded_catch_handler[handlers_size]</td>
2175 <td>actual list of handler lists, represented directly (not as offsets),
2176 and concatenated sequentially</td>
2177</tr>
2178</tbody>
2179</table>
2180
Clay Murphy945af1a2013-07-01 17:31:13 -07002181<h3>encoded_catch_handler Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002182
2183<table class="format">
2184<thead>
2185<tr>
2186 <th>Name</th>
2187 <th>Format</th>
2188 <th>Description</th>
2189</tr>
2190</thead>
2191<tbody>
2192<tr>
2193 <td>size</td>
2194 <td>sleb128</td>
2195 <td>number of catch types in this list. If non-positive, then this is
2196 the negative of the number of catch types, and the catches are followed
2197 by a catch-all handler. For example: A <code>size</code> of <code>0</code>
2198 means that there is a catch-all but no explicitly typed catches.
2199 A <code>size</code> of <code>2</code> means that there are two explicitly
2200 typed catches and no catch-all. And a <code>size</code> of <code>-1</code>
2201 means that there is one typed catch along with a catch-all.
2202 </td>
2203</tr>
2204<tr>
2205 <td>handlers</td>
2206 <td>encoded_type_addr_pair[abs(size)]</td>
2207 <td>stream of <code>abs(size)</code> encoded items, one for each caught
2208 type, in the order that the types should be tested.
2209 </td>
2210</tr>
2211<tr>
2212 <td>catch_all_addr</td>
2213 <td>uleb128 <i>(optional)</i></td>
2214 <td>bytecode address of the catch-all handler. This element is only
2215 present if <code>size</code> is non-positive.
2216 </td>
2217</tr>
2218</tbody>
2219</table>
2220
Clay Murphy945af1a2013-07-01 17:31:13 -07002221<h3>encoded_type_addr_pair Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002222
2223<table class="format">
2224<thead>
2225<tr>
2226 <th>Name</th>
2227 <th>Format</th>
2228 <th>Description</th>
2229</tr>
2230</thead>
2231<tbody>
2232<tr>
2233 <td>type_idx</td>
2234 <td>uleb128</td>
2235 <td>index into the <code>type_ids</code> list for the type of the
2236 exception to catch
2237 </td>
2238</tr>
2239<tr>
2240 <td>addr</td>
2241 <td>uleb128</td>
2242 <td>bytecode address of the associated exception handler</td>
2243</tr>
2244</tbody>
2245</table>
2246
Clay Murphy945af1a2013-07-01 17:31:13 -07002247<h3>debug_info_item</h3>
2248<h4>referenced from code_item</h4>
2249<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002250<h4>alignment: none (byte-aligned)</h4>
2251
2252<p>Each <code>debug_info_item</code> defines a DWARF3-inspired byte-coded
2253state machine that, when interpreted, emits the positions
2254table and (potentially) the local variable information for a
2255<code>code_item</code>. The sequence begins with a variable-length
2256header (the length of which depends on the number of method
2257parameters), is followed by the state machine bytecodes, and ends
2258with an <code>DBG_END_SEQUENCE</code> byte.</p>
2259
2260<p>The state machine consists of five registers. The
2261<code>address</code> register represents the instruction offset in the
2262associated <code>insns_item</code> in 16-bit code units. The
2263<code>address</code> register starts at <code>0</code> at the beginning of each
Elliott Hughes8d777942012-01-05 17:27:02 -08002264<code>debug_info</code> sequence and must only monotonically increase.
Dan Bornstein25705bc2011-04-12 16:23:13 -07002265The <code>line</code> register represents what source line number
2266should be associated with the next positions table entry emitted by
2267the state machine. It is initialized in the sequence header, and may
2268change in positive or negative directions but must never be less than
2269<code>1</code>. The <code>source_file</code> register represents the
2270source file that the line number entries refer to. It is initialized to
2271the value of <code>source_file_idx</code> in <code>class_def_item</code>.
2272The other two variables, <code>prologue_end</code> and
2273<code>epilogue_begin</code>, are boolean flags (initialized to
2274<code>false</code>) that indicate whether the next position emitted
2275should be considered a method prologue or epilogue. The state machine
2276must also track the name and type of the last local variable live in
2277each register for the <code>DBG_RESTART_LOCAL</code> code.</p>
2278
2279<p>The header is as follows:</p>
2280
2281<table class="format">
2282<thead>
2283<tr>
2284 <th>Name</th>
2285 <th>Format</th>
2286 <th>Description</th>
2287</tr>
2288</thead>
2289<tbody>
2290<tr>
2291 <td>line_start</td>
2292 <td>uleb128</td>
2293 <td>the initial value for the state machine's <code>line</code> register.
2294 Does not represent an actual positions entry.
2295 </td>
2296</tr>
2297<tr>
2298 <td>parameters_size</td>
2299 <td>uleb128</td>
2300 <td>the number of parameter names that are encoded. There should be
2301 one per method parameter, excluding an instance method's <code>this</code>,
2302 if any.
2303 </td>
2304</tr>
2305<tr>
2306 <td>parameter_names</td>
2307 <td>uleb128p1[parameters_size]</td>
2308 <td>string index of the method parameter name. An encoded value of
2309 <code>NO_INDEX</code> indicates that no name
2310 is available for the associated parameter. The type descriptor
2311 and signature are implied from the method descriptor and signature.
2312 </td>
2313</tr>
2314</tbody>
2315</table>
2316
2317<p>The byte code values are as follows:</p>
2318
2319<table class="debugByteCode">
2320<thead>
2321<tr>
2322 <th>Name</th>
2323 <th>Value</th>
2324 <th>Format</th>
2325 <th>Arguments</th>
2326 <th>Description</th>
2327</tr>
2328</thead>
2329<tbody>
2330<tr>
2331 <td>DBG_END_SEQUENCE</td>
2332 <td>0x00</td>
2333 <td></td>
2334 <td><i>(none)</i></td>
2335 <td>terminates a debug info sequence for a <code>code_item</code></td>
2336</tr>
2337<tr>
2338 <td>DBG_ADVANCE_PC</td>
2339 <td>0x01</td>
2340 <td>uleb128&nbsp;addr_diff</td>
2341 <td><code>addr_diff</code>: amount to add to address register</td>
2342 <td>advances the address register without emitting a positions entry</td>
2343</tr>
2344<tr>
2345 <td>DBG_ADVANCE_LINE</td>
2346 <td>0x02</td>
2347 <td>sleb128&nbsp;line_diff</td>
2348 <td><code>line_diff</code>: amount to change line register by</td>
2349 <td>advances the line register without emitting a positions entry</td>
2350</tr>
2351<tr>
2352 <td>DBG_START_LOCAL</td>
2353 <td>0x03</td>
2354 <td>uleb128&nbsp;register_num<br/>
2355 uleb128p1&nbsp;name_idx<br/>
2356 uleb128p1&nbsp;type_idx
2357 </td>
2358 <td><code>register_num</code>: register that will contain local<br/>
2359 <code>name_idx</code>: string index of the name<br/>
2360 <code>type_idx</code>: type index of the type
2361 </td>
2362 <td>introduces a local variable at the current address. Either
2363 <code>name_idx</code> or <code>type_idx</code> may be
2364 <code>NO_INDEX</code> to indicate that that value is unknown.
2365 </td>
2366</tr>
2367<tr>
2368 <td>DBG_START_LOCAL_EXTENDED</td>
2369 <td>0x04</td>
2370 <td>uleb128&nbsp;register_num<br/>
2371 uleb128p1&nbsp;name_idx<br/>
2372 uleb128p1&nbsp;type_idx<br/>
2373 uleb128p1&nbsp;sig_idx
2374 </td>
2375 <td><code>register_num</code>: register that will contain local<br/>
2376 <code>name_idx</code>: string index of the name<br/>
2377 <code>type_idx</code>: type index of the type<br/>
2378 <code>sig_idx</code>: string index of the type signature
2379 </td>
2380 <td>introduces a local with a type signature at the current address.
2381 Any of <code>name_idx</code>, <code>type_idx</code>, or
2382 <code>sig_idx</code> may be <code>NO_INDEX</code>
2383 to indicate that that value is unknown. (If <code>sig_idx</code> is
2384 <code>-1</code>, though, the same data could be represented more
2385 efficiently using the opcode <code>DBG_START_LOCAL</code>.)
2386 <p><b>Note:</b> See the discussion under
2387 "<code>dalvik.annotation.Signature</code>" below for caveats about
2388 handling signatures.</p>
2389 </td>
2390</tr>
2391<tr>
2392 <td>DBG_END_LOCAL</td>
2393 <td>0x05</td>
2394 <td>uleb128&nbsp;register_num</td>
2395 <td><code>register_num</code>: register that contained local</td>
2396 <td>marks a currently-live local variable as out of scope at the current
2397 address
2398 </td>
2399</tr>
2400<tr>
2401 <td>DBG_RESTART_LOCAL</td>
2402 <td>0x06</td>
2403 <td>uleb128&nbsp;register_num</td>
2404 <td><code>register_num</code>: register to restart</td>
2405 <td>re-introduces a local variable at the current address. The name
2406 and type are the same as the last local that was live in the specified
2407 register.
2408 </td>
2409</tr>
2410<tr>
2411 <td>DBG_SET_PROLOGUE_END</td>
2412 <td>0x07</td>
2413 <td></td>
2414 <td><i>(none)</i></td>
2415 <td>sets the <code>prologue_end</code> state machine register,
2416 indicating that the next position entry that is added should be
2417 considered the end of a method prologue (an appropriate place for
2418 a method breakpoint). The <code>prologue_end</code> register is
2419 cleared by any special (<code>&gt;= 0x0a</code>) opcode.
2420 </td>
2421</tr>
2422<tr>
2423 <td>DBG_SET_EPILOGUE_BEGIN</td>
2424 <td>0x08</td>
2425 <td></td>
2426 <td><i>(none)</i></td>
2427 <td>sets the <code>epilogue_begin</code> state machine register,
2428 indicating that the next position entry that is added should be
2429 considered the beginning of a method epilogue (an appropriate place
2430 to suspend execution before method exit).
2431 The <code>epilogue_begin</code> register is cleared by any special
2432 (<code>&gt;= 0x0a</code>) opcode.
2433 </td>
2434</tr>
2435<tr>
2436 <td>DBG_SET_FILE</td>
2437 <td>0x09</td>
2438 <td>uleb128p1&nbsp;name_idx</td>
2439 <td><code>name_idx</code>: string index of source file name;
2440 <code>NO_INDEX</code> if unknown
2441 </td>
2442 <td>indicates that all subsequent line number entries make reference to this
2443 source file name, instead of the default name specified in
2444 <code>code_item</code>
2445 </td>
2446</tr>
2447<tr>
2448 <td><i>Special Opcodes</i></td>
2449 <!-- When updating the range below, make sure to search for other
2450 instances of 0x0a in this section. -->
2451 <td>0x0a&hellip;0xff</td>
2452 <td></td>
2453 <td><i>(none)</i></td>
2454 <td>advances the <code>line</code> and <code>address</code> registers,
2455 emits a position entry, and clears <code>prologue_end</code> and
2456 <code>epilogue_begin</code>. See below for description.
2457 </td>
2458</tr>
2459</tbody>
2460</table>
2461
2462<h3>Special Opcodes</h3>
2463
2464<p>Opcodes with values between <code>0x0a</code> and <code>0xff</code>
2465(inclusive) move both the <code>line</code> and <code>address</code>
2466registers by a small amount and then emit a new position table entry.
2467The formula for the increments are as follows:</p>
2468
2469<pre>
2470DBG_FIRST_SPECIAL = 0x0a // the smallest special opcode
2471DBG_LINE_BASE = -4 // the smallest line number increment
2472DBG_LINE_RANGE = 15 // the number of line increments represented
2473
2474adjusted_opcode = opcode - DBG_FIRST_SPECIAL
2475
2476line += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE)
2477address += (adjusted_opcode / DBG_LINE_RANGE)
2478</pre>
2479
Clay Murphy945af1a2013-07-01 17:31:13 -07002480<h3>annotations_directory_item</h3>
2481<h4>referenced from class_def_item</h4>
2482<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002483<h4>alignment: 4 bytes</h4>
2484
2485<table class="format">
2486<thead>
2487<tr>
2488 <th>Name</th>
2489 <th>Format</th>
2490 <th>Description</th>
2491</tr>
2492</thead>
2493<tbody>
2494<tr>
2495 <td>class_annotations_off</td>
2496 <td>uint</td>
2497 <td>offset from the start of the file to the annotations made directly
2498 on the class, or <code>0</code> if the class has no direct annotations.
2499 The offset, if non-zero, should be to a location in the
2500 <code>data</code> section. The format of the data is specified
2501 by "<code>annotation_set_item</code>" below.
2502 </td>
2503</tr>
2504<tr>
2505 <td>fields_size</td>
2506 <td>uint</td>
2507 <td>count of fields annotated by this item</td>
2508</tr>
2509<tr>
2510 <td>annotated_methods_size</td>
2511 <td>uint</td>
2512 <td>count of methods annotated by this item</td>
2513</tr>
2514<tr>
2515 <td>annotated_parameters_size</td>
2516 <td>uint</td>
2517 <td>count of method parameter lists annotated by this item</td>
2518</tr>
2519<tr>
2520 <td>field_annotations</td>
2521 <td>field_annotation[fields_size] <i>(optional)</i></td>
2522 <td>list of associated field annotations. The elements of the list must
2523 be sorted in increasing order, by <code>field_idx</code>.
2524 </td>
2525</tr>
2526<tr>
2527 <td>method_annotations</td>
2528 <td>method_annotation[methods_size] <i>(optional)</i></td>
2529 <td>list of associated method annotations. The elements of the list must
2530 be sorted in increasing order, by <code>method_idx</code>.
2531 </td>
2532</tr>
2533<tr>
2534 <td>parameter_annotations</td>
2535 <td>parameter_annotation[parameters_size] <i>(optional)</i></td>
2536 <td>list of associated method parameter annotations. The elements of the
2537 list must be sorted in increasing order, by <code>method_idx</code>.
2538 </td>
2539</tr>
2540</tbody>
2541</table>
2542
2543<p><b>Note:</b> All elements' <code>field_id</code>s and
2544<code>method_id</code>s must refer to the same defining class.</p>
2545
Clay Murphy945af1a2013-07-01 17:31:13 -07002546<h3>field_annotation Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002547
2548<table class="format">
2549<thead>
2550<tr>
2551 <th>Name</th>
2552 <th>Format</th>
2553 <th>Description</th>
2554</tr>
2555</thead>
2556<tbody>
2557<tr>
2558 <td>field_idx</td>
2559 <td>uint</td>
2560 <td>index into the <code>field_ids</code> list for the identity of the
2561 field being annotated
2562 </td>
2563</tr>
2564<tr>
2565 <td>annotations_off</td>
2566 <td>uint</td>
2567 <td>offset from the start of the file to the list of annotations for
2568 the field. The offset should be to a location in the <code>data</code>
2569 section. The format of the data is specified by
2570 "<code>annotation_set_item</code>" below.
2571 </td>
2572</tr>
2573</tbody>
2574</table>
2575
Clay Murphy945af1a2013-07-01 17:31:13 -07002576<h3>method_annotation Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002577
2578<table class="format">
2579<thead>
2580<tr>
2581 <th>Name</th>
2582 <th>Format</th>
2583 <th>Description</th>
2584</tr>
2585</thead>
2586<tbody>
2587<tr>
2588 <td>method_idx</td>
2589 <td>uint</td>
2590 <td>index into the <code>method_ids</code> list for the identity of the
2591 method being annotated
2592 </td>
2593</tr>
2594<tr>
2595 <td>annotations_off</td>
2596 <td>uint</td>
2597 <td>offset from the start of the file to the list of annotations for
2598 the method. The offset should be to a location in the
2599 <code>data</code> section. The format of the data is specified by
2600 "<code>annotation_set_item</code>" below.
2601 </td>
2602</tr>
2603</tbody>
2604</table>
2605
Clay Murphy945af1a2013-07-01 17:31:13 -07002606<h3>parameter_annotation Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002607
2608<table class="format">
2609<thead>
2610<tr>
2611 <th>Name</th>
2612 <th>Format</th>
2613 <th>Description</th>
2614</tr>
2615</thead>
2616<tbody>
2617<tr>
2618 <td>method_idx</td>
2619 <td>uint</td>
2620 <td>index into the <code>method_ids</code> list for the identity of the
2621 method whose parameters are being annotated
2622 </td>
2623</tr>
2624<tr>
2625 <td>annotations_off</td>
2626 <td>uint</td>
2627 <td>offset from the start of the file to the list of annotations for
2628 the method parameters. The offset should be to a location in the
2629 <code>data</code> section. The format of the data is specified by
2630 "<code>annotation_set_ref_list</code>" below.
2631 </td>
2632</tr>
2633</tbody>
2634</table>
2635
Clay Murphy945af1a2013-07-01 17:31:13 -07002636<h3>annotation_set_ref_list</h3>
2637<h4>referenced from parameter_annotations_item</h4>
2638<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002639<h4>alignment: 4 bytes</h4>
2640
2641<table class="format">
2642<thead>
2643<tr>
2644 <th>Name</th>
2645 <th>Format</th>
2646 <th>Description</th>
2647</tr>
2648</thead>
2649<tbody>
2650<tr>
2651 <td>size</td>
2652 <td>uint</td>
2653 <td>size of the list, in entries</td>
2654</tr>
2655<tr>
2656 <td>list</td>
2657 <td>annotation_set_ref_item[size]</td>
2658 <td>elements of the list</td>
2659</tr>
2660</tbody>
2661</table>
2662
Clay Murphy945af1a2013-07-01 17:31:13 -07002663<h3>annotation_set_ref_item Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002664
2665<table class="format">
2666<thead>
2667<tr>
2668 <th>Name</th>
2669 <th>Format</th>
2670 <th>Description</th>
2671</tr>
2672</thead>
2673<tbody>
2674<tr>
2675 <td>annotations_off</td>
2676 <td>uint</td>
2677 <td>offset from the start of the file to the referenced annotation set
2678 or <code>0</code> if there are no annotations for this element.
2679 The offset, if non-zero, should be to a location in the <code>data</code>
2680 section. The format of the data is specified by
2681 "<code>annotation_set_item</code>" below.
2682 </td>
2683</tr>
2684</tbody>
2685</table>
2686
Clay Murphy945af1a2013-07-01 17:31:13 -07002687<h3>annotation_set_item</h3>
2688<h4>referenced from annotations_directory_item, field_annotations_item,
2689method_annotations_item, and annotation_set_ref_item</h4>
2690<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002691<h4>alignment: 4 bytes</h4>
2692
2693<table class="format">
2694<thead>
2695<tr>
2696 <th>Name</th>
2697 <th>Format</th>
2698 <th>Description</th>
2699</tr>
2700</thead>
2701<tbody>
2702<tr>
2703 <td>size</td>
2704 <td>uint</td>
2705 <td>size of the set, in entries</td>
2706</tr>
2707<tr>
2708 <td>entries</td>
2709 <td>annotation_off_item[size]</td>
2710 <td>elements of the set. The elements must be sorted in increasing order,
2711 by <code>type_idx</code>.
2712 </td>
2713</tr>
2714</tbody>
2715</table>
2716
Clay Murphy945af1a2013-07-01 17:31:13 -07002717<h3>annotation_off_item Format</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002718
2719<table class="format">
2720<thead>
2721<tr>
2722 <th>Name</th>
2723 <th>Format</th>
2724 <th>Description</th>
2725</tr>
2726</thead>
2727<tbody>
2728<tr>
2729 <td>annotation_off</td>
2730 <td>uint</td>
2731 <td>offset from the start of the file to an annotation.
2732 The offset should be to a location in the <code>data</code> section,
2733 and the format of the data at that location is specified by
2734 "<code>annotation_item</code>" below.
2735 </td>
2736</tr>
2737</tbody>
2738</table>
2739
2740
Clay Murphy945af1a2013-07-01 17:31:13 -07002741<h3>annotation_item</h3>
2742<h4>referenced from annotation_set_item</h4>
2743<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002744<h4>alignment: none (byte-aligned)</h4>
2745
2746<table class="format">
2747<thead>
2748<tr>
2749 <th>Name</th>
2750 <th>Format</th>
2751 <th>Description</th>
2752</tr>
2753</thead>
2754<tbody>
2755<tr>
2756 <td>visibility</td>
2757 <td>ubyte</td>
2758 <td>intended visibility of this annotation (see below)</td>
2759</tr>
2760<tr>
2761 <td>annotation</td>
2762 <td>encoded_annotation</td>
2763 <td>encoded annotation contents, in the format described by
2764 "<code>encoded_annotation</code> Format" under
2765 "<code>encoded_value</code> Encoding" above.
2766 </td>
2767</tr>
2768</tbody>
2769</table>
2770
2771<h3>Visibility values</h3>
2772
2773<p>These are the options for the <code>visibility</code> field in an
2774<code>annotation_item</code>:</p>
2775
2776<table class="format">
2777<thead>
2778<tr>
2779 <th>Name</th>
2780 <th>Value</th>
2781 <th>Description</th>
2782</tr>
2783</thead>
2784<tbody>
2785<tr>
2786 <td>VISIBILITY_BUILD</td>
2787 <td>0x00</td>
2788 <td>intended only to be visible at build time (e.g., during compilation
2789 of other code)
2790 </td>
2791</tr>
2792<tr>
2793 <td>VISIBILITY_RUNTIME</td>
2794 <td>0x01</td>
2795 <td>intended to visible at runtime</td>
2796</tr>
2797<tr>
2798 <td>VISIBILITY_SYSTEM</td>
2799 <td>0x02</td>
2800 <td>intended to visible at runtime, but only to the underlying system
2801 (and not to regular user code)
2802 </td>
2803</tr>
2804</tbody>
2805</table>
2806
Clay Murphy945af1a2013-07-01 17:31:13 -07002807<h3>encoded_array_item</h3>
2808<h4>referenced from class_def_item</h4>
2809<h4>appears in the data section</h4>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002810<h4>alignment: none (byte-aligned)</h4>
2811
2812<table class="format">
2813<thead>
2814<tr>
2815 <th>Name</th>
2816 <th>Format</th>
2817 <th>Description</th>
2818</tr>
2819</thead>
2820<tbody>
2821<tr>
2822 <td>value</td>
2823 <td>encoded_array</td>
2824 <td>bytes representing the encoded array value, in the format specified
2825 by "<code>encoded_array</code> Format" under "<code>encoded_value</code>
2826 Encoding" above.
2827 </td>
2828</tr>
2829</tbody>
2830</table>
2831
Clay Murphy414d4712013-06-03 18:44:16 -07002832<h2>System Annotations</h2>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002833
2834<p>System annotations are used to represent various pieces of reflective
2835information about classes (and methods and fields). This information is
2836generally only accessed indirectly by client (non-system) code.</p>
2837
2838<p>System annotations are represented in <code>.dex</code> files as
2839annotations with visibility set to <code>VISIBILITY_SYSTEM</code>.
2840
Clay Murphy945af1a2013-07-01 17:31:13 -07002841<h3>dalvik.annotation.AnnotationDefault</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002842<h4>appears on methods in annotation interfaces</h4>
2843
2844<p>An <code>AnnotationDefault</code> annotation is attached to each
2845annotation interface which wishes to indicate default bindings.</p>
2846
2847<table class="format">
2848<thead>
2849<tr>
2850 <th>Name</th>
2851 <th>Format</th>
2852 <th>Description</th>
2853</tr>
2854</thead>
2855<tbody>
2856<tr>
2857 <td>value</td>
2858 <td>Annotation</td>
2859 <td>the default bindings for this annotation, represented as an annotation
2860 of this type. The annotation need not include all names defined by the
2861 annotation; missing names simply do not have defaults.
2862 </td>
2863</tr>
2864</tbody>
2865</table>
2866
Clay Murphy945af1a2013-07-01 17:31:13 -07002867<h3>dalvik.annotation.EnclosingClass</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002868<h4>appears on classes</h4>
2869
2870<p>An <code>EnclosingClass</code> annotation is attached to each class
2871which is either defined as a member of another class, per se, or is
2872anonymous but not defined within a method body (e.g., a synthetic
2873inner class). Every class that has this annotation must also have an
Elliott Hughes8d777942012-01-05 17:27:02 -08002874<code>InnerClass</code> annotation. Additionally, a class must not have
Dan Bornstein25705bc2011-04-12 16:23:13 -07002875both an <code>EnclosingClass</code> and an
2876<code>EnclosingMethod</code> annotation.</p>
2877
2878<table class="format">
2879<thead>
2880<tr>
2881 <th>Name</th>
2882 <th>Format</th>
2883 <th>Description</th>
2884</tr>
2885</thead>
2886<tbody>
2887<tr>
2888 <td>value</td>
2889 <td>Class</td>
2890 <td>the class which most closely lexically scopes this class</td>
2891</tr>
2892</tbody>
2893</table>
2894
Clay Murphy945af1a2013-07-01 17:31:13 -07002895<h3>dalvik.annotation.EnclosingMethod</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002896<h4>appears on classes</h4>
2897
2898<p>An <code>EnclosingMethod</code> annotation is attached to each class
2899which is defined inside a method body. Every class that has this
2900annotation must also have an <code>InnerClass</code> annotation.
Elliott Hughes8d777942012-01-05 17:27:02 -08002901Additionally, a class must not have both an <code>EnclosingClass</code>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002902and an <code>EnclosingMethod</code> annotation.</p>
2903
2904<table class="format">
2905<thead>
2906<tr>
2907 <th>Name</th>
2908 <th>Format</th>
2909 <th>Description</th>
2910</tr>
2911</thead>
2912<tbody>
2913<tr>
2914 <td>value</td>
2915 <td>Method</td>
2916 <td>the method which most closely lexically scopes this class</td>
2917</tr>
2918</tbody>
2919</table>
2920
Clay Murphy945af1a2013-07-01 17:31:13 -07002921<h3>dalvik.annotation.InnerClass</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002922<h4>appears on classes</h4>
2923
2924<p>An <code>InnerClass</code> annotation is attached to each class
2925which is defined in the lexical scope of another class's definition.
2926Any class which has this annotation must also have <i>either</i> an
2927<code>EnclosingClass</code> annotation <i>or</i> an
2928<code>EnclosingMethod</code> annotation.</p>
2929
2930<table class="format">
2931<thead>
2932<tr>
2933 <th>Name</th>
2934 <th>Format</th>
2935 <th>Description</th>
2936</tr>
2937</thead>
2938<tbody>
2939<tr>
2940 <td>name</td>
2941 <td>String</td>
2942 <td>the originally declared simple name of this class (not including any
2943 package prefix). If this class is anonymous, then the name is
2944 <code>null</code>.
2945 </td>
2946</tr>
2947<tr>
2948 <td>accessFlags</td>
2949 <td>int</td>
2950 <td>the originally declared access flags of the class (which may differ
2951 from the effective flags because of a mismatch between the execution
2952 models of the source language and target virtual machine)
2953 </td>
2954</tr>
2955</tbody>
2956</table>
2957
Clay Murphy945af1a2013-07-01 17:31:13 -07002958<h3>dalvik.annotation.MemberClasses</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002959<h4>appears on classes</h4>
2960
2961<p>A <code>MemberClasses</code> annotation is attached to each class
2962which declares member classes. (A member class is a direct inner class
2963that has a name.)</p>
2964
2965<table class="format">
2966<thead>
2967<tr>
2968 <th>Name</th>
2969 <th>Format</th>
2970 <th>Description</th>
2971</tr>
2972</thead>
2973<tbody>
2974<tr>
2975 <td>value</td>
2976 <td>Class[]</td>
2977 <td>array of the member classes</td>
2978</tr>
2979</tbody>
2980</table>
2981
Clay Murphy945af1a2013-07-01 17:31:13 -07002982<h3>dalvik.annotation.Signature</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07002983<h4>appears on classes, fields, and methods</h4>
2984
2985<p>A <code>Signature</code> annotation is attached to each class,
2986field, or method which is defined in terms of a more complicated type
2987than is representable by a <code>type_id_item</code>. The
2988<code>.dex</code> format does not define the format for signatures; it
2989is merely meant to be able to represent whatever signatures a source
2990language requires for successful implementation of that language's
2991semantics. As such, signatures are not generally parsed (or verified)
2992by virtual machine implementations. The signatures simply get handed
2993off to higher-level APIs and tools (such as debuggers). Any use of a
2994signature, therefore, should be written so as not to make any
2995assumptions about only receiving valid signatures, explicitly guarding
2996itself against the possibility of coming across a syntactically
2997invalid signature.</p>
2998
2999<p>Because signature strings tend to have a lot of duplicated content,
3000a <code>Signature</code> annotation is defined as an <i>array</i> of
3001strings, where duplicated elements naturally refer to the same
3002underlying data, and the signature is taken to be the concatenation of
3003all the strings in the array. There are no rules about how to pull
3004apart a signature into separate strings; that is entirely up to the
3005tools that generate <code>.dex</code> files.</p>
3006
3007<table class="format">
3008<thead>
3009<tr>
3010 <th>Name</th>
3011 <th>Format</th>
3012 <th>Description</th>
3013</tr>
3014</thead>
3015<tbody>
3016<tr>
3017 <td>value</td>
3018 <td>String[]</td>
3019 <td>the signature of this class or member, as an array of strings that
3020 is to be concatenated together</td>
3021</tr>
3022</tbody>
3023</table>
3024
Clay Murphy945af1a2013-07-01 17:31:13 -07003025<h3>dalvik.annotation.Throws</h3>
Dan Bornstein25705bc2011-04-12 16:23:13 -07003026<h4>appears on methods</h4>
3027
3028<p>A <code>Throws</code> annotation is attached to each method which is
3029declared to throw one or more exception types.</p>
3030
3031<table class="format">
3032<thead>
3033<tr>
3034 <th>Name</th>
3035 <th>Format</th>
3036 <th>Description</th>
3037</tr>
3038</thead>
3039<tbody>
3040<tr>
3041 <td>value</td>
3042 <td>Class[]</td>
3043 <td>the array of exception types thrown</td>
3044</tr>
3045</tbody>
3046</table>