Google is committed to advancing racial equity for Black communities. See how.
本頁面由 Cloud Translation API 翻譯而成。
Switch to English

Dalvik可執行格式

本文檔介紹了.dex文件的佈局和內容,這些文件用於保存一組類定義及其關聯的輔助數據。

類型指南

名稱描述
字節 8位有符號整數
字節 8位無符號整數
16位帶符號整數,小端
超短 16位無符號整數,小端
整型 32位帶符號整數,小端
int 32位無符號整數,小端
64位帶符號整數,小端
烏龍 64位無符號整數,小端
sleb128 帶符號的LEB128,長度可變(請參見下文)
uleb128 無符號LEB128,可變長度(請參見下文)
uleb128p1 無符號LEB128加1 ,長度可變(請參見下文)

LEB128

LEB128(“L ittle-êndian ASE 128”)可以任意的符號或無符號的整數數量的可變長度編碼。該格式是從DWARF3規範中藉用的。在.dex文件中,LEB128僅用於編碼32位量。

每個LEB128編碼值由1-5個字節組成,它們一起代表一個32位值。除序列中的最後一個字節(其最高有效位清零)外,每個字節均具有其最高有效位集。每個字節的其餘七個位是有效載荷,數量的最低有效七位在第一個字節,第二個在後七個字節,依此類推。在帶符號的LEB128( sleb128 )的情況下,序列中最後一個字節的最高有效載荷位將被符號擴展以產生最終值。在無符號的情況下( uleb128 ),任何未明確表示的位都將解釋為0

兩字節LEB128值的按位圖
第一個字節第二字節
1 6 5 4 3 21 0 0 13 1211 10 9 8 7

變體uleb128p1用於表示帶符號的值,其中表示形式是有符號值加上一個編碼為uleb128的值。這樣就可以將-1 (也可以看作是無符號值0xffffffff )(但沒有其他負數)編碼為單個字節,並且在表示數字必須為非負數或-1 (或0xffffffff ),並且不允許其他負值(或者不太可能需要大的無符號值)。

以下是格式的一些示例:

編碼序列作為sleb128 As uleb128 uleb128p1
00 0 0 -1
01 1個 1個 0
7樓 -1 127 126
80 7樓 -128 16256 16255

文件佈局

名稱格式描述
標頭 header_item 標頭
string_ids string_id_item [] 字符串標識符列表。這些是此文件使用的所有字符串的標識符,用於內部命名(例如,類型描述符)或作為代碼引用的常量對象。該列表必須使用UTF-16代碼點值(不以對語言環境敏感的方式)按字符串內容排序(並且不包含任何重複的條目)。
type_ids type_id_item [] 類型標識符列表。這些是此文件引用的所有類型(類,數組或原始類型)的標識符,無論是否在文件中定義。該列表必須按string_id索引排序,並且不得包含任何重複的條目。
proto_ids proto_id_item [] 方法原型標識符列表。這些是此文件引用的所有原型的標識符。此列表必須按返回類型(按type_id索引)的主要順序排序,然後按參數列表(按type_id順序排序,各個參數按type_id索引排序)排序。該列表不得包含任何重複的條目。
field_ids field_id_item [] 字段標識符列表。這些是此文件引用的所有字段的標識符,無論是否在文件中定義。此列表必須排序,其中定義類型(按type_id索引)是主要順序,字段名(按string_id索引)是中間順序,類型(按type_id索引)是次要順序。該列表不得包含任何重複的條目。
method_ids method_id_item [] 方法標識符列表。這些是此文件引用的所有方法的標識符,無論是否在文件中定義。該列表必須進行排序,其中定義類型(按type_id索引)是主要順序,方法名稱(按string_id索引)是中間順序,方法原型(按proto_id索引)是次要順序。該列表不得包含任何重複的條目。
class_defs class_def_item [] 類定義列表。必須對類進行排序,以使給定類的超類和已實現的接口早於引用類出現在列表中。此外,對於同名類的定義在列表中多次出現是無效的。
call_site_ids call_site_id_item [] 呼叫站點標識符列表。這些是此文件引用的所有呼叫站點的標識符,無論是否在文件中定義。此列表必須按call_site_off升序排序。
method_handles method_handle_item [] 方法處理列表。此文件引用的所有方法句柄的列表,無論是否在文件中定義。該列表未排序,並且可能包含重複項,這些重複項在邏輯上將對應於不同的方法句柄實例。
數據 ubyte [] 數據區域,其中包含上面列出的表的所有支持數據。不同的項目具有不同的對齊要求,如果有必要,請在每個項目之前插入填充字節,以實現正確的對齊。
link_data ubyte [] 靜態鏈接文件中使用的數據。本節中未指定本節中數據的格式。在未鏈接的文件中,此部分為空,運行時實現可能會視需要使用它。

位域,字符串和常量定義

DEX_FILE_MAGIC

嵌入在header_item中

常量數組/字符串DEX_FILE_MAGIC.dex文件開頭必須出現的字節列表,以便可以這樣識別。該值有意包含換行符( "\n"0x0a )和空字節( "\0"0x00 ),以幫助檢測某些形式的損壞。該值還將格式版本號編碼為三個十進制數字,隨著格式的發展,該版本號預計會隨時間單調增加。

ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x39 0x00 }
                        = "dex\n039\0"

注意: Android 9.0版本中增加了對該格式版本039的支持,該版本引入了兩個新的字節碼const-method-handleconst-method-type 。 (這些內容分別在“ 字節碼設置摘要”表中進行了描述。)在Android 10中,版本039擴展了DEX文件格式,以包含僅適用於引導類路徑上的DEX文件的隱藏API信息。

注意: Android 8.0版本中添加了對格式038版本的支持。 038版添加了新的字節碼( invoke-polymorphicinvoke-custom )以及方法句柄的數據。

注意: Android 7.0版本中添加了對格式037版本的支持。在版本037之前,大多數版本的Android都使用該格式的版本035 。版本035037之間的唯一區別是添加了默認方法和對invoke的調整。

注意:該格式至少有兩個較早的版本已在廣泛可用的公共軟件版本中使用。例如, 009版本用於Android平台的M3版本(2007年11月至2007年12月),而013版本用於Android平台的M5版本(2008年2月至2008年3月)。在某些方面,這些格式的早期版本與本文檔中描述的版本有很大不同。

ENDIAN_CONSTANT和REVERSE_ENDIAN_CONSTANT

