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