The ID tables follow the header. Every class in the file shares them, and instructions and other items refer to their entries by index. All offsets are from the start of the file. Source: the Dalvik executable format.
Strings
string_id_item (4 bytes, aligned to 4)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 4 | uint string_data_off | Offset of the string’s string_data_item in the data section. |
string_data_item (no alignment)
| Type and name | Meaning |
|---|---|
uleb128 utf16_size | Length of the string in UTF-16 code units (not bytes). |
ubyte[] data | The string in MUTF-8, followed by a zero byte. |
MUTF-8
Strings use Modified UTF-8, the encoding of Java class files:
- Only the one-, two- and three-byte UTF-8 forms are used.
- Characters above U+FFFF are written as a UTF-16 surrogate pair, each surrogate encoded as three bytes.
- U+0000 is written as the two bytes
C0 80, so a zero byte only ever ends a string. - Because of the surrogates, comparing the bytes with
strcmp()does not always order strings correctly; compare the decoded UTF-16 units instead.
Names and descriptors
| Syntax | Form |
|---|---|
| SimpleName | One or more of: A–Z, a–z, 0–9, $, -, _, U+00A1–U+1FFF, U+2010–U+2027, U+2030–U+D7FF, U+E000–U+FFEF and U+10000–U+10FFFF. From version 040 also the space U+0020, U+00A0, U+2000–U+200A and U+202F. |
| MemberName | A SimpleName, or < SimpleName > for <init> and <clinit>. |
| FullClassName | Optional package parts, each a SimpleName and /, then a SimpleName: java/lang/String. |
| TypeDescriptor | V (void, return types only), a primitive letter, L FullClassName ;, or one to 255 [ before a non-void descriptor for an array. |
| ShortyDescriptor | A short form of a prototype: the return type letter, then one letter per parameter, with every reference type (class or array) as L. |
| Letter | Type |
|---|---|
V | void |
Z | boolean |
B | byte |
S | short |
C | char |
I | int |
J | long |
F | float |
D | double |
L…; | A class, such as Ljava/lang/String; |
[ | An array of the type that follows, such as [I for int[] |
Types and prototypes
type_id_item (4 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 4 | uint descriptor_idx | Index into string_ids of the type’s TypeDescriptor. |
proto_id_item (12 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 4 | uint shorty_idx | Index into string_ids of the ShortyDescriptor. |
4 | 4 | uint return_type_idx | Index into type_ids of the return type. |
8 | 4 | uint parameters_off | Offset of a type_list of the parameter types, or 0 if there are none. The list never contains void. |
type_list (aligned to 4)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 4 | uint size | Number of entries. |
4 | 2 × size | type_item list[] | Each a ushort type_idx, an index into type_ids. |
Fields and methods
field_id_item (8 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 2 | ushort class_idx | Index into type_ids of the class that defines the field (must be a class type). |
2 | 2 | ushort type_idx | Index into type_ids of the field’s type. |
4 | 4 | uint name_idx | Index into string_ids of the field’s MemberName. |
method_id_item (8 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 2 | ushort class_idx | Index into type_ids of the defining class or array type. |
2 | 2 | ushort proto_idx | Index into proto_ids of the method’s prototype. |
4 | 4 | uint name_idx | Index into string_ids of the method’s MemberName. |
Class definitions
class_def_item (32 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0x00 | 4 | uint class_idx | Index into type_ids of this class (a class type, not an array or primitive). |
0x04 | 4 | uint access_flags | Access flags. |
0x08 | 4 | uint superclass_idx | Index into type_ids of the superclass, or NO_INDEX for a root class such as Object. |
0x0C | 4 | uint interfaces_off | Offset of a type_list of the interfaces it implements, or 0. No duplicates. |
0x10 | 4 | uint source_file_idx | Index into string_ids of the source file name, or NO_INDEX. |
0x14 | 4 | uint annotations_off | Offset of an annotations_directory_item, or 0. |
0x18 | 4 | uint class_data_off | Offset of the class_data_item, or 0 if the class has no fields or methods (for example a marker interface). |
0x1C | 4 | uint static_values_off | Offset of an encoded_array_item with the initial values of the static fields, in field order, or 0. Missing trailing values mean 0 or null. |
Access flags
Used in class_def_item, encoded_field,
encoded_method and the InnerClass annotation.
| Value | Name | Classes | Fields | Methods |
|---|---|---|---|---|
0x00001 | ACC_PUBLIC | public | public | public |
0x00002 | ACC_PRIVATE | private (inner classes only) | private | private |
0x00004 | ACC_PROTECTED | protected (inner classes only) | protected | protected |
0x00008 | ACC_STATIC | static: no outer this (inner classes only) | static | static: no this argument |
0x00010 | ACC_FINAL | cannot be subclassed | immutable after construction | cannot be overridden |
0x00020 | ACC_SYNCHRONIZED | — | — | a lock is taken around the call (only allowed with ACC_NATIVE) |
0x00040 | ACC_VOLATILE / ACC_BRIDGE | — | volatile | bridge method made by the compiler |
0x00080 | ACC_TRANSIENT / ACC_VARARGS | — | not saved by default serialisation | last argument is a varargs array |
0x00100 | ACC_NATIVE | — | — | implemented in native code |
0x00200 | ACC_INTERFACE | interface | — | — |
0x00400 | ACC_ABSTRACT | cannot be instantiated | — | not implemented by this class |
0x00800 | ACC_STRICT | — | — | strict floating-point rules (strictfp) |
0x01000 | ACC_SYNTHETIC | not in source | not in source | not in source |
0x02000 | ACC_ANNOTATION | annotation type | — | — |
0x04000 | ACC_ENUM | enum type | enum constant | — |
0x08000 | (unused) | — | — | — |
0x10000 | ACC_CONSTRUCTOR | — | — | constructor or class initialiser |
0x20000 | ACC_DECLARED_SYNCHRONIZED | — | — | declared synchronized; for reflection only, no effect on execution |
ACC_PRIVATE, ACC_PROTECTED and ACC_STATIC on a
class are allowed only in an InnerClass annotation, never in a
class_def_item.
Call sites and method handles
Added in version 038 for invoke-custom and
invoke-polymorphic.
call_site_id_item (4 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 4 | uint call_site_off | Offset of the call site’s call_site_item. |
call_site_item
An encoded_array_item (no alignment). Its first three values are the
bootstrap linker method (a VALUE_METHOD_HANDLE), the method name to
resolve (a VALUE_STRING) and the method type (a
VALUE_METHOD_TYPE). Any further values are passed to the bootstrap
method as extra arguments.
method_handle_item (8 bytes)
| Offset | Size | Type and name | Meaning |
|---|---|---|---|
0 | 2 | ushort method_handle_type | Kind of handle, from the table below. |
2 | 2 | ushort unused | — |
4 | 2 | ushort field_or_method_id | Index into field_ids for accessor handles, otherwise into method_ids. |
6 | 2 | ushort unused | — |
| Value | Name | Handle to |
|---|---|---|
0x00 | METHOD_HANDLE_TYPE_STATIC_PUT | static field setter |
0x01 | METHOD_HANDLE_TYPE_STATIC_GET | static field getter |
0x02 | METHOD_HANDLE_TYPE_INSTANCE_PUT | instance field setter |
0x03 | METHOD_HANDLE_TYPE_INSTANCE_GET | instance field getter |
0x04 | METHOD_HANDLE_TYPE_INVOKE_STATIC | static method |
0x05 | METHOD_HANDLE_TYPE_INVOKE_INSTANCE | instance method |
0x06 | METHOD_HANDLE_TYPE_INVOKE_CONSTRUCTOR | constructor |
0x07 | METHOD_HANDLE_TYPE_INVOKE_DIRECT | direct (non-virtual) method |
0x08 | METHOD_HANDLE_TYPE_INVOKE_INTERFACE | interface method |
Sources
The Android Open Source Project’s Dalvik executable format: “MUTF-8 (Modified UTF-8) encoding”, “String syntax” (SimpleName, MemberName, FullClassName, TypeDescriptor, ShortyDescriptor), “access_flags definitions”, “string_id_item”, “string_data_item”, “type_id_item”, “proto_id_item”, “field_id_item”, “method_id_item”, “class_def_item”, “call_site_id_item”, “call_site_item”, “method_handle_item”, “Method handle type codes” and “type_list”.