嵌入在header_item中

常量ENDIAN_CONSTANT用於指示在其中找到文件的文件的字節序。儘管標準.dex格式為.dex字節序,但實現方式可以選擇執行字節交換。如果實現遇到一個endian_tagREVERSE_ENDIAN_CONSTANT而不是ENDIAN_CONSTANT的標頭,則它將知道該文件已從預期格式進行字節交換。

uint ENDIAN_CONSTANT = 0x12345678;
uint REVERSE_ENDIAN_CONSTANT = 0x78563412;

NO_INDEX

嵌入在class_def_item和debug_info_item中

常量NO_INDEX用於指示缺少索引值。

注意:此值未定義為0 ,因為實際上通常是有效索引。

NO_INDEX的所選值可以表示為uleb128p1編碼中的單個字節。

uint NO_INDEX = 0xffffffff;    // == -1 if treated as a signed int

access_flags定義

嵌入在class_def_item,encoded_field,encoded_method和InnerClass中

這些標誌的位域用於指示類和類成員的可訪問性和整體屬性。

名稱對於類(和InnerClass註釋) 對於領域方法
ACC_PUBLIC 0x1 public :隨處可見 public :隨處可見 public :隨處可見
ACC_PRIVATE 0x2 * private :僅對定義類可見 private :僅對定義類可見 private :僅對定義類可見
ACC_PROTECTED 0x4 * protected :對包和子類可見 protected :對包和子類可見 protected :對包和子類可見
ACC_STATIC 0x8 * static :不是使用外部this引用構造的 static :全局到定義類 static :不接受this參數
ACC_FINAL 0x10 final :不可歸類的 final :構造後不變的 final :不可替代
ACC_SYNCHRONIZED 0x20 synchronized :圍繞此方法的調用自動獲取關聯的鎖。

注意:僅當還設置了ACC_NATIVE時,此設置才有效。

ACC_VOLATILE 0x40 volatile :特殊的訪問規則可幫助確保線程安全
ACC_BRIDGE 0x40 橋方法,由編譯器自動添加為類型安全橋
ACC_TRANSIENT 0x80 transient :默認情況下不保存
ACC_VARARGS 0x80 編譯器應將最後一個參數視為“剩餘”參數
ACC_NATIVE 0x100 native :以本機代碼實現
ACC_INTERFACE 0x200 interface :可多重實現的抽像類
ACC_ABSTRACT 0x400 abstract :不可直接實例化 abstract :此類未實現
ACC_STRICT 0x800 strictfp :浮點運算的嚴格規則
ACC_SYNTHETIC 0x1000 沒有在源代碼中直接定義沒有在源代碼中直接定義沒有在源代碼中直接定義
ACC_ANNOTATION 0x2000 聲明為註釋類
ACC_ENUM 0x4000 聲明為枚舉類型聲明為枚舉值
(沒用過) 0x8000
ACC_CONSTRUCTOR 0x10000 構造方法(類或實例初始化器)
ACC_DECLARED_
已同步
0x20000 宣布已synchronized

注意:這對執行沒有任何影響(除了反映該標誌本身以外)。

* 僅允許InnerClass註釋InnerClass ,並且永遠不能在class_def_item

MUTF-8(修改的UTF-8)編碼

為了.dex傳統支持, .dex格式以事實上的標準修改UTF-8格式(以下稱為MUTF-8)對字符串數據進行編碼。該格式與標準UTF-8相同,除了:

  • 僅使用一,二和三字節編碼。
  • U+10000U+10ffff範圍內的代碼點被編碼為代理對,每個代理對均表示為三字節編碼值。
  • 碼點U+0000以兩字節形式編碼。
  • 普通的空字節(值0 )表示字符串的結尾,標準C語言解釋也是如此。

上面的前兩項可以總結為:MUTF-8是UTF-16的編碼格式,而不是Unicode字符的更直接的編碼格式。

上面的最後兩項使同時可以在字符串中包含代碼點U+0000並且仍然可以將其作為C樣式的以空字符結尾的字符串進行操作。

但是, U+0000的特殊編碼意味著,與普通的UTF-8不同,在一對MUTF-8字符串上調用標準C函數strcmp()結果並不總是表示對不相等字符串進行比較的正確簽名結果。當考慮排序(不只是相等性)時,比較MUTF-8字符串的最直接方法是逐字符解碼它們,並比較解碼後的值。 (但是,更聰明的實現也是可能的。)

有關字符編碼的更多信息,請參考Unicode標準 。實際上,MUTF-8本身比相對於UTF-8更接近(相對不太為人所知)的編碼CESU-8

encode_value編碼

嵌入在註解元素和編碼數組項中

encoded_value是(幾乎)任意的層次結構化數據的編碼片段。編碼既緊湊又易於解析。

名稱格式描述
(value_arg << 5)|值類型字節指示緊隨其後的value的類型的字節,以及高階三位中的可選澄清參數。有關各種value定義,請參見下文。在大多數情況下, value_arg將緊隨其後的value的長度以字節為單位進行編碼,如(size - 1) ,例如0表示該值需要一個字節,而7表示它需要八個字節;但是,也有如下例外。
ubyte [] 代表值的字節,長度可變,並且對不同的value_type字節的解釋不同,儘管始終為little-endian。有關詳細信息,請參見下面的各種值定義。

值格式

