このドキュメントでは、一連のクラス定義とそれに関連する付属データを保持するために使用される.dex
ファイルのレイアウトと内容について説明します。
タイプガイド
名前 | 説明 |
---|---|
バイト | 8 ビット符号付き整数 |
ubyte | 8 ビット符号なし整数 |
短い | 16 ビットの符号付き整数、リトル エンディアン |
ショート | 16 ビット符号なし int、リトル エンディアン |
整数 | 32 ビット符号付き int、リトル エンディアン |
ユニット | 32 ビット符号なし int、リトル エンディアン |
長いです | 64 ビット符号付き int、リトル エンディアン |
ロング | 64 ビット符号なし int、リトル エンディアン |
スレブ128 | 符号付き LEB128、可変長 (下記参照) |
ウレブ128 | 符号なし LEB128、可変長 (下記参照) |
uleb128p1 | unsigned LEB128 plus 1 、可変長 (下記参照) |
LEB128
LEB128 (" L ittle- Endian Base 128 ") は、任意の符号付きまたは符号なし整数量の可変長エンコーディングです。形式はDWARF3仕様から借用されました。 .dex
ファイルでは、LEB128 は 32 ビット量をエンコードするためにのみ使用されます。
LEB128 でエンコードされた各値は、1 から 5 バイトで構成され、これらを合わせて 1 つの 32 ビット値を表します。各バイトには、最上位ビットがクリアされているシーケンスの最後のバイトを除いて、最上位ビットが設定されています。各バイトの残りの 7 ビットはペイロードであり、量の最下位 7 ビットが最初のバイトに、次の 7 ビットが 2 番目のバイトに、というように続きます。符号付き LEB128 ( sleb128
) の場合、シーケンスの最終バイトの最上位ペイロード ビットが符号拡張されて、最終値が生成されます。符号なしの場合 ( uleb128
)、明示的に表されていないビットは0
として解釈されます。
2 バイトの LEB128 値のビット単位の図 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
最初のバイト | 2バイト目 | ||||||||||||||
1 | ビット6 | ビット5 | ビット4 | ビット3 | ビット2 | ビット1 | ビット0 | 0 | ビット13 | ビット12 | ビット11 | ビット10 | ビット9 | ビット8 | ビット7 |
バリアントuleb128p1
は、符号付きの値を表すために使用されます。この表現は、 uleb128
としてエンコードされた値に 1 を加えたものです。これにより、 -1
(符号なしの値0xffffffff
と考えられる) のエンコーディングが作成されますが、他の負の数は 1 バイトではなく、表現される数値が非負または-1
(または0xffffffff
)、およびその他の負の値が許可されていない場所 (または大きな符号なし値が必要になる可能性が低い場所)。
フォーマットの例を次に示します。
エンコードされたシーケンス | sleb128 として | uleb128 として | uleb128p1 として |
---|---|---|---|
00 | 0 | 0 | -1 |
01 | 1 | 1 | 0 |
7f | -1 | 127 | 126 |
80 7f | -128 | 16256 | 16255 |
ファイルのレイアウト
名前 | フォーマット | 説明 |
---|---|---|
ヘッダ | header_item | ヘッダー |
string_id | string_id_item[] | 文字列識別子リスト。これらは、このファイルで使用されるすべての文字列の識別子であり、内部命名 (型記述子など) またはコードによって参照される定数オブジェクトとして使用されます。このリストは、UTF-16 コード ポイント値を使用して (ロケールに依存しない方法で)、文字列の内容で並べ替える必要があり、重複するエントリが含まれていてはなりません。 |
type_id | type_id_item[] | タイプ識別子リスト。これらは、ファイルで定義されているかどうかに関係なく、このファイルによって参照されるすべての型 (クラス、配列、またはプリミティブ型) の識別子です。このリストは、 string_id インデックスでソートする必要があり、重複するエントリが含まれていてはなりません。 |
proto_ids | proto_id_item[] | メソッド プロトタイプ識別子リスト。これらは、このファイルによって参照されるすべてのプロトタイプの識別子です。このリストは、戻り値の型 ( type_id インデックス順) で並べ替え、次に引数リスト (辞書式順序、個々の引数をtype_id インデックス順) で並べ替える必要があります。リストに重複するエントリが含まれていてはなりません。 |
フィールド ID | field_id_item[] | フィールド識別子リスト。これらは、ファイルで定義されているかどうかに関係なく、このファイルによって参照されるすべてのフィールドの識別子です。このリストはソートする必要があります。定義するタイプ ( type_id インデックスによる) がメジャー オーダー、フィールド名 ( string_id インデックスによる) が中間オーダー、タイプ ( type_id インデックスによる) がマイナー オーダーです。リストに重複するエントリが含まれていてはなりません。 |
method_id | 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[] | 上記のテーブルのすべてのサポート データを含むデータ領域。アイテムごとに異なるアライメント要件があり、適切なアライメントを実現するために、必要に応じて各アイテムの前にパディング バイトが挿入されます。 |
リンクデータ | ubyte[] | 静的にリンクされたファイルで使用されるデータ。このセクションのデータの形式は、このドキュメントでは規定されていません。このセクションは、リンクされていないファイルでは空であり、ランタイムの実装は適切と思われる場合に使用できます。 |
ビットフィールド、文字列、および定数の定義
DEX_FILE_MAGIC
header_item に埋め込まれています
定数配列/文字列DEX_FILE_MAGIC
は、.dex ファイルとして認識されるために、 .dex
ファイルの先頭に表示される必要があるバイトのリストです。特定の形式の破損の検出に役立つように、値には意図的に改行 ( "\n"
または0x0a
) と NULL バイト ( "\0"
または0x00
) が含まれています。この値は、フォーマットのバージョン番号も 3 桁の 10 進数としてエンコードします。これは、フォーマットが進化するにつれて時間の経過とともに単調に増加すると予想されます。
ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x39 0x00 } = "dex\n039\0"
注:この形式のバージョン039
のサポートは Android 9.0 リリースで追加され、2 つの新しいバイトコードconst-method-handle
とconst-method-type
が導入されました。 Android 10 では、バージョン039
でDEXファイル形式が拡張され、ブート クラス パス上の DEX ファイルにのみ適用される非表示の API 情報が含まれるようになりました。
注:バージョン038
の形式のサポートは、Android 8.0 リリースで追加されました。バージョン038
では、新しいバイトコード ( invoke-polymorphic
およびinvoke-custom
) とメソッド ハンドルのデータが追加されました。
注:バージョン037
の形式のサポートは、Android 7.0 リリースで追加されました。バージョン037
より前の Android のほとんどのバージョンでは、バージョン035
の形式が使用されていました。バージョン035
と037
の唯一の違いは、デフォルト メソッドの追加とinvoke
の調整です。
注:この形式の少なくとも 2 つの以前のバージョンは、広く入手可能な公開ソフトウェア リリースで使用されています。たとえば、バージョン009
は Android プラットフォームの M3 リリース (2007 年 11 月から 12 月) に使用され、バージョン013
は Android プラットフォームの M5 リリース (2008 年 2 月から 3 月) に使用されました。いくつかの点で、これらの以前のバージョンの形式は、このドキュメントで説明されているバージョンとは大きく異なります。
ENDIAN_CONSTANT および REVERSE_ENDIAN_CONSTANT
header_item に埋め込まれています
定数ENDIAN_CONSTANT
は、見つかったファイルのエンディアンを示すために使用されます。標準の.dex
形式はリトル エンディアンですが、実装によってバイト スワップの実行が選択される場合があります。実装がendian_tag
がREVERSE_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
エンコーディングで 1 バイトとして表現できます。
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_VOLATILE | 0x40 | volatile : スレッド セーフに役立つ特別なアクセス ルール | ||
ACC_BRIDGE | 0x40 | タイプ セーフなブリッジとしてコンパイラによって自動的に追加される bridge メソッド | ||
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_合成 | 0x1000 | ソースコードで直接定義されていない | ソースコードで直接定義されていない | ソースコードで直接定義されていない |
ACC_ANNOTATION | 0x2000 | 注釈クラスとして宣言 | ||
ACC_ENUM | 0x4000 | 列挙型として宣言 | 列挙値として宣言 | |
(未使用) | 0x8000 | |||
ACC_CONSTRUCTOR | 0x10000 | コンストラクター メソッド (クラスまたはインスタンス初期化子) | ||
ACC_DECLARED_ 同期 | 0x20000 | 宣言されたsynchronized 。注:これは実行には影響しません (このフラグ自体の反映以外には)。 |
InnerClass
アノテーションでのみ on が許可され、 class_def_item
で on であってはなりません。
MUTF-8 (修正 UTF-8) エンコーディング
より簡単なレガシー サポートへの譲歩として、 .dex
形式はその文字列データを事実上の標準の変更された UTF-8 形式 (以降、MUTF-8 と呼びます) でエンコードします。この形式は、次の点を除いて、標準の UTF-8 と同じです。
- 1、2、および 3 バイトのエンコーディングのみが使用されます。
-
U+10000
…U+10ffff
の範囲のコード ポイントは、それぞれが 3 バイトのエンコードされた値として表されるサロゲート ペアとしてエンコードされます。 - コード ポイント
U+0000
は 2 バイト形式でエンコードされます。 - 通常のヌル バイト (値
0
) は、標準の C 言語の解釈と同様に、文字列の末尾を示します。
上記の最初の 2 つの項目は次のように要約できます。MUTF-8 は、Unicode 文字のより直接的なエンコーディング形式ではなく、UTF-16 のエンコーディング形式です。
上記の最後の 2 つの項目により、コード ポイントU+0000
を文字列に含め、それを C スタイルのヌル終了文字列として操作することが同時に可能になります。
ただし、 U+0000
の特別なエンコーディングは、通常の UTF-8 とは異なり、MUTF-8 文字列のペアで標準 C 関数strcmp()
を呼び出した結果が、等しくない文字列の比較の適切に署名された結果を常に示すとは限らないことを意味します。 .順序付け (同等性だけでなく) が重要な場合、MUTF-8 文字列を比較する最も簡単な方法は、それらを文字ごとにデコードし、デコードされた値を比較することです。 (ただし、より賢い実装も可能です。)
文字エンコーディングの詳細については、Unicode 標準を参照してください。 MUTF-8 は実際には、UTF-8 自体よりも (比較的あまり知られていない) エンコードCESU-8に近いです。
encoded_value エンコーディング
annotation_element と encoded_array_item に埋め込まれています
encoded_value
は、(ほぼ) 任意の階層構造データのエンコードされた断片です。エンコーディングは、コンパクトで簡単に解析できるようにすることを目的としています。
名前 | フォーマット | 説明 |
---|---|---|
(value_arg << 5) | value_type | ubyte | 直後のvalue のタイプを示すバイトと、上位 3 ビットのオプションの明確化引数。さまざまなvalue の定義については、以下を参照してください。ほとんどの場合、 value_arg は直後のvalue の長さを(size - 1) のようにバイト単位でエンコードします。たとえば、 0 は値に 1 バイトが必要であることを意味し、 7 は 8 バイトが必要であることを意味します。ただし、以下に示す例外があります。 |
価値 | ubyte[] | 値を表すバイト。長さは可変で、常にリトルエンディアンですが、 value_type バイトごとに異なる解釈がされます。詳細については、以下のさまざまな値の定義を参照してください。 |
値の形式
タイプ名 | value_type | value_arg 形式 | value の形式 | 説明 |
---|---|---|---|---|
VALUE_BYTE | 0x00 | (なし; 0 でなければなりません) | ubyte[1] | 符号付き半角整数値 |
VALUE_SHORT | 0x02 | サイズ - 1 (0…1) | ubyte[サイズ] | 符号付き 2 バイト整数値、符号拡張 |
VALUE_CHAR | 0x03 | サイズ - 1 (0…1) | ubyte[サイズ] | 符号なし 2 バイト整数値、ゼロ拡張 |
VALUE_INT | 0x04 | サイズ - 1 (0…3) | ubyte[サイズ] | 符号付き 4 バイト整数値、符号拡張 |
VALUE_LONG | 0x06 | サイズ - 1 (0…7) | ubyte[サイズ] | 符号付き 8 バイト整数値、符号拡張 |
VALUE_FLOAT | 0x10 | サイズ - 1 (0…3) | ubyte[サイズ] | 右にゼロ拡張され、IEEE754 32 ビット浮動小数点値として解釈される 4 バイトのビット パターン |
VALUE_DOUBLE | 0x11 | サイズ - 1 (0…7) | ubyte[サイズ] | 右にゼロ拡張され、IEEE754 64 ビット浮動小数点値として解釈される 8 バイトのビット パターン |
VALUE_METHOD_TYPE | 0x15 | サイズ - 1 (0…3) | ubyte[サイズ] | 符号なし (ゼロ拡張) の 4 バイト整数値proto_ids セクションへのインデックスとして解釈され、メソッド タイプ値を表します。 |
VALUE_METHOD_HANDLE | 0x16 | サイズ - 1 (0…3) | ubyte[サイズ] | method_handles セクションへのインデックスとして解釈され、メソッド ハンドル値を表す符号なし (ゼロ拡張) 4 バイト整数値 |
VALUE_STRING | 0x17 | サイズ - 1 (0…3) | ubyte[サイズ] | string_ids セクションへのインデックスとして解釈され、文字列値を表す符号なし (ゼロ拡張) の 4 バイト整数値 |
VALUE_TYPE | 0x18 | サイズ - 1 (0…3) | ubyte[サイズ] | type_ids セクションへのインデックスとして解釈され、反映型/クラス値を表す符号なし (ゼロ拡張) 4 バイト整数値 |
VALUE_FIELD | 0x19 | サイズ - 1 (0…3) | ubyte[サイズ] | field_ids セクションへのインデックスとして解釈され、反映フィールド値を表す符号なし (ゼロ拡張) 4 バイト整数値 |
VALUE_METHOD | 0x1a | サイズ - 1 (0…3) | ubyte[サイズ] | method_ids セクションへのインデックスとして解釈され、リフレクション メソッド値を表す符号なし (ゼロ拡張) 4 バイト整数値 |
VALUE_ENUM | 0x1b | サイズ - 1 (0…3) | ubyte[サイズ] | field_ids セクションへのインデックスとして解釈され、列挙型定数の値を表す符号なし (ゼロ拡張) 4 バイト整数値 |
VALUE_ARRAY | 0x1c | (なし; 0 でなければなりません) | エンコードされた配列 | 以下の「 encoded_array format」で指定された形式の値の配列。 value のサイズは、エンコーディングで暗黙的に指定されます。 |
VALUE_ANNOTATION | 0x1d | (なし; 0 でなければなりません) | エンコードされた注釈 | 以下の「 encoded_annotation 形式」で指定された形式のサブ注釈。 value のサイズは、エンコーディングで暗黙的に指定されます。 |
値_NULL | 0x1e | (なし; 0 でなければなりません) | (なし) | null 参照値 |
VALUE_BOOLEAN | 0x1f | ブール値 (0…1) | (なし) | 1 ビット値; false の場合は0 、 true は1 です。ビットはvalue_arg で表されます。 |
エンコードされた配列形式
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ウレブ128 | 配列の要素数 |
値 | エンコードされた_値[サイズ] | 順次連結された、このセクションで指定された形式の一連のsize のencoded_value バイト シーケンス。 |
エンコードされた注釈形式
名前 | フォーマット | 説明 |
---|---|---|
type_idx | ウレブ128 | 注釈のタイプ。これはクラス (配列またはプリミティブではない) 型でなければなりません。 |
サイズ | ウレブ128 | このアノテーションの名前と値のマッピングの数 |
要素 | 注釈要素[サイズ] | 直接インラインで表される (オフセットとしてではなく) 注釈の要素。要素は、 string_id インデックスの昇順で並べ替える必要があります。 |
注釈要素の形式
名前 | フォーマット | 説明 |
---|---|---|
name_idx | ウレブ128 | string_ids セクションへのインデックスとして表される要素名。文字列は、上で定義したMemberNameの構文に準拠する必要があります。 |
価値 | エンコードされた値 | 要素値 |
文字列構文
最終的に文字列を参照する.dex
ファイルには、いくつかの種類の項目があります。次の BNF スタイルの定義は、これらの文字列の受け入れ可能な構文を示しています。
シンプルネーム
SimpleNameは、他のものの名前の構文の基礎です。 .dex
形式では、ここでかなりの自由度が許容されます (ほとんどの一般的なソース言語よりもはるかに広い)。簡単に言うと、単純な名前は、下位 ASCII のアルファベット文字または数字、いくつかの特定の下位 ASCII 記号、および制御、スペース、または特殊文字ではないほとんどの非 ASCII コード ポイントで構成されます。バージョン040
以降、この形式ではスペース文字を追加で使用できます (Unicode Zs
カテゴリ)。サロゲート コード ポイント ( U+d800
… U+dfff
の範囲) は、それ自体は有効な名前文字とは見なされませんが、Unicode の補助文字は有効であることに注意してください (これは、 SimpleNameCharのルールの最終的な選択肢によって表されます)。ファイルでは、MUTF-8 エンコーディングのサロゲート コード ポイントのペアとして表す必要があります。
シンプルネーム→ | ||
SimpleNameChar ( SimpleNameChar )* | ||
SimpleNameChar → | ||
'A' … 'Z' | ||
| | | 'a' … 'z' | |
| | | '0' … '9' | |
| | | ' ' | DEX バージョン 040 以降 |
| | | '$' | |
| | | '-' | |
| | | '_' | |
| | | U+00a0 | DEX バージョン 040 以降 |
| | | U+00a1 … U+1fff | |
| | | U+2000 … U+200a | DEX バージョン 040 以降 |
| | | U+2010 … U+2027 | |
| | | U+202f | DEX バージョン 040 以降 |
| | | U+2030 … U+d7ff | |
| | | U+e000 … U+ffef | |
| | | U+10000 … U+10ffff |
メンバー名
field_id_item と method_id_item で使用
MemberNameはクラスのメンバーの名前であり、メンバーはフィールド、メソッド、および内部クラスです。
会員名→ | |
シンプルネーム | |
| | | '<' シンプルネーム'>' |
FullClassName
FullClassNameは、オプションのパッケージ指定子とそれに続く必須の名前を含む完全修飾クラス名です。
フルクラス名→ | |
OptionalPackagePrefix SimpleName | |
OptionalPackagePrefix → | |
(単純な名前'/' )* |
TypeDescriptor
type_id_item で使用
TypeDescriptorは、プリミティブ、クラス、配列、およびvoid
を含む任意の型の表現です。さまざまなバージョンの意味については、以下を参照してください。
TypeDescriptor → | |
'V' | |
| | | FieldTypeDescriptor |
FieldTypeDescriptor → | |
NonArrayFieldTypeDescriptor | |
| | | ( '[' * 1…255) NonArrayFieldTypeDescriptor |
NonArrayFieldTypeDescriptor → | |
'Z' | |
| | | 'B' |
| | | 'S' |
| | | 'C' |
| | | 'I' |
| | | 'J' |
| | | 'F' |
| | | 'D' |
| | | 'L' フルクラス名';' |
ShortyDescriptor
proto_id_item で使用
ShortyDescriptorは、さまざまな参照 (クラスまたは配列) 型の間に区別がないことを除いて、戻り値とパラメーターの型を含むメソッド プロトタイプの短い形式の表現です。代わりに、すべての参照型は単一'L'
文字で表されます。
ShortyDescriptor → | |
ShortyReturnType ( ShortyFieldType )* | |
ShortyReturnType → | |
'V' | |
| | | ShortyFieldType |
ShortyFieldType → | |
'Z' | |
| | | 'B' |
| | | 'S' |
| | | 'C' |
| | | 'I' |
| | | 'J' |
| | | 'F' |
| | | 'D' |
| | | 'L' |
TypeDescriptorセマンティクス
これは、 TypeDescriptorの各バリアントの意味です。
構文 | 意味 |
---|---|
Ⅴ | void ;戻り値の型にのみ有効 |
Z | boolean |
B | byte |
S | short |
C | char |
私 | int |
J | long |
ふ | float |
D | double |
L完全/修飾/名前; | クラスのfully.qualified.Name |
[記述子 | 配列の配列に対して再帰descriptor に使用できますが、255 次元を超えることは無効です。 |
アイテムと関連構造
このセクションには、 .dex
ファイルに表示される可能性がある各最上位項目の定義が含まれています。
header_item
ヘッダーセクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
マジック | ubyte[8] = DEX_FILE_MAGIC | 魔法値。詳細については、上記の「 DEX_FILE_MAGIC 」の下の説明を参照してください。 |
チェックサム | ユニット | ファイルの残りの adler32 チェックサム ( magic とこのフィールド以外のすべて)。ファイルの破損を検出するために使用されます |
サイン | ubyte[20] | ファイルの残りの SHA-1 署名 (ハッシュ) ( magic 、 checksum 、およびこのフィールド以外のすべて)。ファイルを一意に識別するために使用されます |
ファイルサイズ | ユニット | ファイル全体 (ヘッダーを含む) のサイズ (バイト単位) |
header_size | 単位 = 0x70 | ヘッダー (このセクション全体) のサイズ (バイト単位)。これにより、フォーマットを無効にすることなく、少なくとも限られた量の後方/前方互換性が可能になります。 |
endian_tag | uint = ENDIAN_CONSTANT | エンディアン タグ。詳細については、上記の「 ENDIAN_CONSTANT およびREVERSE_ENDIAN_CONSTANT 」の下の説明を参照してください。 |
link_size | ユニット | リンク セクションのサイズ、またはこのファイルが静的にリンクされていない場合は0 |
リンクオフ | ユニット | ファイルの先頭からリンク セクションまでのオフセット、またはlink_size == 0 0 ゼロ以外のオフセットは、 link_data セクションへのオフセットである必要があります。指摘されたデータの形式は、このドキュメントでは規定されていません。このヘッダー フィールド (および前のフィールド) は、ランタイム実装で使用するためのフックとして残されます。 |
map_off | ユニット | ファイルの先頭からマップ項目までのオフセット。ゼロ以外のオフセットは、 data セクションへのオフセットである必要があり、データは以下の「 map_list 」で指定された形式である必要があります。 |
string_ids_size | ユニット | 文字列識別子リスト内の文字列の数 |
string_ids_off | ユニット | ファイルの先頭から文字列識別子リストまでのオフセット、またはstring_ids_size == 0 0 確かに奇妙なエッジ ケース)。ゼロ以外の場合、オフセットはstring_ids セクションの先頭にする必要があります。 |
type_ids_size | ユニット | タイプ識別子リスト内の要素の数、最大 65535 |
type_ids_off | ユニット | ファイルの先頭から型識別子リストまでのオフセット、またはtype_ids_size == 0 0 確かに奇妙なエッジ ケース)。ゼロ以外の場合、オフセットはtype_ids セクションの先頭にある必要があります。 |
proto_ids_size | ユニット | プロトタイプ識別子リスト内の要素の数、最大 65535 |
proto_ids_off | ユニット | ファイルの先頭からプロトタイプ識別子リストまでのオフセット、またはproto_ids_size == 0 0 確かに奇妙なエッジ ケース)。ゼロ以外のオフセットは、 proto_ids セクションの先頭に設定する必要があります。 |
field_ids_size | ユニット | フィールド識別子リストの要素数 |
field_ids_off | ユニット | ファイルの先頭からフィールド識別子リストまでのオフセット、またはfield_ids_size == 0 0 ゼロ以外の場合、オフセットはfield_ids セクションの先頭にある必要があります。 |
method_ids_size | ユニット | メソッド識別子リストの要素数 |
method_ids_off | ユニット | ファイルの先頭からメソッド識別子リストまでのオフセット、またはmethod_ids_size == 0 0 オフセットがゼロでない場合は、 method_ids セクションの先頭までにする必要があります。 |
class_defs_size | ユニット | クラス定義リストの要素数 |
class_defs_off | ユニット | ファイルの先頭からクラス定義リストまでのオフセット、またはclass_defs_size == 0 0 確かに奇妙なエッジ ケース)。ゼロ以外の場合、オフセットはclass_defs セクションの先頭にある必要があります。 |
データサイズ | ユニット | data セクションのサイズ (バイト単位)。 sizeof(uint) の偶数倍でなければなりません。 |
data_off | ユニット | ファイルの先頭からdata セクションの先頭までのオフセット。 |
map_list
データセクションに表示されます
header_item から参照
アラインメント: 4 バイト
これは、ファイルの内容全体を順番に並べたリストです。これには、 header_item
に関していくらかの冗長性が含まれていますが、ファイル全体を反復処理するために使用する簡単な形式になることを目的としています。与えられたタイプは、マップ内で最大 1 回出現する必要がありますが、形式の残りの部分によって暗示される制限を除いて、タイプが出現する順序に制限はありません (たとえば、 header
セクションが最初に出現し、その後にstring_ids
が続く必要があります)。セクションなど)。さらに、マップ エントリは初期オフセット順に並べる必要があり、重複してはなりません。
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ユニット | エントリのリストのサイズ |
リスト | map_item[サイズ] | リストの要素 |
map_item 形式
名前 | フォーマット | 説明 |
---|---|---|
タイプ | ショート | アイテムの種類;下の表を参照 |
未使用 | ショート | (未使用) |
サイズ | ユニット | 指定されたオフセットで検出されるアイテムの数のカウント |
オフセット | ユニット | ファイルの先頭から問題の項目までのオフセット |
タイプコード
アイテムの種類 | 絶え間ない | 価値 | 項目サイズ (バイト単位) |
---|---|---|---|
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_TYPE_LIST | 0x1001 | 4 + (アイテムのサイズ * 2) |
annotation_set_ref_list | 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 | 暗黙;解析する必要があります |
エンコードされた配列アイテム | 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 | ユニット | ファイルの先頭からこのアイテムの文字列データまでのオフセット。オフセットはdata セクション内の位置である必要があり、データは以下の " string_data_item " で指定された形式である必要があります。オフセットのアライメント要件はありません。 |
string_data_item
データセクションに表示されます
整列: なし (バイト整列)
名前 | フォーマット | 説明 |
---|---|---|
utf16_size | ウレブ128 | この文字列のサイズ (UTF-16 コード単位) (多くのシステムでは「文字列の長さ」)。つまり、これは文字列のデコードされた長さです。 (エンコードされた長さは、 0 バイトの位置によって暗示されます。) |
データ | ubyte[] | 一連の MUTF-8 コード単位 (別名オクテット、別名バイト) の後に値0 のバイトが続きます。データ形式の詳細と説明については、上記の「MUTF-8 (Modified UTF-8) Encoding」を参照してください。注: UTF-16 サロゲート コード ユニット (つまり、 |
type_id_item
type_ids セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
descriptor_idx | ユニット | このタイプの記述子文字列のstring_ids リストへのインデックス。文字列は、上で定義したTypeDescriptorの構文に準拠する必要があります。 |
proto_id_item
proto_ids セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
shorty_idx | ユニット | このプロトタイプの短い形式の記述子文字列のstring_ids リストへのインデックス。文字列は、上記で定義されたShortyDescriptorの構文に準拠している必要があり、このアイテムの戻り値の型とパラメーターに対応している必要があります。 |
return_type_idx | ユニット | このプロトタイプの戻り型のtype_ids リストへのインデックス |
parameters_off | ユニット | ファイルの先頭からこのプロトタイプのパラメーター型のリストまでのオフセット、またはこのプロトタイプにパラメーターがない場合は0 。このオフセットがゼロでない場合は、 data セクションにある必要があり、そこにあるデータは、以下の"type_list" で指定された形式である必要があります。さらに、リストにはvoid 型への参照があってはなりません。 |
field_id_item
field_ids セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
class_idx | ショート | このフィールドの定義者のtype_ids リストへのインデックス。これは、配列またはプリミティブ型ではなく、クラス型である必要があります。 |
type_idx | ショート | このフィールドのタイプのtype_ids リストへのインデックス |
name_idx | ユニット | このフィールドの名前のstring_ids リストにインデックスを付けます。文字列は、上で定義したMemberNameの構文に準拠する必要があります。 |
method_id_item
method_ids セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
class_idx | ショート | このメソッドの定義者のtype_ids リストにインデックスを付けます。これは、プリミティブ型ではなく、クラスまたは配列型である必要があります。 |
proto_idx | ショート | このメソッドのプロトタイプのproto_ids リストへのインデックス |
name_idx | ユニット | このメソッドの名前のstring_ids リストにインデックスを付けます。文字列は、上で定義したMemberNameの構文に準拠する必要があります。 |
class_def_item
class_defs セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
class_idx | ユニット | このクラスのtype_ids リストへのインデックス。これは、配列またはプリミティブ型ではなく、クラス型である必要があります。 |
access_flags | ユニット | クラスのアクセス フラグ ( public 、 final など)。詳細については、「 access_flags 定義」を参照してください。 |
superclass_idx | ユニット | スーパークラスのtype_ids リストへのインデックス、またはこのクラスがスーパークラスを持たない (つまり、 Object などのルート クラスである) 場合は定数値NO_INDEX です。存在する場合、これはクラス型である必要があり、配列またはプリミティブ型ではありません。 |
インターフェイスオフ | ユニット | ファイルの先頭からインターフェイスのリストまでのオフセット、または存在しない場合は0 。このオフセットはdata セクションにある必要があり、そこにあるデータは以下の「 type_list 」で指定された形式である必要があります。リストの各要素は (配列やプリミティブ型ではなく) クラス型でなければならず、重複があってはなりません。 |
source_file_idx | ユニット | このクラス (少なくとも大部分) の元のソースを含むファイルの名前のstring_ids リストへのインデックス、またはこの情報の欠如を表す特別な値NO_INDEX 。特定のメソッドのdebug_info_item は、このソース ファイルをオーバーライドする可能性がありますが、ほとんどのクラスは 1 つのソース ファイルからしか取得されないことが予想されます。 |
注釈_オフ | ユニット | ファイルの先頭からこのクラスの注釈構造体までのオフセット、またはこのクラスに注釈がない場合は0 。このオフセットがゼロでない場合は、 data セクションにある必要があり、そこにあるデータは、以下の「 annotations_directory_item 」で指定された形式である必要があります。すべてのアイテムは、このクラスを定義者として参照しています。 |
class_data_off | ユニット | ファイルの先頭からこの項目の関連するクラス データまでのオフセット、またはこのクラスのクラス データがない場合は0 。 (これは、たとえば、このクラスがマーカー インターフェイスの場合に当てはまります。) ゼロ以外の場合、オフセットはdata セクションにある必要があり、そこにあるデータは、以下の「 class_data_item 」で指定された形式である必要があります。すべての項目がこのクラスを定義者として参照しています。 |
static_values_off | ユニット | ファイルの先頭からstatic フィールドの初期値のリストまでのオフセット、または何もない場合は0 (すべてのstatic フィールドは0 またはnull で初期化されます)。このオフセットはdata セクションにある必要があり、そこにあるデータは、以下の「 encoded_array_item 」で指定された形式である必要があります。配列のサイズは、このクラスによって宣言されたstatic フィールドの数を超えてはなりません。要素は、対応するfield_list で宣言されたのと同じ順序でstatic フィールドに対応します。各配列要素の型は、対応するフィールドの宣言された型と一致する必要があります。 static フィールドよりも配列内の要素が少ない場合、残りのフィールドはタイプに適した0 またはnull で初期化されます。 |
call_site_id_item
call_site_ids セクションに表示されます
アラインメント: 4 バイト
名前 | フォーマット | 説明 |
---|---|---|
call_site_off | ユニット | ファイルの先頭から呼び出しサイト定義までのオフセット。オフセットはデータ セクションにある必要があり、そこにあるデータは、以下の「call_site_item」で指定された形式である必要があります。 |
call_site_item
データセクションに表示されます
整列: なし (バイト整列)
call_site_item は、要素がブートストラップ リンカー メソッドに提供される引数に対応する encoded_array_item です。最初の 3 つの引数は次のとおりです。
- ブートストラップ リンカー メソッドを表すメソッド ハンドル (VALUE_METHOD_HANDLE)。
- ブートストラップ リンカーが解決するメソッド名 (VALUE_STRING)。
- 解決するメソッド名の型に対応するメソッド型 (VALUE_METHOD_TYPE)。
追加の引数は、ブートストラップ リンカー メソッドに渡される定数値です。これらの引数は、型変換なしで順番に渡されます。
ブートストラップ リンカー メソッドを表すメソッド ハンドルには、戻り値の型java.lang.invoke.CallSite
が必要です。最初の 3 つのパラメータ タイプは次のとおりです。
-
java.lang.invoke.Lookup
-
java.lang.String
-
java.lang.invoke.MethodType
追加の引数のパラメーターの型は、それらの定数値から決定されます。
method_handle_item
appears in the method_handles section
alignment: 4 bytes
名前 | フォーマット | 説明 |
---|---|---|
method_handle_type | ショート | type of the method handle; see table below |
unused | ショート | (未使用) |
field_or_method_id | ショート | Field or method id depending on whether the method handle type is an accessor or a method invoker |
unused | ショート | (未使用) |
Method Handle Type Codes
Constant | Value | 説明 |
---|---|---|
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)
名前 | フォーマット | 説明 |
---|---|---|
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
名前 | フォーマット | 説明 |
---|---|---|
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
名前 | フォーマット | 説明 |
---|---|---|
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
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ユニット | size of the list, in entries |
list | type_item[size] | elements of the list |
type_item format
名前 | フォーマット | 説明 |
---|---|---|
type_idx | ショート | index into the type_ids list |
code_item
referenced from encoded_method
appears in the data section
alignment: 4 bytes
名前 | フォーマット | 説明 |
---|---|---|
registers_size | ショート | the number of registers used by this code |
ins_size | ショート | the number of words of incoming arguments to the method that this code is for |
outs_size | ショート | the number of words of outgoing argument space required by this code for method invocation |
tries_size | ショート | 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 | ユニット | 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 | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
start_addr | ユニット | 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 | ショート | number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 . |
handler_off | ショート | 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
名前 | フォーマット | 説明 |
---|---|---|
サイズ | 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
名前 | フォーマット | 説明 |
---|---|---|
サイズ | 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
名前 | フォーマット | 説明 |
---|---|---|
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:
名前 | フォーマット | 説明 |
---|---|---|
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:
名前 | Value | フォーマット | 引数 | 説明 |
---|---|---|---|---|
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 localname_idx : string index of the nametype_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 localname_idx : string index of the nametype_idx : type index of the typesig_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 " |
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
名前 | フォーマット | 説明 |
---|---|---|
class_annotations_off | ユニット | 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 | ユニット | count of fields annotated by this item |
annotated_methods_size | ユニット | count of methods annotated by this item |
annotated_parameters_size | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
field_idx | ユニット | index into the field_ids list for the identity of the field being annotated |
annotations_off | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
method_idx | ユニット | index into the method_ids list for the identity of the method being annotated |
annotations_off | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
method_idx | ユニット | index into the method_ids list for the identity of the method whose parameters are being annotated |
annotations_off | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ユニット | size of the list, in entries |
list | annotation_set_ref_item[size] | elements of the list |
annotation_set_ref_item format
名前 | フォーマット | 説明 |
---|---|---|
annotations_off | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ユニット | 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
名前 | フォーマット | 説明 |
---|---|---|
annotation_off | ユニット | 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)
名前 | フォーマット | 説明 |
---|---|---|
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
:
名前 | Value | 説明 |
---|---|---|
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)
名前 | フォーマット | 説明 |
---|---|---|
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 .
名前 | フォーマット | 説明 |
---|---|---|
サイズ | ユニット | 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:
名前 | Value | 説明 |
---|---|---|
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.
名前 | フォーマット | 説明 |
---|---|---|
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.
名前 | フォーマット | 説明 |
---|---|---|
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.
名前 | フォーマット | 説明 |
---|---|---|
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 | 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 | 整数 | 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.)
名前 | フォーマット | 説明 |
---|---|---|
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.
名前 | フォーマット | 説明 |
---|---|---|
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 | 整数[] | 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:
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.
名前 | フォーマット | 説明 |
---|---|---|
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.
名前 | フォーマット | 説明 |
---|---|---|
value | Class[] | the array of exception types thrown |