Dokumen ini menjelaskan tata letak dan konten file .dex
, yang digunakan untuk menampung sekumpulan definisi kelas dan data tambahan terkait.
Panduan untuk tipe
Nama | Deskripsi |
---|---|
byte | 8-bit int |
ubyte | 8-bit unsigned int |
pendek | 16-bit ditandatangani int, little-endian |
ushort | 16-bit unsigned int, little-endian |
int | 32-bit bertanda tangan int, little-endian |
uint | 32-bit unsigned int, little-endian |
panjang | 64-bit bertanda tangan int, little-endian |
ulong | 64-bit unsigned int, little-endian |
sleb128 | LEB128 bertanda tangan, panjang variabel (lihat di bawah) |
uleb128 | LEB128 unsigned, panjang variabel (lihat di bawah) |
uleb128p1 | LEB128 plus 1 unsigned, variabel-panjang (lihat di bawah) |
LEB128
LEB128 (" L ittle- E ndian B ase 128 ") adalah pengkodean dengan panjang variabel untuk jumlah bilangan bulat bertanda tangan atau tidak bertanda tangan sewenang-wenang. Formatnya dipinjam dari spesifikasi DWARF3 . Dalam .dex
berkas, LEB128 hanya pernah digunakan untuk encode jumlah 32-bit.
Setiap nilai yang dikodekan LEB128 terdiri dari satu hingga lima byte, yang bersama-sama mewakili satu nilai 32-bit. Setiap byte memiliki kumpulan bit paling signifikannya kecuali untuk byte terakhir dalam urutan, yang memiliki bit paling signifikan jelasnya. Tujuh bit yang tersisa dari setiap byte adalah payload, dengan tujuh bit paling tidak signifikan dari kuantitas pada byte pertama, tujuh bit berikutnya pada byte kedua dan seterusnya. Dalam kasus LEB128 bertanda ( sleb128
), bit muatan paling signifikan dari byte akhir dalam urutan adalah perluasan tanda untuk menghasilkan nilai akhir. Dalam kasus unsigned ( uleb128
), bit apa pun yang tidak direpresentasikan secara eksplisit diartikan sebagai 0
.
Diagram bitwise dari nilai LEB128 dua byte | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Byte pertama | Byte kedua | ||||||||||||||
1 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | 0 | bit 13 | bit 12 | bit 11 | bit 10 | bit 9 | bit 8 | bit 7 |
Varian uleb128p1
digunakan untuk mewakili nilai bertanda, dengan representasi dari nilai plus satu yang dikodekan sebagai uleb128
. Ini membuat pengkodean -1
(sebagai alternatif dianggap sebagai nilai unsigned 0xffffffff
) - tetapi tidak ada angka negatif lainnya - satu byte, dan berguna dalam kasus-kasus di mana angka yang diwakili harus baik non-negatif atau -1
(atau 0xffffffff
), dan di mana tidak ada nilai negatif lain yang diperbolehkan (atau di mana nilai unsigned yang besar kemungkinan tidak diperlukan).
Berikut beberapa contoh formatnya:
Urutan Tersandi | Sebagai sleb128 | Sebagai uleb128 | Sebagai uleb128p1 |
---|---|---|---|
00 | 0 | 0 | -1 |
01 | 1 | 1 | 0 |
7f | -1 | 127 | 126 |
80 7f | -128 | 16256 | 16255 |
Tata letak file
Nama | Format | Deskripsi |
---|---|---|
header | header_item | header |
string_id | string_id_item [] | daftar pengenal string. Ini adalah pengidentifikasi untuk semua string yang digunakan oleh file ini, baik untuk penamaan internal (misalnya, deskriptor tipe) atau sebagai objek konstan yang dirujuk oleh kode. Daftar ini harus diurutkan berdasarkan konten string, menggunakan nilai poin kode UTF-16 (bukan dengan cara yang sensitif terhadap lokal), dan tidak boleh berisi entri duplikat. |
type_ids | type_id_item [] | ketik daftar pengenal. Ini adalah pengenal untuk semua jenis (kelas, larik, atau jenis primitif) yang dirujuk oleh file ini, baik ditentukan dalam file atau tidak. Daftar ini harus diurutkan berdasarkan indeks string_id , dan tidak boleh berisi entri duplikat. |
proto_id | proto_id_item [] | metode daftar pengidentifikasi prototipe. Ini adalah pengenal untuk semua prototipe yang dirujuk oleh file ini. Daftar ini harus diurutkan dalam urutan utama tipe-balik (menurut indeks type_id ), dan kemudian menurut daftar argumen (pengurutan leksikografik, masing-masing argumen diurutkan berdasarkan indeks type_id ). Daftar tidak boleh berisi entri duplikat. |
field_id | field_id_item [] | daftar pengidentifikasi bidang. Ini adalah pengidentifikasi untuk semua bidang yang dirujuk oleh file ini, baik ditentukan dalam file atau tidak. Daftar ini harus diurutkan, di mana jenis yang menentukan (menurut indeks type_id ) adalah urutan utama, nama bidang (menurut indeks string_id ) adalah urutan perantara, dan jenis (menurut indeks type_id ) adalah urutan minor. Daftar tidak boleh berisi entri duplikat. |
method_ids | method_id_item [] | daftar pengidentifikasi metode. Ini adalah pengidentifikasi untuk semua metode yang dirujuk oleh file ini, baik ditentukan dalam file atau tidak. Daftar ini harus diurutkan, di mana jenis yang menentukan (menurut indeks type_id ) adalah urutan utama, nama metode (menurut indeks string_id ) adalah urutan perantara, dan prototipe metode (menurut indeks proto_id ) adalah urutan minor. Daftar tidak boleh berisi entri duplikat. |
class_defs | class_def_item [] | daftar definisi kelas. Kelas-kelas harus diurutkan sedemikian rupa sehingga kelas super dan antarmuka yang diimplementasikan muncul dalam daftar lebih awal dari kelas pengarah. Selain itu, tidak valid untuk definisi kelas dengan nama yang sama muncul lebih dari sekali dalam daftar. |
call_site_ids | call_site_id_item [] | panggil daftar pengenal situs. Ini adalah pengidentifikasi untuk semua situs panggilan yang dirujuk oleh file ini, baik ditentukan dalam file atau tidak. Daftar ini harus diurutkan dalam urutan menaik call_site_off . |
method_handles | method_handle_item [] | metode menangani daftar. Daftar semua tuas metode yang dirujuk oleh file ini, baik ditentukan dalam file atau tidak. Daftar ini tidak diurutkan dan mungkin berisi duplikat yang secara logis akan sesuai dengan contoh penanganan metode yang berbeda. |
data | ubyte [] | area data, yang berisi semua data pendukung untuk tabel yang tercantum di atas. Item yang berbeda memiliki persyaratan penyelarasan yang berbeda, dan byte padding disisipkan sebelum setiap item jika perlu untuk mencapai keselarasan yang tepat. |
link_data | ubyte [] | data yang digunakan dalam file yang ditautkan secara statis. Format data di bagian ini tidak ditentukan oleh dokumen ini. Bagian ini kosong dalam file yang tidak ditautkan, dan implementasi runtime dapat menggunakannya sesuai keinginan. |
Bitfield, string, dan definisi konstan
DEX_FILE_MAGIC
tertanam di header_item
Array / string konstan DEX_FILE_MAGIC
adalah daftar byte yang harus muncul di awal file .dex
agar bisa dikenali. Nilai sengaja berisi baris baru ( "\n"
atau 0x0a
) dan byte nol ( "\0"
atau 0x00
) untuk membantu dalam mendeteksi bentuk korupsi tertentu. Nilai juga menyandikan nomor versi format sebagai tiga digit desimal, yang diharapkan meningkat secara monoton seiring waktu seiring perkembangan format.
ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x39 0x00 } = "dex\n039\0"
Catatan: Dukungan untuk format versi 039
telah ditambahkan dalam rilis Android 9.0, yang memperkenalkan dua bytecode baru, const-method-handle
dan const-method-type
. (Masing-masing dijelaskan dalam Ringkasan tabel kumpulan bytecode .) Di Android 10, versi 039
memperluas format file DEX untuk menyertakan informasi API tersembunyi yang hanya berlaku untuk file DEX di jalur kelas boot.
Catatan: Dukungan untuk versi 038
format telah ditambahkan di rilis Android 8.0. Versi 038
menambahkan bytecode baru ( invoke-polymorphic
dan invoke-custom
) dan data untuk pegangan metode.
Catatan: Dukungan untuk versi 037
dari format tersebut telah ditambahkan di rilis Android 7.0. Sebelum versi 037
sebagian besar versi Android telah menggunakan format versi 035
. Satu-satunya perbedaan antara versi 035
dan 037
adalah penambahan metode default dan penyesuaian invoke
.
Catatan: Setidaknya beberapa versi sebelumnya dari format tersebut telah digunakan dalam rilis perangkat lunak publik yang tersedia secara luas. Misalnya, versi 009
digunakan untuk rilis M3 platform Android (November – Desember 2007), dan versi 013
digunakan untuk rilis M5 platform Android (Februari – Maret 2008). Dalam beberapa hal, versi format sebelumnya ini berbeda secara signifikan dari versi yang dijelaskan dalam dokumen ini.
ENDIAN_CONSTANT dan REVERSE_ENDIAN_CONSTANT
tertanam di header_item
Konstanta ENDIAN_CONSTANT
digunakan untuk menunjukkan endian dari file di mana ia ditemukan. Meskipun format .dex
standar adalah little-endian, implementasi dapat memilih untuk melakukan pertukaran byte. Jika sebuah implementasi menemukan sebuah header yang endian_tag
- endian_tag
REVERSE_ENDIAN_CONSTANT
bukan ENDIAN_CONSTANT
, itu akan mengetahui bahwa file telah ditukar byte dari bentuk yang diharapkan.
uint ENDIAN_CONSTANT = 0x12345678; uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
tertanam dalam class_def_item dan debug_info_item
NO_INDEX
konstan digunakan untuk menunjukkan bahwa nilai indeks tidak ada.
Catatan: Nilai ini tidak didefinisikan sebagai 0
, karena biasanya itu adalah indeks yang valid.
Nilai yang dipilih untuk NO_INDEX
dapat direpresentasikan sebagai byte tunggal dalam pengkodean uleb128p1
.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
definisi access_flags
tertanam di class_def_item, encoded_field, encoded_method, dan InnerClass
Bitfields dari flag ini digunakan untuk menunjukkan aksesibilitas dan properti keseluruhan dari kelas dan anggota kelas.
Nama | Nilai | Untuk Kelas (dan anotasi Kelas InnerClass ) | Untuk Fields | Untuk Metode |
---|---|---|---|---|
ACC_PUBLIC | 0x1 | public : terlihat di mana-mana | public : terlihat di mana-mana | public : terlihat di mana-mana |
ACC_PRIVATE | 0x2 | private : hanya dapat dilihat oleh kelas yang menentukan | private : hanya dapat dilihat oleh kelas yang ditentukan | private : hanya dapat dilihat oleh kelas yang menentukan |
DIPERLINDUNGI | 0x4 | protected : terlihat oleh paket dan subkelas | protected : terlihat oleh paket dan subkelas | protected : terlihat oleh paket dan subkelas |
ACC_STATIC | 0x8 | static : tidak dibuat dengan bagian luar referensi this | static : global untuk menentukan kelas | static : tidak mengambil argumen this |
ACC_FINAL | 0x10 | final : tidak dapat disubkelas | final : tidak dapat diubah setelah konstruksi | final : tidak dapat diganti |
ACC_SYNCHRONIZED | 0x20 | synchronized : kunci terkait secara otomatis diperoleh sekitar panggilan ke metode ini. Catatan: Ini hanya valid untuk disetel jika | ||
ACC_VOLATILE | 0x40 | volatile : aturan akses khusus untuk membantu keamanan thread | ||
ACC_BRIDGE | 0x40 | metode jembatan, ditambahkan secara otomatis oleh kompiler sebagai jembatan tipe-aman | ||
ACC_TRANSIENT | 0x80 | transient : tidak akan disimpan dengan serialisasi default | ||
ACC_VARG | 0x80 | Argumen terakhir harus diperlakukan sebagai argumen "istirahat" oleh kompilator | ||
ACC_NATIVE | 0x100 | native : diimplementasikan dalam kode native | ||
ACC_INTERFACE | 0x200 | interface : kelas abstrak multiply-implementable | ||
ACC_ABSTRACT | 0x400 | abstract : tidak dapat langsung dipakai | abstract : tidak diterapkan oleh kelas ini | |
ACC_STRICT | 0x800 | strictfp : aturan ketat untuk aritmatika floating-point | ||
ACC_SYNTHETIC | 0x1000 | tidak secara langsung didefinisikan dalam kode sumber | tidak secara langsung didefinisikan dalam kode sumber | tidak secara langsung didefinisikan dalam kode sumber |
ACC_ANNOTATION | 0x2000 | dideklarasikan sebagai kelas anotasi | ||
ACC_ENUM | 0x4000 | dinyatakan sebagai tipe yang dicacah | dinyatakan sebagai nilai yang disebutkan | |
(tidak digunakan) | 0x8000 | |||
ACC_CONSTRUCTOR | 0x10000 | metode konstruktor (penginisialisasi kelas atau instance) | ||
ACC_DECLARED_ DISINKRONKAN | 0x20000 | dinyatakan synchronized .Catatan: Ini tidak berpengaruh pada eksekusi (selain sebagai refleksi dari flag ini, per se). |
InnerClass
, dan tidak boleh aktif dalam class_def_item
.
Pengkodean MUTF-8 (Modifikasi UTF-8)
Sebagai konsesi untuk memudahkan dukungan warisan, format .dex
mengkodekan data stringnya dalam bentuk UTF-8 yang dimodifikasi standar de facto, selanjutnya disebut sebagai MUTF-8. Formulir ini identik dengan standar UTF-8, kecuali:
- Hanya pengkodean satu, dua, dan tiga byte yang digunakan.
- Titik kode dalam rentang
U+10000
…U+10ffff
dikodekan sebagai pasangan pengganti, yang masing-masing direpresentasikan sebagai nilai yang dikodekan tiga byte. - Titik kode
U+0000
dikodekan dalam bentuk dua byte. - Byte kosong polos (nilai
0
) menunjukkan akhir string, seperti interpretasi bahasa C standar.
Dua item pertama di atas dapat diringkas sebagai: MUTF-8 adalah format pengkodean untuk UTF-16, alih-alih menjadi format pengkodean yang lebih langsung untuk karakter Unicode.
Dua item terakhir di atas memungkinkan untuk secara bersamaan menyertakan titik kode U+0000
dalam sebuah string dan masih memanipulasinya sebagai string diakhiri dengan gaya-C.
Namun, pengkodean khusus U+0000
berarti bahwa, tidak seperti UTF-8 normal, hasil pemanggilan fungsi standar C strcmp()
pada sepasang string MUTF-8 tidak selalu menunjukkan hasil yang ditandatangani dengan benar dari perbandingan string yang tidak sama . Ketika memesan (bukan hanya kesetaraan) menjadi perhatian, cara paling mudah untuk membandingkan string MUTF-8 adalah dengan mendekodekannya karakter demi karakter, dan membandingkan nilai yang didekodekan. (Namun, implementasi yang lebih cerdas juga dimungkinkan.)
Silakan merujuk ke Standar Unicode untuk informasi lebih lanjut tentang pengkodean karakter. MUTF-8 sebenarnya lebih dekat dengan pengkodean CESU-8 (yang relatif kurang terkenal) daripada UTF-8 per se.
encoded_value encoding
tertanam dalam annotation_element dan encoded_array_item
encoded_value
adalah bagian yang dienkode dari (hampir) data yang terstruktur secara hierarki. Pengkodean dimaksudkan agar ringkas dan langsung dapat diurai.
Nama | Format | Deskripsi |
---|---|---|
(nilai_arg << 5) | value_type | ubyte | byte menunjukkan jenis segera selanjutnya value bersama dengan mengklarifikasi argumen opsional dalam tinggi-order tiga bit. Lihat di bawah untuk berbagai definisi value . Dalam kebanyakan kasus, value_arg mengkodekan panjang segera-berikutnya value dalam byte, seperti (size - 1) , misalnya, 0 berarti bahwa nilai memerlukan satu byte, dan 7 berarti membutuhkan delapan byte; Namun, ada pengecualian seperti yang disebutkan di bawah ini. |
nilai | ubyte [] | byte yang mewakili nilai, panjang variabel dan diinterpretasikan secara berbeda untuk byte value_type berbeda, meskipun selalu little-endian. Lihat berbagai definisi nilai di bawah untuk detailnya. |
Format nilai
Ketik nama | value_type | Format value_arg | Format value | Deskripsi |
---|---|---|---|---|
VALUE_BYTE | 0x00 | (tidak ada; harus 0 ) | ubyte [1] | nilai integer satu byte yang ditandatangani |
VALUE_SHORT | 0x02 | ukuran - 1 (0… 1) | ubyte [size] | menandatangani nilai integer dua byte, sign-extended |
VALUE_CHAR | 0x03 | ukuran - 1 (0… 1) | ubyte [size] | unsigned dua-byte integer value, zero-extended |
VALUE_INT | 0x04 | ukuran - 1 (0… 3) | ubyte [size] | menandatangani nilai integer empat-byte, sign-extended |
VALUE_LONG | 0x06 | ukuran - 1 (0… 7) | ubyte [size] | nilai integer delapan byte yang ditandatangani, sign-extended |
VALUE_FLOAT | 0x10 | ukuran - 1 (0… 3) | ubyte [size] | pola bit empat-byte, nol-diperpanjang ke kanan , dan ditafsirkan sebagai nilai titik mengambang IEEE754 32-bit |
VALUE_DOUBLE | 0x11 | ukuran - 1 (0… 7) | ubyte [size] | pola bit delapan-byte, nol-diperpanjang ke kanan , dan ditafsirkan sebagai nilai titik mengambang 64-bit IEEE754 |
VALUE_METHOD_TYPE | 0x15 | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke dalam bagian proto_ids dan mewakili nilai jenis metode |
VALUE_METHOD_HANDLE | 0x16 | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke dalam bagian method_handles dan mewakili nilai penanganan metode |
VALUE_STRING | 0x17 | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke bagian string_ids dan mewakili nilai string |
VALUE_TYPE | 0x18 | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke dalam bagian type_ids dan mewakili tipe reflektif / nilai kelas |
VALUE_FIELD | 0x19 | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke dalam bagian field_ids dan mewakili nilai bidang reflektif |
VALUE_METHOD | 0x1a | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, ditafsirkan sebagai indeks ke bagian method_ids dan mewakili nilai metode reflektif |
VALUE_ENUM | 0x1b | ukuran - 1 (0… 3) | ubyte [size] | unsigned (zero-extended) empat-byte nilai integer, diinterpretasikan sebagai indeks ke bagian field_ids dan mewakili nilai konstanta tipe enumerasi |
VALUE_ARRAY | 0x1c | (tidak ada; harus 0 ) | encoded_array | larik nilai, dalam format yang ditentukan oleh "format encoded_array " di bawah. Ukuran value tersirat dalam pengkodean. |
VALUE_ANNOTATION | 0x1d | (tidak ada; harus 0 ) | encoded_annotation | sub-anotasi, dalam format yang ditentukan oleh "format encoded_annotation " di bawah. Ukuran value tersirat dalam pengkodean. |
VALUE_NULL | 0x1e | (tidak ada; harus 0 ) | (tidak ada) | nilai referensi null |
VALUE_BOOLEAN | 0x1f | boolean (0… 1) | (tidak ada) | nilai satu-bit; 0 untuk false dan 1 untuk true . Bit direpresentasikan dalam value_arg . |
format encoded_array
Nama | Format | Deskripsi |
---|---|---|
ukuran | uleb128 | jumlah elemen dalam array |
nilai-nilai | encoded_value [size] | serangkaian size urutan byte encoded_value dalam format yang ditentukan oleh bagian ini, digabungkan secara berurutan. |
encoded_annotation format
Nama | Format | Deskripsi |
---|---|---|
type_idx | uleb128 | jenis anotasi. Ini harus berupa tipe kelas (bukan array atau primitif). |
ukuran | uleb128 | jumlah pemetaan nama-nilai dalam anotasi ini |
elemen | annotation_element [size] | elemen anotasi, direpresentasikan langsung dalam baris (bukan sebagai offset). Elemen harus diurutkan dalam urutan meningkat berdasarkan indeks string_id . |
format annotation_element
Nama | Format | Deskripsi |
---|---|---|
name_idx | uleb128 | nama elemen, direpresentasikan sebagai indeks ke dalam bagian string_ids . String harus sesuai dengan sintaks MemberName , yang ditentukan di atas. |
nilai | encoded_value | nilai elemen |
Sintaks string
Ada beberapa jenis item dalam file .dex
yang pada akhirnya merujuk ke sebuah string. Definisi gaya BNF berikut menunjukkan sintaks yang dapat diterima untuk string ini.
SimpleName
SimpleName adalah dasar untuk sintaks nama hal lain. Format .dex
memungkinkan cukup banyak lintang di sini (jauh lebih banyak daripada bahasa sumber yang paling umum). Singkatnya, nama sederhana terdiri dari karakter atau digit alfabet ASCII rendah, beberapa simbol ASCII rendah tertentu, dan sebagian besar titik kode non-ASCII yang bukan kontrol, spasi, atau karakter khusus. Mulai dari versi 040
format tambahan memungkinkan karakter spasi (kategori Unicode Zs
). Perhatikan bahwa poin kode pengganti (dalam kisaran U+d800
... U+dfff
) tidak dianggap karakter nama yang valid, per se, tetapi karakter Unicode tambahan berlaku (yang diwakili oleh alternatif akhir dari aturan untuk SimpleNameChar), dan mereka harus direpresentasikan dalam file sebagai pasangan titik kode pengganti dalam pengkodean MUTF-8.
SimpleName → | ||
SimpleNameChar ( SimpleNameChar ) * | ||
SimpleNameChar → | ||
'A' … 'Z' | ||
| | 'a' … 'z' | |
| | '0' ... '9' | |
| | ' ' | sejak DEX versi 040 |
| | '$' | |
| | '-' | |
| | '_' | |
| | U+00a0 | sejak DEX versi 040 |
| | U+00a1 … U+1fff | |
| | U+2000 … U+200a | sejak DEX versi 040 |
| | U+2010 … U+2027 | |
| | U+202f | sejak DEX versi 040 |
| | U+2030 … U+d7ff | |
| | U+e000 … U+ffef | |
| | U+10000 … U+10ffff |
Nama anggota
digunakan oleh field_id_item dan method_id_item
MemberName adalah nama anggota kelas, bidang anggota, metode, dan kelas dalam.
MemberName → | |
SimpleName | |
| | '<' SimpleName '>' |
FullClassName
FullClassName adalah nama kelas yang sepenuhnya memenuhi syarat, termasuk penentu paket opsional diikuti dengan nama yang diperlukan.
FullClassName → | |
OpsionalPackagePrefix SimpleName | |
OpsionalPackagePrefix → | |
( SimpleName '/' ) * |
TypeDescriptor
digunakan oleh type_id_item
TypeDescriptor adalah representasi dari semua jenis, termasuk primitif, kelas, array, dan void
. Lihat di bawah untuk arti dari berbagai versi.
TypeDescriptor → | |
'V' | |
| | FieldTypeDescriptor |
FieldTypeDescriptor → | |
NonArrayFieldTypeDescriptor | |
| | ( '[' * 1… 255) NonArrayFieldTypeDescriptor |
NonArrayFieldTypeDescriptor → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' FullClassName ';' |
ShortyDescriptor
digunakan oleh proto_id_item
ShortyDescriptor adalah representasi bentuk singkat dari prototipe metode, termasuk tipe parameter dan kembalian, kecuali tidak ada perbedaan antara berbagai tipe referensi (kelas atau larik). Sebaliknya, semua jenis referensi diwakili oleh satu karakter 'L'
.
ShortyDescriptor → | |
ShortyReturnType ( ShortyFieldType ) * | |
ShortyReturnType → | |
'V' | |
| | ShortyFieldType |
ShortyFieldType → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' |
TypeDescriptor Semantics
Ini adalah arti dari setiap varian TypeDescriptor .
Sintaksis | Berarti |
---|---|
V. | void ; hanya berlaku untuk tipe pengembalian |
Z | boolean |
B | byte |
S | short |
C | char |
saya | int |
J | long |
F | float |
D | double |
L sepenuhnya / memenuhi syarat / Nama ; | kelas fully.qualified.Name |
[ keterangan | array descriptor , dapat digunakan secara rekursif untuk array-of-array, meskipun tidak valid untuk memiliki lebih dari 255 dimensi. |
Item dan struktur terkait
Bagian ini menyertakan definisi untuk setiap item level teratas yang mungkin muncul dalam file .dex
.
header_item
muncul di bagian tajuk
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
sihir | ubyte [8] = DEX_FILE_MAGIC | nilai ajaib. Lihat diskusi di atas di bawah " DEX_FILE_MAGIC " untuk lebih jelasnya. |
checksum | uint | adler32 checksum dari sisa file (semuanya kecuali magic dan bidang ini); digunakan untuk mendeteksi kerusakan file |
tanda tangan | ubyte [20] | SHA-1 signature (hash) dari sisa file (semuanya kecuali magic , checksum , dan field ini); digunakan untuk mengidentifikasi file secara unik |
ukuran file | uint | ukuran seluruh file (termasuk header), dalam byte |
header_size | uint = 0x70 | ukuran tajuk (seluruh bagian ini), dalam byte. Hal ini memungkinkan setidaknya sejumlah kompatibilitas mundur / maju tanpa membatalkan format. |
endian_tag | uint = ENDIAN_CONSTANT | tag endianness. Lihat diskusi di atas di bawah " ENDIAN_CONSTANT dan REVERSE_ENDIAN_CONSTANT " untuk detail selengkapnya. |
link_size | uint | ukuran bagian tautan, atau 0 jika file ini tidak ditautkan secara statis |
link_off | uint | offset dari awal file ke bagian link, atau 0 jika link_size == 0 . Offset, jika bukan nol, harus menjadi offset ke bagian link_data . Format data yang ditunjukkan tidak ditentukan oleh dokumen ini; kolom header ini (dan sebelumnya) dibiarkan sebagai kait untuk digunakan oleh implementasi runtime. |
map_off | uint | offset dari awal file ke item peta. Offset, yang tidak boleh nol, harus menjadi offset ke bagian data , dan data harus dalam format yang ditentukan oleh " map_list " di bawah. |
string_ids_size | uint | jumlah string dalam daftar pengenal string |
string_ids_off | uint | offset dari awal file ke daftar pengenal string, atau 0 jika string_ids_size == 0 (memang kasus tepi yang aneh). Offset, jika bukan nol, harus di awal bagian string_ids . |
type_ids_size | uint | jumlah elemen dalam daftar pengenal tipe, paling banyak 65535 |
type_ids_off | uint | offset dari awal file ke daftar pengenal tipe, atau 0 jika type_ids_size == 0 (memang kasus tepi yang aneh). Offset, jika bukan nol, harus di awal bagian type_ids . |
proto_ids_size | uint | jumlah elemen dalam daftar pengenal prototipe, paling banyak 65535 |
proto_ids_off | uint | offset dari awal file ke daftar pengidentifikasi prototipe, atau 0 jika proto_ids_size == 0 (memang kasus tepi yang aneh). Offset, jika bukan nol, harus di awal bagian proto_ids . |
field_ids_size | uint | jumlah elemen dalam daftar pengidentifikasi bidang |
field_ids_off | uint | offset dari awal file ke daftar pengidentifikasi bidang, atau 0 jika field_ids_size == 0 . Offset, jika bukan nol, harus di awal bagian field_ids . |
method_ids_size | uint | jumlah elemen dalam daftar pengidentifikasi metode |
method_ids_off | uint | offset dari awal file ke daftar pengenal metode, atau 0 jika method_ids_size == 0 . Offset, jika bukan nol, harus di awal bagian method_ids . |
class_defs_size | uint | jumlah elemen dalam daftar definisi kelas |
class_defs_off | uint | offset dari awal file ke daftar definisi kelas, atau 0 jika class_defs_size == 0 (memang kasus tepi yang aneh). class_defs , jika bukan nol, harus di awal bagian class_defs . |
data_size | uint | Ukuran bagian data dalam byte. Harus merupakan kelipatan dari sizeof (uint). |
data_off | uint | offset dari awal file hingga awal bagian data . |
map_list
muncul di bagian data
direferensikan dari header_item
perataan: 4 byte
Ini adalah daftar seluruh konten file, secara berurutan. Ini berisi beberapa redundansi sehubungan dengan header_item
tetapi dimaksudkan untuk menjadi bentuk yang mudah digunakan untuk mengulangi seluruh file. Jenis tertentu harus muncul paling banyak sekali dalam peta, tetapi tidak ada batasan tentang jenis urutan apa yang dapat muncul, selain pembatasan yang tersirat oleh format lainnya (misalnya, bagian header
harus muncul terlebih dahulu, diikuti oleh string_ids
bagian, dll.). Selain itu, entri peta harus diurutkan berdasarkan offset awal dan tidak boleh tumpang tindih.
Nama | Format | Deskripsi |
---|---|---|
ukuran | uint | ukuran daftar, dalam entri |
daftar | map_item [size] | elemen dari daftar |
format map_item
Nama | Format | Deskripsi |
---|---|---|
Tipe | ushort | jenis barang; lihat tabel di bawah |
tidak terpakai | ushort | (tidak digunakan) |
ukuran | uint | hitungan jumlah item yang dapat ditemukan di offset yang ditunjukkan |
mengimbangi | uint | offset dari awal file ke item yang dimaksud |
Ketik Kode
Tipe barang | Konstan | Nilai | Ukuran Item Dalam Bytes |
---|---|---|---|
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 + (ukuran.item * 12) |
type_list | TYPE_TYPE_LIST | 0x1001 | 4 + (ukuran.item * 2) |
annotation_set_ref_list | TYPE_ANNOTATION_SET_REF_LIST | 0x1002 | 4 + (ukuran.item * 4) |
annotation_set_item | TYPE_ANNOTATION_SET_ITEM | 0x1003 | 4 + (ukuran.item * 4) |
class_data_item | TYPE_CLASS_DATA_ITEM | 0x2000 | implisit; harus mengurai |
code_item | TYPE_CODE_ITEM | 0x2001 | implisit; harus mengurai |
string_data_item | TYPE_STRING_DATA_ITEM | 0x2002 | implisit; harus mengurai |
debug_info_item | TYPE_DEBUG_INFO_ITEM | 0x2003 | implisit; harus mengurai |
annotation_item | TYPE_ANNOTATION_ITEM | 0x2004 | implisit; harus mengurai |
encoded_array_item | TYPE_ENCODED_ARRAY_ITEM | 0x2005 | implisit; harus mengurai |
annotations_directory_item | TYPE_ANNOTATIONS_DIRECTORY_ITEM | 0x2006 | implisit; harus mengurai |
hiddenapi_class_data_item | TYPE_HIDDENAPI_CLASS_DATA_ITEM | 0xF000 | implisit; harus mengurai |
string_id_item
muncul di bagian string_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
string_data_off | uint | offset dari awal file ke data string untuk item ini. Offset harus ke lokasi di bagian data , dan data harus dalam format yang ditentukan oleh " string_data_item " di bawah ini. Tidak ada persyaratan penyelarasan untuk offset. |
string_data_item
muncul di bagian data
perataan: tidak ada (rata-byte)
Nama | Format | Deskripsi |
---|---|---|
utf16_size | uleb128 | ukuran string ini, dalam unit kode UTF-16 (yang merupakan "panjang string" di banyak sistem). Artinya, ini adalah panjang string yang didekodekan. (Panjang yang disandikan tersirat oleh posisi 0 byte.) |
data | ubyte [] | serangkaian unit kode MUTF-8 (alias oktet, alias byte) diikuti oleh byte bernilai 0 . Lihat "Pengkodean MUTF-8 (UTF-8 yang Dimodifikasi)" di atas untuk detail dan diskusi tentang format data. Catatan: Ini dapat diterima untuk memiliki string yang menyertakan (bentuk yang dikodekan) unit kode pengganti UTF-16 (yaitu, |
type_id_item
muncul di bagian type_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
deskriptor_idx | uint | indeks ke dalam daftar string_ids untuk deskripsi string jenis ini. String harus sesuai dengan sintaks untuk TypeDescriptor , yang ditentukan di atas. |
proto_id_item
muncul di bagian proto_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
shorty_idx | uint | indeks ke dalam daftar string_ids untuk string deskriptor bentuk pendek dari prototipe ini. String harus sesuai dengan sintaks untuk ShortyDescriptor , yang ditentukan di atas, dan harus sesuai dengan jenis kembalian dan parameter item ini. |
return_type_idx | uint | indeks ke dalam daftar type_ids untuk tipe kembalian dari prototipe ini |
parameter_off | uint | offset dari awal file ke daftar tipe parameter untuk prototipe ini, atau 0 jika prototipe ini tidak memiliki parameter. Offset ini, jika bukan nol, harus ada di bagian data , dan data di sana harus dalam format yang ditentukan oleh "type_list" bawah. Selain itu, tidak boleh ada referensi ke tipe void dalam daftar. |
field_id_item
muncul di bagian field_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
class_idx | ushort | indeks ke dalam daftar type_ids untuk definisi bidang ini. Ini harus tipe kelas, dan bukan tipe larik atau primitif. |
type_idx | ushort | indeks ke dalam daftar type_ids untuk jenis bidang ini |
name_idx | uint | indeks ke dalam daftar string_ids untuk nama bidang ini. String harus sesuai dengan sintaks MemberName , yang ditentukan di atas. |
method_id_item
muncul di bagian method_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
class_idx | ushort | indeks ke dalam daftar type_ids untuk type_ids metode ini. Ini harus berupa kelas atau tipe larik, dan bukan tipe primitif. |
proto_idx | ushort | indeks ke dalam daftar proto_ids untuk prototipe metode ini |
name_idx | uint | indeks ke dalam daftar string_ids untuk nama metode ini. String harus sesuai dengan sintaks MemberName , yang ditentukan di atas. |
class_def_item
muncul di bagian class_defs
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
class_idx | uint | indeks ke dalam daftar type_ids untuk kelas ini. Ini harus tipe kelas, dan bukan tipe larik atau primitif. |
access_flags | uint | tanda akses untuk kelas ( public , final , dll.). Lihat "Definisi access_flags " untuk detailnya. |
superclass_idx | uint | indeks ke dalam daftar type_ids untuk superclass, atau nilai konstan NO_INDEX jika kelas ini tidak memiliki superclass (yaitu, itu adalah kelas root seperti Object ). Jika ada, ini harus tipe kelas, dan bukan tipe larik atau primitif. |
interfaces_off | uint | offset dari awal file ke daftar antarmuka, atau 0 jika tidak ada. Offset ini harus ada di bagian data , dan data di sana harus dalam format yang ditentukan oleh " type_list " di bawah. Setiap elemen dari daftar harus berjenis kelas (bukan jenis larik atau primitif), dan tidak boleh ada duplikat. |
source_file_idx | uint | indeks ke dalam daftar string_ids untuk nama file yang berisi sumber asli untuk (setidaknya sebagian besar) kelas ini, atau nilai khusus NO_INDEX untuk menunjukkan kurangnya informasi ini. debug_info_item dari metode apa pun yang diberikan dapat menimpa file sumber ini, tetapi harapannya adalah bahwa sebagian besar kelas hanya akan datang dari satu file sumber. |
annotations_off | uint | offset dari awal file ke struktur anotasi untuk kelas ini, atau 0 jika tidak ada anotasi pada kelas ini. Offset ini, jika bukan nol, harus ada di bagian data , dan data di sana harus dalam format yang ditentukan oleh " annotations_directory_item " di bawah ini, dengan semua item merujuk ke kelas ini sebagai definisinya. |
class_data_off | uint | offset dari awal file ke data kelas terkait untuk item ini, atau 0 jika tidak ada data kelas untuk kelas ini. (Ini mungkin kasusnya, misalnya, jika kelas ini adalah antarmuka marker.) Offset, jika bukan nol, harus ada di bagian data , dan data di sana harus dalam format yang ditentukan oleh " class_data_item " di bawah, dengan semua item mengacu pada kelas ini sebagai definisi. |
static_values_off | uint | offset dari awal file ke daftar nilai awal untuk bidang static , atau 0 jika tidak ada (dan semua bidang static akan diinisialisasi dengan 0 atau null ). Offset ini harus berada di bagian data , dan data di sana harus dalam format yang ditentukan oleh " encoded_array_item " di bawah. Ukuran larik tidak boleh lebih besar dari jumlah bidang static dideklarasikan oleh kelas ini, dan elemen yang sesuai dengan bidang static dalam urutan yang sama seperti yang dideklarasikan dalam field_list terkait. Jenis setiap elemen larik harus cocok dengan jenis yang dideklarasikan dari bidang terkait. Jika ada lebih sedikit elemen dalam larik daripada jumlah bidang static , maka bidang yang tersisa diinisialisasi dengan 0 atau null sesuai untuk tipe. |
call_site_id_item
muncul di bagian call_site_ids
perataan: 4 byte
Nama | Format | Deskripsi |
---|---|---|
call_site_off | uint | offset dari awal file untuk memanggil definisi situs. Offset harus ada di bagian data, dan datanya harus dalam format yang ditentukan oleh "call_site_item" di bawah. |
call_site_item
muncul di bagian data
perataan: tidak ada (selaras byte)
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:
- A method handle representing the bootstrap linker method (VALUE_METHOD_HANDLE).
- A method name that the bootstrap linker should resolve (VALUE_STRING).
- 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:
-
java.lang.invoke.Lookup
-
java.lang.String
-
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 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
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:
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 |