類型名稱 value_type value_arg格式 value格式描述
VALUE_BYTE 0x00 (無;必須為0 ubyte [1] 有符號的一字節整數值
VALUE_SHORT 0x02 大小-1(0…1) ubyte [大小] 帶符號的兩字節整數值,帶符號擴展
VALUE_CHAR 0x03 大小-1(0…1) ubyte [大小] 無符號兩字節整數值,零擴展
VALUE_INT 0x04 大小-1(0…3) ubyte [大小] 帶符號的四字節整數值,帶符號擴展
VALUE_LONG 0x06 大小-1(0…7) ubyte [大小] 帶符號的八字節整數值,帶符號擴展
VALUE_FLOAT 0x10 大小-1(0…3) ubyte [大小] 四字節位模式, 向右零擴展,並解釋為IEEE754 32位浮點值
VALUE_DOUBLE 0x11 大小-1(0…7) ubyte [大小] 八字節位模式, 向右零擴展,並解釋為IEEE754 64位浮點值
VALUE_METHOD_TYPE 0x15 大小-1(0…3) ubyte [大小] 無符號(零擴展)四字節整數值,被解釋為proto_ids部分的索引並表示方法類型值
VALUE_METHOD_HANDLE 0x16 大小-1(0…3) ubyte [大小] 無符號(零擴展)的四字節整數值,被解釋為method_handles節中的索引並表示方法句柄值
VALUE_STRING 0x17 大小-1(0…3) ubyte [大小] 無符號(零擴展)的四字節整數值,解釋為string_ids部分的索引並表示字符串值
值類型 0x18 大小-1(0…3) ubyte [大小] 無符號(零擴展)四字節整數值,被解釋為type_ids部分的索引,並表示反射類型/類值
VALUE_FIELD 0x19 大小-1(0…3) ubyte [大小] 無符號(零擴展)四字節整數值,被解釋為field_ids部分的索引並表示反射字段值
VALUE_METHOD 0x1a 大小-1(0…3) ubyte [大小] 無符號(零擴展)的四字節整數值,被解釋為method_ids部分的索引並表示反射方法值
VALUE_ENUM 0x1b 大小-1(0…3) ubyte [大小] 無符號(零擴展)四字節整數值,被解釋為field_ids部分的索引,並表示枚舉類型常量的值
VALUE_ARRAY 0x1c (無;必須為0 encode_array 值的數組,格式由下面的“ encoded_array格式”指定。該value的大小在編碼中是隱式的。
VALUE_ANNOTATION 0x1d (無;必須為0 encode_annotation 子註釋,格式由下面的“ encoded_annotation格式”指定。該value的大小在編碼中是隱式的。
VALUE_NULL 0x1e (無;必須為0 (沒有) null參考值
VALUE_BOOLEAN 0x1f 布爾值(0…1) (沒有) 一位值; 0代表false1代表true 。該位在value_arg表示。

encode_array格式

名稱格式描述
尺寸 uleb128 數組中元素的數量
價值觀 encode_value [大小] 一系列size encoded_value在此部分中指定的格式字節序列,依次級聯。

encode_annotation格式

名稱格式描述
type_idx uleb128 註釋的類型。這必須是一個類(不是數組或原始類型)類型。
尺寸 uleb128 此批註中名稱/值映射的數量
元素註解元素[大小] 註釋的元素,直接以行形式表示(而不是偏移量)。元素必須按string_id索引以升序排序。

註解元素格式

名稱格式描述
name_idx uleb128 元素名稱,表示為string_ids部分的索引。該字符串必須符合上面定義的MemberName的語法。
編碼值元素值

字符串語法

.dex文件中有幾種項目,這些項目最終引用一個字符串。以下BNF樣式定義指示這些字符串可接受的語法。

簡單名稱

SimpleName是其他事物名稱語法的基礎。 .dex格式在這裡可以有很大的自由度(比大多數常見的源語言要多得多)。簡而言之,簡單名稱由任何低ASCII字母字符或數字,一些特定的低ASCII符號和大多數非控制,空格或特殊字符的非ASCII代碼點組成。從040版開始,該格式還允許使用空格字符(Unicode Zs類別)。需要注意的是代理代碼點(範圍U+d800 ... U+dfff )不被認為是有效的名稱字符本身,而是統一補充字符有效的(這是由SimpleNameChar規則的最終替代為代表),他們應該在文件中表示為MUTF-8編碼中的代理代碼點對。

SimpleName
SimpleNameCharSimpleNameChar )*
SimpleNameChar
'A''Z'
| 'a''z'
| '0''9'
| ' ' 自DEX 040版本起
| '$'
| '-'
| '_'
| U+00a0 自DEX 040版本起
| U+00a1U+1fff
| U+2000U+200a 自DEX 040版本起
| U+2010U+2027
| U+202f 自DEX 040版本起
| U+2030U+d7ff
| U+e000U+ffef
| U+10000U+10ffff

成員名字

由field_id_item和method_id_item使用

MemberName是類成員的名稱,成員是字段,方法和內部類。

會員名
簡單名稱
| '<' SimpleName '>'

FullClassName

FullClassName是一個完全合格的類名,包括一個可選的包說明符,後跟一個必需的名稱。

FullClassName
OptionalPackagePrefix SimpleName
可選包前綴
SimpleName '/' )*

類型描述符

由type_id_item使用

TypeDescriptor是任何類型的表示形式,包括基元,類,數組和void 。有關各種版本的含義,請參見下文。

類型描述符
'V'
| FieldTypeDescriptor
FieldTypeDescriptor
NonArrayFieldTypeDescriptor
| '[' * 1…255) NonArrayFieldTypeDescriptor
NonArrayFieldTypeDescriptor
'Z'
| 'B'
| 'S'
| 'C'
| 'I'
| 'J'
| 'F'
| 'D'
| 'L' FullClassName ';'

矮子描述符

由proto_id_item使用

ShortyDescriptor是方法原型的簡短形式表示形式,包括返回類型和參數類型,只是各種引用(類或數組)類型之間沒有區別。相反,所有引用類型都由單個'L'字符表示。

ShortyDescriptor
ShortyReturnTypeShortyFieldType )*
ShortyReturnType
'V'
| ShortyFieldType
ShortyFieldType
'Z'
| 'B'
| 'S'
| 'C'
| 'I'
| 'J'
| 'F'
| 'D'
| 'L'

類型描述符語義

這就是TypeDescriptor的每個變體的含義。

句法含義
V void ;僅對返回類型有效
ž boolean
byte
小號 short
C char
一世 int
Ĵ long
F float
d double
L 完整/合格/名稱 ; 該類fully.qualified.Name
[ 描述符 descriptor數組,可遞歸地用於數組數組,儘管具有超過255個維度是無效的。

項目和相關結構

本節包括.dex文件中可能出現的每個頂級項目的定義。

header_item

出現在標題部分

對齊方式:4個字節

名稱格式描述
魔法 ubyte [8] = DEX_FILE_MAGIC 神奇的價值。有關更多詳細信息,請參見上面“ DEX_FILE_MAGIC ”下的討論。
校驗和 int adler32文件其餘部分的校驗和(除magic和此字段外的所有內容);用於檢測文件損壞
簽名優字節[20] 文件其餘部分(除magicchecksum和此字段之外的所有內容)的SHA-1簽名(哈希);用於唯一標識文件
文件大小 int 整個文件(包括標題)的大小,以字節為單位
header_size uint = 0x70 標頭的大小(整個部分),以字節為單位。這允許至少有限的向後/向前兼容性,而不會使格式無效。
endian_tag uint = ENDIAN_CONSTANT 字節序標籤。有關更多詳細信息,請參見上面“ ENDIAN_CONSTANTREVERSE_ENDIAN_CONSTANT ”下的討論。
link_size int 鏈接部分的大小,如果此文件不是靜態鏈接,則為0
link_off int 從該文件的開始偏移到鏈接部分,或0如果link_size == 0 。偏移量(如果非零)應為link_data節的偏移量。本文檔未指定所指向的數據格式;此標頭字段(和前一個字段)保留為掛鉤,供運行時實現使用。
map_off int 從文件開頭到地圖項的偏移量。該偏移量必須為非零,應為data節中的偏移量,並且數據應採用下面的“ map_list ”指定的格式。
string_ids_size int 字符串標識符列表中的字符串計數
string_ids_off int 從該文件的開始偏移為字符串的標識符列表,或者0string_ids_size == 0 (誠然奇怪邊緣情況)。偏移量(如果非零)應為string_ids部分的string_ids
type_ids_size int 類型標識符列表中的元素數量,最多65535
type_ids_off int 從文件的類型的標識符列表中的開始,或偏移0如果type_ids_size == 0 (誠然奇怪邊緣情況)。偏移量(如果非零)應為type_ids部分的type_ids
proto_ids_size int 原型標識符列表中的元素數量,最多65535
proto_ids_off int 從該文件的開始偏移原型標識符列表,或者0proto_ids_size == 0 (誠然奇怪邊緣情況)。偏移量(如果非零)應為proto_ids部分的proto_ids
field_ids_size int 字段標識符列表中的元素計數
field_ids_off int 從文件開始到外地標識目錄偏移,或0 ,如果field_ids_size == 0 。偏移量(如果非零)應為field_ids部分的field_ids
method_ids_size int 方法標識符列表中的元素計數
method_ids_off int 從文件的起始位置的偏移的方法的標識符列表,或者0method_ids_size == 0 。偏移量(如果非零)應為method_ids部分的method_ids
class_defs_size int 類定義列表中的元素數
class_defs_off int 從文件的起始位置的偏移到的類定義列表,或者0class_defs_size == 0 (誠然奇怪邊緣情況)。偏移量(如果非零)應為class_defs節的class_defs
數據大小 int data段的大小(以字節為單位)。必須是sizeof(uint)的偶數倍。
data_off int 從文件開頭到data節開頭的偏移量。

map_list

出現在數據部分

從header_item引用

對齊方式:4個字節

這是按順序列出文件全部內容的列表。它包含與header_item一些冗餘,但旨在成為一種易於使用的形式來迭代整個文件。給定類型必須在地圖中最多出現一次,但是除了其餘格式所隱含的限制(例如, header部分必須首先出現,然後是string_ids ,對可能以哪種順序類型出現沒有限制。部分等)。此外,映射條目必須按初始偏移量排序,並且不能重疊。

名稱格式描述
尺寸 int 列表的大小,以條目為單位
清單 map_item [大小] 列表中的元素

map_item格式

名稱格式描述
類型超短項目類型;見下表
沒用過超短 (沒用過)
尺寸 int 在指定的偏移量處找到的項目數的計數
抵消 int 從文件開頭到相關項目的偏移量

類型代碼

物品種類不變項目大小(以字節為單位)
header_item TYPE_HEADER_ITEM 0x0000 0x70
string_id_item TYPE_STRING_ID_ITEM 0x0001 0x04
type_id_item TYPE_TYPE_ID_ITEM 0x0002 0x04
proto_id_item TYPE_PROTO_ID_ITEM 0x0003 0x0c
field_id_item TYPE_FIELD_ID_ITEM 0x0004 0x08
method_id_item TYPE_METHOD_ID_ITEM 0x0005 0x08
class_def_item TYPE_CLASS_DEF_ITEM 0x0006 0x20
call_site_id_item TYPE_CALL_SITE_ID_ITEM 0x0007 0x04
method_handle_item TYPE_METHOD_HANDLE_ITEM 0x0008 0x08
map_list TYPE_MAP_LIST 0x1000 4 +(項目大小* 12)
type_list TYPE_TYPE_LIST 0x1001 4 +(項目大小* 2)
註解_設置_引用列表 TYPE_ANNOTATION_SET_REF_LIST 0x1002 4 +(項目大小* 4)
註解集項目 TYPE_ANNOTATION_SET_ITEM 0x1003 4 +(項目大小* 4)
class_data_item TYPE_CLASS_DATA_ITEM 0x2000 隱含的必須解析
code_item TYPE_CODE_ITEM 0x2001 隱含的必須解析
string_data_item TYPE_STRING_DATA_ITEM 0x2002 隱含的必須解析
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 隱含的必須解析
註解_項目 TYPE_ANNOTATION_ITEM 0x2004 隱含的必須解析
encode_array_item TYPE_ENCODED_ARRAY_ITEM 0x2005 隱含的必須解析
註解_目錄_項目 TYPE_ANNOTATIONS_DIRECTORY_ITEM 0x2006 隱含的必須解析
hiddenapi_class_data_item TYPE_HIDDENAPI_CLASS_DATA_ITEM 0xF000 隱含的必須解析

string_id_item

出現在string_ids部分

對齊方式:4個字節

名稱格式描述
string_data_off int 從文件開頭到此項目的字符串數據的偏移量。偏移量應位於data部分中的某個位置,並且數據應採用下面的“ string_data_item ”指定的格式。偏移沒有對齊要求。

string_data_item

出現在數據部分

對齊方式:無(字節對齊)

名稱格式描述
utf16_size uleb128 此字符串的大小,以UTF-16代碼單位(在許多系統中為“字符串長度”)。也就是說,這是字符串的解碼長度。 (編碼的長度由0字節的位置暗示。)
數據 ubyte [] 一系列MUTF-8代碼單元(又稱八位字節,又稱字節),後跟一個值為0的字節。有關數據格式的詳細信息和討論,請參見上面的“ MUTF-8(修改後的UTF-8)編碼”。

注意:可以接受一個字符串,該字符串包含(相對於通常編碼而言)UTF-16代理代碼單元(即U+d800U+dfff )為隔離形式或無序形式將Unicode轉換為UTF-16。如果合適,取決於字符串的更高級別的使用來拒絕這種無效的編碼。

type_id_item

出現在type_ids部分中

對齊方式:4個字節

名稱格式描述
descriptor_idx int 索引到此類型的描述符字符串的string_ids列表中。該字符串必須符合上面定義的TypeDescriptor的語法。

proto_id_item

出現在proto_ids部分

對齊方式:4個字節

名稱格式描述
shorty_idx int 索引到此原型的簡短描述符字符串的string_ids列表中。該字符串必須符合上面定義的ShortyDescriptor的語法,並且必須與此項目的返回類型和參數相對應。
return_type_idx int 此原型的返回類型的type_ids列表索引
parameters_off int 從文件的開頭到此原型的參數類型列表的偏移量;如果此原型沒有參數,則為0 。此偏移量(如果非零)應位於data部分,並且其中的數據應採用下面的"type_list"指定的格式。此外,列表中不應引用void類型。

field_id_item

出現在field_ids部分

對齊方式:4個字節

名稱格式描述
class_idx 超短索引到此字段定義者的type_ids列表中。這必須是類類型,而不是數組或原始類型。
type_idx 超短索引到此字段類型的type_ids列表中
name_idx int 索引到該字段名稱的string_ids列表中。該字符串必須符合上面定義的MemberName的語法。

method_id_item

出現在method_ids部分中

對齊方式:4個字節

名稱格式描述
class_idx 超短索引到此方法的定義者的type_ids列表中。這必須是類或數組類型,而不是原始類型。
proto_idx 超短索引到此方法的原型的proto_ids列表中
name_idx int 索引到該方法名稱的string_ids列表中。該字符串必須符合上面定義的MemberName的語法。

class_def_item

出現在class_defs部分中

對齊方式:4個字節

名稱格式描述
class_idx int 索引到type_ids列表中。這必須是類類型,而不是數組或原始類型。
access_flags int 類的訪問標誌( publicfinal等)。有關詳細信息,請參見“ access_flags定義”。
超類IDX int 索引到超類的type_ids列表中;如果該類沒有超類(即它是一個根類,例如Object ), NO_INDEX常數NO_INDEX 。如果存在,則必須為類類型,而不是數組或原始類型。
interfaces_off int 從文件開始的偏移量,以列表界面,或0 ,如果有沒有。此偏移應在data部分中,並且那裡的數據應採用下面“ type_list ”指定的格式。列表中的每個元素都必須是類類型(而不是數組或原始類型),並且不得有任何重複項。
source_file_idx int 索引到string_ids列表中,以獲取包含該類(至少大部分)的原始源的文件名,或特殊值NO_INDEX來表示缺少此信息。任何給定方法的debug_info_item都可以覆蓋此源文件,但是可以預期的是,大多數類將僅來自一個源文件。
註解 int 從文件開頭到此類的註釋結構的偏移量;如果此類沒有註釋,則為0 。此偏移量(如果非零)應位於data部分中,並且該數據的格式應為下面的“ annotations_directory_item ”指定的格式,所有引用此類的項目均作為定義程序。
class_data_off int 從文件開頭到此項的關聯類數據的偏移量;如果沒有此類的類數據,則為0 。 (例如,如果此類是標記接口,則可能是這種情況。)偏移量(如果非零)應位於data節中,並且數據應採用下面的“ class_data_item ”指定的格式,所有將此類作為定義器的項目。
static_values_off int 從文件開頭到static字段初始值列表的偏移量;如果不存在,則為0如果沒有,則將所有static字段初始化為0null )。此偏移應在data部分中,並且那裡的數據應採用下面的“ encoded_array_item ”指定的格式。數組的大小不得大於此類所聲明的static字段的數量,並且元素與static字段的對應順序應與在相應field_list聲明的順序相同。每個數組元素的類型必須匹配其對應字段的聲明類型。如果數組中的元素少於static字段,則將剩餘的字段初始化為類型合適的0null

call_site_id_item

出現在call_site_ids部分

對齊方式:4個字節

名稱格式描述
call_site_off int 從文件開頭到調用站點定義的偏移量。偏移量應在數據部分中,並且那裡的數據應採用下面的“ call_site_item”指定的格式。

call_site_item

出現在數據部分

對齊方式:無(字節對齊)

The call_site_item is an encoded_array_item whose elements correspond to the arguments provided to a bootstrap linker method. The first three arguments are:

  1. A method handle representing the bootstrap linker method (VALUE_METHOD_HANDLE).
  2. A method name that the bootstrap linker should resolve (VALUE_STRING).
  3. A method type corresponding to the type of the method name to be resolved (VALUE_METHOD_TYPE).

Any additional arguments are constant values passed to the bootstrap linker method. These arguments are passed in order and without any type conversions.

The method handle representing the bootstrap linker method must have return type java.lang.invoke.CallSite . The first three parameter types are:

  1. java.lang.invoke.Lookup
  2. java.lang.String
  3. java.lang.invoke.MethodType

The parameter types of any additional arguments are determined from their constant values.

method_handle_item

appears in the method_handles section

alignment: 4 bytes

Name Format Description
method_handle_type ushort type of the method handle; see table below
unused ushort (unused)
field_or_method_id ushort Field or method id depending on whether the method handle type is an accessor or a method invoker
unused ushort (unused)

Method Handle Type Codes

Constant Value Description
METHOD_HANDLE_TYPE_STATIC_PUT 0x00 Method handle is a static field setter (accessor)
METHOD_HANDLE_TYPE_STATIC_GET 0x01 Method handle is a static field getter (accessor)
METHOD_HANDLE_TYPE_INSTANCE_PUT 0x02 Method handle is an instance field setter (accessor)
METHOD_HANDLE_TYPE_INSTANCE_GET 0x03 Method handle is an instance field getter (accessor)
METHOD_HANDLE_TYPE_INVOKE_STATIC 0x04 Method handle is a static method invoker
METHOD_HANDLE_TYPE_INVOKE_INSTANCE 0x05 Method handle is an instance method invoker
METHOD_HANDLE_TYPE_INVOKE_CONSTRUCTOR 0x06 Method handle is a constructor method invoker
METHOD_HANDLE_TYPE_INVOKE_DIRECT 0x07 Method handle is a direct method invoker
METHOD_HANDLE_TYPE_INVOKE_INTERFACE 0x08 Method handle is an interface method invoker

class_data_item

referenced from class_def_item

appears in the data section

alignment: none (byte-aligned)

Name Format Description
static_fields_size uleb128 the number of static fields defined in this item
instance_fields_size uleb128 the number of instance fields defined in this item
direct_methods_size uleb128 the number of direct methods defined in this item
virtual_methods_size uleb128 the number of virtual methods defined in this item
static_fields encoded_field[static_fields_size] the defined static fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order.
instance_fields encoded_field[instance_fields_size] the defined instance fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order.
direct_methods encoded_method[direct_methods_size] the defined direct (any of static , private , or constructor) methods, represented as a sequence of encoded elements. The methods must be sorted by method_idx in increasing order.
virtual_methods encoded_method[virtual_methods_size] the defined virtual (none of static , private , or constructor) methods, represented as a sequence of encoded elements. This list should not include inherited methods unless overridden by the class that this item represents. The methods must be sorted by method_idx in increasing order. The method_idx of a virtual method must not be the same as any direct method.

Note: All elements' field_id s and method_id s must refer to the same defining class.

encoded_field format

Name Format Description
field_idx_diff uleb128 index into the field_ids list for the identity of this field (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.
access_flags uleb128 access flags for the field ( public , final , etc.). See " access_flags Definitions" for details.

encoded_method format

Name Format Description
method_idx_diff uleb128 index into the method_ids list for the identity of this method (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.
access_flags uleb128 access flags for the method ( public , final , etc.). See " access_flags Definitions" for details.
code_off uleb128 offset from the start of the file to the code structure for this method, or 0 if this method is either abstract or native . The offset should be to a location in the data section. The format of the data is specified by " code_item " below.

type_list

referenced from class_def_item and proto_id_item

appears in the data section

alignment: 4 bytes

Name Format Description
size uint size of the list, in entries
list type_item[size] elements of the list

type_item format

Name Format Description
type_idx ushort index into the type_ids list

code_item

referenced from encoded_method

appears in the data section

alignment: 4 bytes

Name Format Description
registers_size ushort the number of registers used by this code
ins_size ushort the number of words of incoming arguments to the method that this code is for
outs_size ushort the number of words of outgoing argument space required by this code for method invocation
tries_size ushort the number of try_item s for this instance. If non-zero, then these appear as the tries array just after the insns in this instance.
debug_info_off uint offset from the start of the file to the debug info (line numbers + local variable info) sequence for this code, or 0 if there simply is no information. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " debug_info_item " below.
insns_size uint size of the instructions list, in 16-bit code units
insns ushort[insns_size] actual array of bytecode. The format of code in an insns array is specified by the companion document Dalvik bytecode . Note that though this is defined as an array of ushort , there are some internal structures that prefer four-byte alignment. Also, if this happens to be in an endian-swapped file, then the swapping is only done on individual ushort s and not on the larger internal structures.
padding ushort (optional) = 0 two bytes of padding to make tries four-byte aligned. This element is only present if tries_size is non-zero and insns_size is odd.
tries try_item[tries_size] (optional) array indicating where in the code exceptions are caught and how to handle them. Elements of the array must be non-overlapping in range and in order from low to high address. This element is only present if tries_size is non-zero.
handlers encoded_catch_handler_list (optional) bytes representing a list of lists of catch types and associated handler addresses. Each try_item has a byte-wise offset into this structure. This element is only present if tries_size is non-zero.

try_item format

Name Format Description
start_addr uint start address of the block of code covered by this entry. The address is a count of 16-bit code units to the start of the first covered instruction.
insn_count ushort number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 .
handler_off ushort offset in bytes from the start of the associated encoded_catch_hander_list to the encoded_catch_handler for this entry. This must be an offset to the start of an encoded_catch_handler .

encoded_catch_handler_list format

Name Format Description
size uleb128 size of this list, in entries
list encoded_catch_handler[handlers_size] actual list of handler lists, represented directly (not as offsets), and concatenated sequentially

encoded_catch_handler format

Name Format Description
size sleb128 number of catch types in this list. If non-positive, then this is the negative of the number of catch types, and the catches are followed by a catch-all handler. For example: A size of 0 means that there is a catch-all but no explicitly typed catches. A size of 2 means that there are two explicitly typed catches and no catch-all. And a size of -1 means that there is one typed catch along with a catch-all.
handlers encoded_type_addr_pair[abs(size)] stream of abs(size) encoded items, one for each caught type, in the order that the types should be tested.
catch_all_addr uleb128 (optional) bytecode address of the catch-all handler. This element is only present if size is non-positive.

encoded_type_addr_pair format

Name Format Description
type_idx uleb128 index into the type_ids list for the type of the exception to catch
addr uleb128 bytecode address of the associated exception handler

debug_info_item

referenced from code_item

appears in the data section

alignment: none (byte-aligned)

Each debug_info_item defines a DWARF3-inspired byte-coded state machine that, when interpreted, emits the positions table and (potentially) the local variable information for a code_item . The sequence begins with a variable-length header (the length of which depends on the number of method parameters), is followed by the state machine bytecodes, and ends with an DBG_END_SEQUENCE byte.

The state machine consists of five registers. The address register represents the instruction offset in the associated insns_item in 16-bit code units. The address register starts at 0 at the beginning of each debug_info sequence and must only monotonically increase. The line register represents what source line number should be associated with the next positions table entry emitted by the state machine. It is initialized in the sequence header, and may change in positive or negative directions but must never be less than 1 . The source_file register represents the source file that the line number entries refer to. It is initialized to the value of source_file_idx in class_def_item . The other two variables, prologue_end and epilogue_begin , are boolean flags (initialized to false ) that indicate whether the next position emitted should be considered a method prologue or epilogue. The state machine must also track the name and type of the last local variable live in each register for the DBG_RESTART_LOCAL code.

The header is as follows:

Name Format Description
line_start uleb128 the initial value for the state machine's line register. Does not represent an actual positions entry.
parameters_size uleb128 the number of parameter names that are encoded. There should be one per method parameter, excluding an instance method's this , if any.
parameter_names uleb128p1[parameters_size] string index of the method parameter name. An encoded value of NO_INDEX indicates that no name is available for the associated parameter. The type descriptor and signature are implied from the method descriptor and signature.

The byte code values are as follows:

Name Value Format Arguments Description
DBG_END_SEQUENCE 0x00 (none) terminates a debug info sequence for a code_item
DBG_ADVANCE_PC 0x01 uleb128 addr_diff addr_diff : amount to add to address register advances the address register without emitting a positions entry
DBG_ADVANCE_LINE 0x02 sleb128 line_diff line_diff : amount to change line register by advances the line register without emitting a positions entry
DBG_START_LOCAL 0x03 uleb128 register_num
uleb128p1 name_idx
uleb128p1 type_idx
register_num : register that will contain local
name_idx : string index of the name
type_idx : type index of the type
introduces a local variable at the current address. Either name_idx or type_idx may be NO_INDEX to indicate that that value is unknown.
DBG_START_LOCAL_EXTENDED 0x04 uleb128 register_num
uleb128p1 name_idx
uleb128p1 type_idx
uleb128p1 sig_idx
register_num : register that will contain local
name_idx : string index of the name
type_idx : type index of the type
sig_idx : string index of the type signature
introduces a local with a type signature at the current address. Any of name_idx , type_idx , or sig_idx may be NO_INDEX to indicate that that value is unknown. (If sig_idx is -1 , though, the same data could be represented more efficiently using the opcode DBG_START_LOCAL .)

Note: See the discussion under " dalvik.annotation.Signature " below for caveats about handling signatures.

DBG_END_LOCAL 0x05 uleb128 register_num register_num : register that contained local marks a currently-live local variable as out of scope at the current address
DBG_RESTART_LOCAL 0x06 uleb128 register_num register_num : register to restart re-introduces a local variable at the current address. The name and type are the same as the last local that was live in the specified register.
DBG_SET_PROLOGUE_END 0x07 (none) sets the prologue_end state machine register, indicating that the next position entry that is added should be considered the end of a method prologue (an appropriate place for a method breakpoint). The prologue_end register is cleared by any special ( >= 0x0a ) opcode.
DBG_SET_EPILOGUE_BEGIN 0x08 (none) sets the epilogue_begin state machine register, indicating that the next position entry that is added should be considered the beginning of a method epilogue (an appropriate place to suspend execution before method exit). The epilogue_begin register is cleared by any special ( >= 0x0a ) opcode.
DBG_SET_FILE 0x09 uleb128p1 name_idx name_idx : string index of source file name; NO_INDEX if unknown indicates that all subsequent line number entries make reference to this source file name, instead of the default name specified in code_item
Special Opcodes 0x0a…0xff (none) advances the line and address registers, emits a position entry, and clears prologue_end and epilogue_begin . See below for description.

Special opcodes

Opcodes with values between 0x0a and 0xff (inclusive) move both the line and address registers by a small amount and then emit a new position table entry. The formula for the increments are as follows:

DBG_FIRST_SPECIAL = 0x0a  // the smallest special opcode
DBG_LINE_BASE   = -4      // the smallest line number increment
DBG_LINE_RANGE  = 15      // the number of line increments represented

adjusted_opcode = opcode - DBG_FIRST_SPECIAL

line += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE)
address += (adjusted_opcode / DBG_LINE_RANGE)

annotations_directory_item

referenced from class_def_item

appears in the data section

alignment: 4 bytes

Name Format Description
class_annotations_off uint offset from the start of the file to the annotations made directly on the class, or 0 if the class has no direct annotations. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " annotation_set_item " below.
fields_size uint count of fields annotated by this item
annotated_methods_size uint count of methods annotated by this item
annotated_parameters_size uint count of method parameter lists annotated by this item
field_annotations field_annotation[fields_size] (optional) list of associated field annotations. The elements of the list must be sorted in increasing order, by field_idx .
method_annotations method_annotation[methods_size] (optional) list of associated method annotations. The elements of the list must be sorted in increasing order, by method_idx .
parameter_annotations parameter_annotation[parameters_size] (optional) list of associated method parameter annotations. The elements of the list must be sorted in increasing order, by method_idx .

Note: All elements' field_id s and method_id s must refer to the same defining class.

field_annotation format

Name Format Description
field_idx uint index into the field_ids list for the identity of the field being annotated
annotations_off uint offset from the start of the file to the list of annotations for the field. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_item " below.

method_annotation format

Name Format Description
method_idx uint index into the method_ids list for the identity of the method being annotated
annotations_off uint offset from the start of the file to the list of annotations for the method. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_item " below.

parameter_annotation format

Name Format Description
method_idx uint index into the method_ids list for the identity of the method whose parameters are being annotated
annotations_off uint offset from the start of the file to the list of annotations for the method parameters. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_ref_list " below.

annotation_set_ref_list

referenced from parameter_annotations_item

appears in the data section

alignment: 4 bytes

Name Format Description
size uint size of the list, in entries
list annotation_set_ref_item[size] elements of the list

annotation_set_ref_item format

Name Format Description
annotations_off uint offset from the start of the file to the referenced annotation set or 0 if there are no annotations for this element. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " annotation_set_item " below.

annotation_set_item

referenced from annotations_directory_item, field_annotations_item, method_annotations_item, and annotation_set_ref_item

appears in the data section

alignment: 4 bytes

Name Format Description
size uint size of the set, in entries
entries annotation_off_item[size] elements of the set. The elements must be sorted in increasing order, by type_idx .

annotation_off_item format

Name Format Description
annotation_off uint offset from the start of the file to an annotation. The offset should be to a location in the data section, and the format of the data at that location is specified by " annotation_item " below.

annotation_item

referenced from annotation_set_item

appears in the data section

alignment: none (byte-aligned)

Name Format Description
visibility ubyte intended visibility of this annotation (see below)
annotation encoded_annotation encoded annotation contents, in the format described by " encoded_annotation format" under " encoded_value encoding" above.

Visibility values

These are the options for the visibility field in an annotation_item :

Name Value Description
VISIBILITY_BUILD 0x00 intended only to be visible at build time (eg, during compilation of other code)
VISIBILITY_RUNTIME 0x01 intended to visible at runtime
VISIBILITY_SYSTEM 0x02 intended to visible at runtime, but only to the underlying system (and not to regular user code)

encoded_array_item

referenced from class_def_item

appears in the data section

alignment: none (byte-aligned)

Name Format Description
value encoded_array bytes representing the encoded array value, in the format specified by " encoded_array Format" under " encoded_value Encoding" above.

hiddenapi_class_data_item

This section contains data on restricted interfaces used by each class.

Note: The hidden API feature was introduced in Android 10.0 and is only applicable to the DEX files of classes in the boot class path. The list of flags described below may be extended in the future releases of Android. For more information, see restrictions on non-SDK interfaces .

Name Format Description
size uint total size of the section
offsets uint[] array of offsets indexed by class_idx . A zero array entry at index class_idx means that either there is no data for this class_idx , or all hidden API flags are zero. Otherwise the array entry is non-zero and contains an offset from the beginning of the section to an array of hidden API flags for this class_idx .
flags uleb128[] concatenated arrays of hidden API flags for each class. Possible flag values are described in the table below. Flags are encoded in the same order as fields and methods are encoded in class data.

Restriction flag types:

Name Value Description
whitelist 0 Interfaces that can be freely used and are supported as part of the officially documented Android framework Package Index .
greylist 1 Non-SDK interfaces that can be used regardless of the application's target API level .
blacklist 2 Non-SDK interfaces that cannot be used regardless of the application's target API level . Accessing one of these interfaces causes a runtime error .
greylist‑max‑o 3 Non-SDK interfaces that can be used for Android 8.x and below unless they are restricted.
greylist‑max‑p 4 Non-SDK interfaces that can be used for Android 9.x unless they are restricted.
greylist‑max‑q 5 Non-SDK interfaces that can be used for Android 10.x unless they are restricted.
greylist‑max‑r 6 Non-SDK interfaces that can be used for Android 11.x unless they are restricted.

System annotations

System annotations are used to represent various pieces of reflective information about classes (and methods and fields). This information is generally only accessed indirectly by client (non-system) code.

System annotations are represented in .dex files as annotations with visibility set to VISIBILITY_SYSTEM .

dalvik.annotation.AnnotationDefault

appears on methods in annotation interfaces

An AnnotationDefault annotation is attached to each annotation interface which wishes to indicate default bindings.

Name Format Description
value Annotation the default bindings for this annotation, represented as an annotation of this type. The annotation need not include all names defined by the annotation; missing names simply do not have defaults.

dalvik.annotation.EnclosingClass

appears on classes

An EnclosingClass annotation is attached to each class which is either defined as a member of another class, per se, or is anonymous but not defined within a method body (eg, a synthetic inner class). Every class that has this annotation must also have an InnerClass annotation. Additionally, a class must not have both an EnclosingClass and an EnclosingMethod annotation.

Name Format Description
value Class the class which most closely lexically scopes this class

dalvik.annotation.EnclosingMethod

appears on classes

An EnclosingMethod annotation is attached to each class which is defined inside a method body. Every class that has this annotation must also have an InnerClass annotation. Additionally, a class must not have both an EnclosingClass and an EnclosingMethod annotation.

Name Format Description
value Method the method which most closely lexically scopes this class

dalvik.annotation.InnerClass

appears on classes

An InnerClass annotation is attached to each class which is defined in the lexical scope of another class's definition. Any class which has this annotation must also have either an EnclosingClass annotation or an EnclosingMethod annotation.

Name Format Description
name String the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null .
accessFlags int the originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine)

dalvik.annotation.MemberClasses

appears on classes

A MemberClasses annotation is attached to each class which declares member classes. (A member class is a direct inner class that has a name.)

Name Format Description
value Class[] array of the member classes

dalvik.annotation.MethodParameters

appears on methods

Note: This annotation was added after Android 7.1. Its presence on earlier Android releases will be ignored.

A MethodParameters annotation is optional and can be used to provide parameter metadata such as parameter names and modifiers.

The annotation can be omitted from a method or constructor safely when the parameter metadata is not required at runtime. java.lang.reflect.Parameter.isNamePresent() can be used to check whether metadata is present for a parameter, and the associated reflection methods such as java.lang.reflect.Parameter.getName() will fall back to default behavior at runtime if the information is not present.

When including parameter metadata, compilers must include information for generated classes such as enums, since the parameter metadata includes whether or not a parameter is synthetic or mandated.

A MethodParameters annotation describes only individual method parameters. Therefore, compilers may omit the annotation entirely for constructors and methods that have no parameters, for the sake of code-size and runtime efficiency.

The arrays documented below must be the same size as for the method_id_item dex structure associated with the method, otherwise a java.lang.reflect.MalformedParametersException will be thrown at runtime.

That is: method_id_item.proto_idx -> proto_id_item.parameters_off -> type_list.size must be the same as names().length and accessFlags().length .

Because MethodParameters describes all formal method parameters, even those not explicitly or implicitly declared in source code, the size of the arrays may differ from the Signature or other metadata information that is based only on explicit parameters declared in source code. MethodParameters will also not include any information about type annotation receiver parameters that do not exist in the actual method signature.

Name Format Description
names String[] The names of formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. A value in the array must be null if the formal parameter with that index has no name.
If parameter name strings are empty or contain '.', ';', '[' or '/' then a java.lang.reflect.MalformedParametersException will be thrown at runtime.
accessFlags int[] The access flags of the formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters.
The value is a bit mask with the following values:
  • 0x0010 : final, the parameter was declared final
  • 0x1000 : synthetic, the parameter was introduced by the compiler
  • 0x8000 : mandated, the parameter is synthetic but also implied by the language specification
If any bits are set outside of this set then a java.lang.reflect.MalformedParametersException will be thrown at runtime.

dalvik.annotation.Signature

appears on classes, fields, and methods

A Signature annotation is attached to each class, field, or method which is defined in terms of a more complicated type than is representable by a type_id_item . The .dex format does not define the format for signatures; it is merely meant to be able to represent whatever signatures a source language requires for successful implementation of that language's semantics. As such, signatures are not generally parsed (or verified) by virtual machine implementations. The signatures simply get handed off to higher-level APIs and tools (such as debuggers). Any use of a signature, therefore, should be written so as not to make any assumptions about only receiving valid signatures, explicitly guarding itself against the possibility of coming across a syntactically invalid signature.

Because signature strings tend to have a lot of duplicated content, a Signature annotation is defined as an array of strings, where duplicated elements naturally refer to the same underlying data, and the signature is taken to be the concatenation of all the strings in the array. There are no rules about how to pull apart a signature into separate strings; that is entirely up to the tools that generate .dex files.

Name Format Description
value String[] the signature of this class or member, as an array of strings that is to be concatenated together

dalvik.annotation.Throws

appears on methods

A Throws annotation is attached to each method which is declared to throw one or more exception types.

Name Format Description
value Class[] the array of exception types thrown