Dieses Dokument beschreibt das Layout und den Inhalt von .dex
Dateien, die verwendet werden, um eine Reihe von Klassendefinitionen und ihre zugehörigen Zusatzdaten zu speichern.
Leitfaden für Typen
Name | Beschreibung |
---|---|
Byte | 8-Bit-Int mit Vorzeichen |
Ubyte | 8-Bit-Ganzzahl ohne Vorzeichen |
kurz | 16-Bit-Int mit Vorzeichen, Little-Endian |
ukurz | 16-Bit unsigned int, Little-Endian |
int | 32-Bit-Int mit Vorzeichen, Little-Endian |
uint | 32-Bit unsigned int, Little-Endian |
lang | 64-Bit-Int mit Vorzeichen, Little-Endian |
lang | 64-Bit unsigned int, Little-Endian |
sleb128 | signiert LEB128, variable Länge (siehe unten) |
uleb128 | unsigned LEB128, variable Länge (siehe unten) |
uleb128p1 | unsigned LEB128 plus 1 , variable Länge (siehe unten) |
LEB128
LEB128 ("Little- E ndian Base 128 ") ist eine Codierung mit variabler Länge für beliebige vorzeichenbehaftete oder vorzeichenlose ganzzahlige Größen. Das Format wurde der DWARF3- Spezifikation entlehnt. In einer .dex
Datei wird LEB128 immer nur zum Codieren von 32-Bit-Mengen verwendet.
Jeder LEB128-codierte Wert besteht aus einem bis fünf Bytes, die zusammen einen einzelnen 32-Bit-Wert darstellen. Jedes Byte hat sein höchstwertiges Bit gesetzt, mit Ausnahme des letzten Bytes in der Sequenz, dessen höchstwertiges Bit gelöscht ist. Die verbleibenden sieben Bits jedes Bytes sind Nutzdaten, wobei die niederwertigsten sieben Bits der Menge im ersten Byte, die nächsten sieben im zweiten Byte und so weiter stehen. Im Fall eines vorzeichenbehafteten LEB128 ( sleb128
) wird das höchstwertige Nutzdatenbit des letzten Bytes in der Sequenz vorzeichenerweitert, um den endgültigen Wert zu erzeugen. Im vorzeichenlosen Fall ( uleb128
) werden alle nicht explizit dargestellten Bits als 0
interpretiert.
Bitweises Diagramm eines Zwei-Byte-LEB128-Werts | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Erstes Byte | Zweites Byte | ||||||||||||||
1 | bisschen 6 | bisschen 5 | bisschen 4 | bisschen 3 | bisschen 2 | Bit 1 | Bit 0 | 0 | bisschen 13 | Bit 12 | Bit 11 | bisschen 10 | bisschen 9 | Bit 8 | bisschen 7 |
Die Variante uleb128p1
wird verwendet, um einen vorzeichenbehafteten Wert darzustellen, wobei die Darstellung aus dem Wert plus eins besteht, der als uleb128
codiert ist. Dies macht die Codierung von -1
(alternativ als vorzeichenloser Wert 0xffffffff
) – aber keiner anderen negativen Zahl – zu einem einzelnen Byte und ist genau in den Fällen nützlich, in denen die dargestellte Zahl entweder nicht negativ oder -1
(bzw 0xffffffff
) und wo keine anderen negativen Werte erlaubt sind (oder wo wahrscheinlich keine großen vorzeichenlosen Werte benötigt werden).
Hier sind einige Beispiele für die Formate:
Verschlüsselte Sequenz | Als sleb128 | Als uleb128 | Als uleb128p1 |
---|---|---|---|
00 | 0 | 0 | -1 |
01 | 1 | 1 | 0 |
7f | -1 | 127 | 126 |
80 7f | -128 | 16256 | 16255 |
Dateilayout
Name | Format | Beschreibung |
---|---|---|
Header | header_item | die Überschrift |
string_ids | string_id_item[] | Liste der String-Identifikatoren. Dies sind Bezeichner für alle Zeichenfolgen, die von dieser Datei verwendet werden, entweder für die interne Benennung (z. B. Typdeskriptoren) oder als konstante Objekte, auf die durch Code verwiesen wird. Diese Liste muss nach Zeichenfolgeninhalten sortiert sein, wobei UTF-16-Codepunktwerte verwendet werden (nicht auf gebietsschemaabhängige Weise), und sie darf keine doppelten Einträge enthalten. |
type_ids | type_id_item[] | Typkennungsliste. Dies sind Bezeichner für alle Typen (Klassen, Arrays oder primitive Typen), auf die diese Datei verweist, unabhängig davon, ob sie in der Datei definiert ist oder nicht. Diese Liste muss nach dem Index string_id sortiert sein und darf keine doppelten Einträge enthalten. |
proto_ids | proto_id_item[] | Liste der Methodenprototyp-Identifikatoren. Dies sind Kennungen für alle Prototypen, auf die diese Datei verweist. Diese Liste muss in der Hauptreihenfolge des Rückgabetyps (nach type_id -Index) und dann nach Argumentliste (lexikografische Reihenfolge, einzelne Argumente nach type_id -Index) sortiert werden. Die Liste darf keine doppelten Einträge enthalten. |
field_ids | field_id_item[] | Liste der Feldbezeichner. Dies sind Bezeichner für alle Felder, auf die diese Datei verweist, unabhängig davon, ob sie in der Datei definiert sind oder nicht. Diese Liste muss sortiert werden, wobei der definierende Typ (nach type_id -Index) die Hauptreihenfolge, der Feldname (nach string_id Index) die Zwischenreihenfolge und der Typ (nach type_id -Index) die Nebenreihenfolge ist. Die Liste darf keine doppelten Einträge enthalten. |
method_ids | method_id_item[] | Liste der Methodenbezeichner. Dies sind Bezeichner für alle Methoden, auf die diese Datei verweist, unabhängig davon, ob sie in der Datei definiert sind oder nicht. Diese Liste muss sortiert werden, wobei der definierende Typ (nach type_id -Index) die Hauptreihenfolge, der Methodenname (nach string_id Index) die Zwischenreihenfolge und der Methodenprototyp (nach proto_id Index) die Nebenreihenfolge ist. Die Liste darf keine doppelten Einträge enthalten. |
class_defs | class_def_item[] | Liste der Klassendefinitionen. Die Klassen müssen so geordnet werden, dass die Oberklasse und die implementierten Schnittstellen einer bestimmten Klasse früher in der Liste erscheinen als die verweisende Klasse. Außerdem darf eine Definition für die gleichnamige Klasse nicht mehr als einmal in der Liste erscheinen. |
call_site_ids | call_site_id_item[] | Liste der Site-Identifikatoren aufrufen. Dies sind Kennungen für alle Aufrufseiten, auf die diese Datei verweist, unabhängig davon, ob sie in der Datei definiert sind oder nicht. Diese Liste muss in aufsteigender Reihenfolge von call_site_off sortiert werden. |
method_handles | method_handle_item[] | Liste der Methoden-Handles. Eine Liste aller Methodenhandles, auf die diese Datei verweist, unabhängig davon, ob sie in der Datei definiert sind oder nicht. Diese Liste ist nicht sortiert und kann Duplikate enthalten, die logisch verschiedenen Methoden-Handle-Instanzen entsprechen. |
Daten | ubyte[] | Datenbereich, der alle Stützdaten für die oben aufgeführten Tabellen enthält. Unterschiedliche Elemente haben unterschiedliche Ausrichtungsanforderungen, und Füllbytes werden bei Bedarf vor jedem Element eingefügt, um eine ordnungsgemäße Ausrichtung zu erreichen. |
link_data | ubyte[] | Daten, die in statisch verknüpften Dateien verwendet werden. Das Format der Daten in diesem Abschnitt wird von diesem Dokument nicht spezifiziert. Dieser Abschnitt ist in nicht verknüpften Dateien leer, und Laufzeitimplementierungen können ihn nach eigenem Ermessen verwenden. |
Bitfeld-, String- und Konstantendefinitionen
DEX_FILE_MAGIC
eingebettet in header_item
Die Konstante Array/String DEX_FILE_MAGIC
ist die Liste der Bytes, die am Anfang einer .dex
Datei stehen müssen, damit sie als solche erkannt wird. Der Wert enthält absichtlich einen Zeilenumbruch ( "\n"
oder 0x0a
) und ein Nullbyte ( "\0"
oder 0x00
), um bei der Erkennung bestimmter Formen von Korruption zu helfen. Der Wert codiert auch eine Formatversionsnummer als drei Dezimalziffern, von der erwartet wird, dass sie mit der Zeit monoton zunimmt, wenn sich das Format weiterentwickelt.
ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x39 0x00 } = "dex\n039\0"
Hinweis: Die Unterstützung für Version 039
des Formats wurde in der Android 9.0-Version hinzugefügt, die zwei neue Bytecodes eingeführt hat, const-method-handle
und const-method-type
. (Diese werden jeweils in der Tabelle Zusammenfassung der Bytecodesätze beschrieben.) In Android 10 erweitert Version 039
das DEX-Dateiformat um versteckte API-Informationen, die nur für DEX-Dateien im Startklassenpfad gelten.
Hinweis: Die Unterstützung für Version 038
des Formats wurde in der Android 8.0-Version hinzugefügt. Version 038
fügte neue Bytecodes ( invoke-polymorphic
und invoke-custom
) und Daten für Methodenhandles hinzu.
Hinweis: Die Unterstützung für Version 037
des Formats wurde in der Version Android 7.0 hinzugefügt. Vor Version 037
haben die meisten Android-Versionen Version 035
des Formats verwendet. Der einzige Unterschied zwischen den Versionen 035
und 037
ist das Hinzufügen von Standardmethoden und die Anpassung des invoke
.
Hinweis: Mindestens ein paar frühere Versionen des Formats wurden in weit verbreiteten öffentlichen Softwareversionen verwendet. Beispielsweise wurde Version 009
für die M3-Versionen der Android-Plattform (November–Dezember 2007) und Version 013
für die M5-Versionen der Android-Plattform (Februar–März 2008) verwendet. Diese früheren Versionen des Formats unterscheiden sich in mehrfacher Hinsicht erheblich von der in diesem Dokument beschriebenen Version.
ENDIAN_CONSTANT und REVERSE_ENDIAN_CONSTANT
eingebettet in header_item
Die Konstante ENDIAN_CONSTANT
wird verwendet, um die Endianness der Datei anzugeben, in der sie gefunden wird. Obwohl das standardmäßige .dex
-Format Little-Endian ist, können Implementierungen Byte-Swapping durchführen. Sollte eine Implementierung auf einen Header stoßen, dessen endian_tag
REVERSE_ENDIAN_CONSTANT
statt ENDIAN_CONSTANT
ist, würde sie wissen, dass die Datei von der erwarteten Form byte-ausgetauscht wurde.
uint ENDIAN_CONSTANT = 0x12345678; uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
eingebettet in class_def_item und debug_info_item
Die Konstante NO_INDEX
wird verwendet, um anzuzeigen, dass ein Indexwert fehlt.
Hinweis: Dieser Wert ist nicht als 0
definiert, da dies normalerweise ein gültiger Index ist.
Der gewählte Wert für NO_INDEX
ist als einzelnes Byte in der uleb128p1
Codierung darstellbar.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
access_flags-Definitionen
eingebettet in class_def_item, encoded_field, encoded_method und InnerClass
Bitfelder dieser Flags werden verwendet, um die Zugänglichkeit und Gesamteigenschaften von Klassen und Klassenmitgliedern anzuzeigen.
Name | Wert | Für Klassen (und InnerClass Anmerkungen) | Für Felder | Für Methoden |
---|---|---|---|---|
ACC_PUBLIC | 0x1 | public : überall sichtbar | public : überall sichtbar | public : überall sichtbar |
ACC_PRIVAT | 0x2 | private : nur für die definierende Klasse sichtbar | private : nur für die definierende Klasse sichtbar | private : nur für die definierende Klasse sichtbar |
ACC_PROTECTED | 0x4 | protected : sichtbar für Paket und Unterklassen | protected : sichtbar für Paket und Unterklassen | protected : sichtbar für Paket und Unterklassen |
ACC_STATIC | 0x8 | static : wird nicht mit einer äußeren this -Referenz erstellt | static : global zur definierenden Klasse | static : nimmt this Argument nicht an |
ACC_FINAL | 0x10 | final : nicht unterklassifizierbar | final : unveränderlich nach der Konstruktion | final : nicht überschreibbar |
ACC_SYNCHRONISIERT | 0x20 | synchronized : Zugeordnete Sperre, die automatisch um den Aufruf dieser Methode herum erworben wird. Hinweis: Das Setzen ist nur gültig, wenn | ||
ACC_VOLATILE | 0x40 | volatile : spezielle Zugriffsregeln zur Unterstützung der Thread-Sicherheit | ||
ACC_BRÜCKE | 0x40 | Bridge-Methode, die vom Compiler automatisch als typsichere Bridge hinzugefügt wird | ||
ACC_TRANSIENT | 0x80 | transient : soll nicht durch Standard-Serialisierung gespeichert werden | ||
ACC_VARARGS | 0x80 | Das letzte Argument sollte vom Compiler als "Rest"-Argument behandelt werden | ||
ACC_NATIVE | 0x100 | native : im nativen Code implementiert | ||
ACC_INTERFACE | 0x200 | interface : mehrfach implementierbare abstrakte Klasse | ||
ACC_ABSTRAKT | 0x400 | abstract : nicht direkt instanziierbar | abstract : von dieser Klasse nicht implementiert | |
ACC_STRICT | 0x800 | strictfp : strenge Regeln für Fließkommaarithmetik | ||
ACC_SYNTHETISCH | 0x1000 | nicht direkt im Quellcode definiert | nicht direkt im Quellcode definiert | nicht direkt im Quellcode definiert |
ACC_ANMERKUNG | 0x2000 | als Annotationsklasse deklariert | ||
ACC_ENUM | 0x4000 | als Aufzählungstyp deklariert | als Aufzählungswert deklariert | |
(ungebraucht) | 0x8000 | |||
ACC_CONSTRUCTOR | 0x10000 | Konstruktormethode (Klassen- oder Instanzinitialisierer) | ||
ACC_DECLARED_ SYNCHRONISIERT | 0x20000 | für synchronized erklärt.Hinweis: Dies hat keine Auswirkung auf die Ausführung (außer in Anbetracht dieses Flags per se). |
InnerClass
Anmerkungen zulässig und darf niemals in einem class_def_item
.
MUTF-8 (modifiziertes UTF-8) Kodierung
Als Zugeständnis an eine einfachere Legacy-Unterstützung codiert das .dex
-Format seine Zeichenfolgendaten in einer de facto standardmäßig modifizierten UTF-8-Form, die im Folgenden als MUTF-8 bezeichnet wird. Dieses Formular ist identisch mit Standard-UTF-8, außer:
- Es werden nur die Ein-, Zwei- und Drei-Byte-Codierungen verwendet.
- Codepunkte im Bereich
U+10000
…U+10ffff
werden als Ersatzpaar codiert, von denen jeder als ein codierter Drei-Byte-Wert dargestellt wird. - Der Codepunkt
U+0000
ist in Zwei-Byte-Form codiert. - Ein einfaches Null-Byte (Wert
0
) zeigt das Ende einer Zeichenfolge an, wie dies auch bei der Standardinterpretation der Sprache C der Fall ist.
Die ersten beiden obigen Elemente können wie folgt zusammengefasst werden: MUTF-8 ist ein Codierungsformat für UTF-16, anstatt ein direkteres Codierungsformat für Unicode-Zeichen zu sein.
Die letzten beiden obigen Elemente ermöglichen es gleichzeitig, den Codepunkt U+0000
in einen String aufzunehmen und ihn dennoch als nullterminierten String im C-Stil zu bearbeiten.
Die spezielle Codierung von U+0000
bedeutet jedoch, dass im Gegensatz zu normalem UTF-8 das Ergebnis des Aufrufs der Standard-C-Funktion strcmp()
für ein Paar von MUTF-8-Strings nicht immer das ordnungsgemäß signierte Ergebnis des Vergleichs ungleicher Strings anzeigt . Wenn die Reihenfolge (nicht nur die Gleichheit) ein Problem darstellt, besteht die einfachste Methode zum Vergleichen von MUTF-8-Strings darin, sie Zeichen für Zeichen zu decodieren und die decodierten Werte zu vergleichen. (Es sind jedoch auch cleverere Implementierungen möglich.)
Weitere Informationen zur Zeichencodierung finden Sie im Unicode-Standard . MUTF-8 ist eigentlich näher an der (relativ weniger bekannten) Codierung CESU-8 als an UTF-8 per se.
encoded_value Codierung
eingebettet in annotation_element und encoded_array_item
Ein encoded_value
ist ein codiertes Stück (fast) beliebiger hierarchisch strukturierter Daten. Die Codierung soll sowohl kompakt als auch einfach zu analysieren sein.
Name | Format | Beschreibung |
---|---|---|
(value_arg << 5) | Werttyp | Ubyte | Byte, das den Typ des unmittelbar nachfolgenden value zusammen mit einem optionalen klärenden Argument in den höherwertigen drei Bits angibt. Nachfolgend finden Sie die verschiedenen value . In den meisten Fällen codiert value_arg die Länge des unmittelbar nachfolgenden value in Bytes, als (size - 1) , z. B. bedeutet 0 , dass der Wert ein Byte erfordert, und 7 bedeutet, dass er acht Bytes erfordert; Es gibt jedoch Ausnahmen, wie unten angegeben. |
Wert | ubyte[] | Bytes, die den Wert darstellen, in der Länge variabel sind und für verschiedene value_type -Bytes unterschiedlich interpretiert werden, jedoch immer Little-Endian. Einzelheiten finden Sie in den verschiedenen Wertdefinitionen unten. |
Wertformate
Modellname | value_type | value_arg Format | value | Beschreibung |
---|---|---|---|---|
VALUE_BYTE | 0x00 | (keine; muss 0 sein) | ubyte[1] | vorzeichenbehafteter 1-Byte-Ganzzahlwert |
VALUE_SHORT | 0x02 | Größe - 1 (0…1) | ubyte[größe] | vorzeichenbehafteter 2-Byte-Ganzzahlwert, vorzeichenerweitert |
VALUE_CHAR | 0x03 | Größe - 1 (0…1) | ubyte[größe] | vorzeichenloser Zwei-Byte-Ganzzahlwert, Null-erweitert |
VALUE_INT | 0x04 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenbehafteter 4-Byte-Ganzzahlwert, vorzeichenerweitert |
VALUE_LONG | 0x06 | Größe - 1 (0…7) | ubyte[größe] | vorzeichenbehafteter 8-Byte-Ganzzahlwert, vorzeichenerweitert |
VALUE_FLOAT | 0x10 | Größe - 1 (0…3) | ubyte[größe] | Vier-Byte-Bitmuster, nach rechts um Null erweitert und als IEEE754-32-Bit-Gleitkommawert interpretiert |
VALUE_DOUBLE | 0x11 | Größe - 1 (0…7) | ubyte[größe] | Acht-Byte-Bitmuster, nach rechts um Null erweitert und als IEEE754-64-Bit-Gleitkommawert interpretiert |
VALUE_METHOD_TYPE | 0x15 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den proto_ids Abschnitt interpretiert wird und einen Methodentypwert darstellt |
VALUE_METHOD_HANDLE | 0x16 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den Abschnitt method_handles wird und einen Methoden-Handle-Wert darstellt |
VALUE_STRING | 0x17 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) 4-Byte-Ganzzahlwert, der als Index in den Abschnitt „ string_ids “ interpretiert wird und einen Zeichenfolgenwert darstellt |
WERTTYP | 0x18 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den Abschnitt „ type_ids “ interpretiert wird und einen reflektierenden Typ-/Klassenwert darstellt |
VALUE_FIELD | 0x19 | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den Abschnitt field_ids wird und einen reflektierenden Feldwert darstellt |
VALUE_METHOD | 0x1a | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den Abschnitt method_ids wird und einen reflektierenden Methodenwert darstellt |
VALUE_ENUM | 0x1b | Größe - 1 (0…3) | ubyte[größe] | vorzeichenloser (nullerweiterter) Vier-Byte-Ganzzahlwert, der als Index in den Abschnitt field_ids wird und den Wert einer Aufzählungstypkonstante darstellt |
VALUE_ARRAY | 0x1c | (keine; muss 0 sein) | codiertes_array | ein Array von Werten in dem Format, das durch " encoded_array format" unten angegeben ist. Die Größe des value ist in der Codierung implizit enthalten. |
VALUE_ANNOTATION | 0x1d | (keine; muss 0 sein) | codierte_Anmerkung | eine Unteranmerkung in dem Format, das unten durch " encoded_annotation format" angegeben ist. Die Größe des value ist in der Codierung implizit enthalten. |
VALUE_NULL | 0x1e | (keine; muss 0 sein) | (keiner) | null Referenzwert |
VALUE_BOOLEAN | 0x1f | boolesch (0…1) | (keiner) | Ein-Bit-Wert; 0 für false und 1 für true . Das Bit wird in value_arg . |
encoded_array-Format
Name | Format | Beschreibung |
---|---|---|
Größe | uleb128 | Anzahl der Elemente im Array |
Werte | kodierter_wert[größe] | eine Reihe von size -Bytesequenzen in dem von diesem Abschnitt encoded_value Format, sequentiell verkettet. |
encoded_annotation-Format
Name | Format | Beschreibung |
---|---|---|
type_idx | uleb128 | Art der Anmerkung. Dies muss ein Klassentyp (nicht Array oder Primitiv) sein. |
Größe | uleb128 | Anzahl der Name-Wert-Zuordnungen in dieser Anmerkung |
Elemente | Anmerkungselement[Größe] | Elemente der Anmerkung, die direkt inline (nicht als Offsets) dargestellt werden. Elemente müssen in aufsteigender Reihenfolge nach string_id Index sortiert werden. |
annotation_element-Format
Name | Format | Beschreibung |
---|---|---|
name_idx | uleb128 | Elementname, dargestellt als Index im Abschnitt string_ids . Die Zeichenfolge muss der oben definierten Syntax für MemberName entsprechen. |
Wert | kodierter_wert | Elementwert |
String-Syntax
Es gibt mehrere Arten von Elementen in einer .dex
-Datei, die letztendlich auf eine Zeichenfolge verweisen. Die folgenden Definitionen im BNF-Stil geben die akzeptable Syntax für diese Zeichenfolgen an.
EinfacherName
Ein SimpleName ist die Grundlage für die Syntax der Namen anderer Dinge. Das .dex
Format lässt hier ziemlich viel Spielraum (viel mehr als die meisten gängigen Quellsprachen). Kurz gesagt, ein einfacher Name besteht aus beliebigen Buchstaben oder Ziffern im Low-ASCII-Format, einigen spezifischen Low-ASCII-Symbolen und den meisten Nicht-ASCII-Codepunkten, die keine Steuerzeichen, Leerzeichen oder Sonderzeichen sind. Ab Version 040
erlaubt das Format zusätzlich Leerzeichen (Kategorie Unicode Zs
). Beachten Sie, dass Ersatzcodepunkte (im Bereich U+d800
… U+dfff
) per se nicht als gültige Namenszeichen gelten, aber Unicode-Ergänzungszeichen gültig sind (die durch die letzte Alternative der Regel für SimpleNameChar dargestellt werden ), und sie sollten in einer Datei als Paare von Ersatzcodepunkten in der MUTF-8-Codierung dargestellt werden.
EinfacherName → | ||
EinfachesNamenszeichen ( EinfachesNamenszeichen )* | ||
SimpleNameChar → | ||
'A' … 'Z' | ||
| | 'a' … 'z' | |
| | '0' … '9' | |
| | ' ' | seit DEX-Version 040 |
| | '$' | |
| | '-' | |
| | '_' | |
| | U+00a0 | seit DEX-Version 040 |
| | U+00a1 … U+1fff | |
| | U+2000 … U+200a | seit DEX-Version 040 |
| | U+2010 … U+2027 | |
| | U+202f | seit DEX-Version 040 |
| | U+2030 … U+d7ff | |
| | U+e000 … U+ffef | |
| | U+10000 … U+10ffff |
Mitgliedsname
Wird von field_id_item und method_id_item verwendet
Ein MemberName ist der Name eines Members einer Klasse, wobei Member Felder, Methoden und innere Klassen sind.
Mitgliedsname → | |
EinfacherName | |
| | '<' EinfacherName '>' |
Vollständiger Klassenname
Ein FullClassName ist ein vollständig qualifizierter Klassenname, einschließlich eines optionalen Paketbezeichners, gefolgt von einem erforderlichen Namen.
Vollständiger Klassenname → | |
OptionalPackagePrefix SimpleName | |
OptionalPackagePrefix → | |
( Einfacher Name '/' )* |
TypeDescriptor
Wird von type_id_item verwendet
Ein TypeDescriptor ist die Darstellung eines beliebigen Typs, einschließlich Primitiven, Klassen, Arrays und void
. Siehe unten für die Bedeutung der verschiedenen Versionen.
Typdeskriptor → | |
'V' | |
| | FieldTypeDescriptor |
FieldTypeDescriptor → | |
NonArrayFieldTypeDescriptor | |
| | ( '[' * 1…255) NichtArrayFieldTypeDescriptor |
NonArrayFieldTypeDescriptor → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' FullClassName ';' |
ShortyDescriptor
Wird von proto_id_item verwendet
Ein ShortyDescriptor ist die Kurzformdarstellung eines Methodenprototyps, einschließlich Rückgabe- und Parametertypen, außer dass es keinen Unterschied zwischen verschiedenen Referenztypen (Klassen oder Arrays) gibt. Stattdessen werden alle Referenztypen durch ein einzelnes 'L'
-Zeichen dargestellt.
ShortyDeskriptor → | |
ShortyReturnType ( ShortyFieldType )* | |
ShortyReturnType → | |
'V' | |
| | ShortyFieldType |
ShortyFieldType → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' |
TypeDescriptor- Semantik
Dies ist die Bedeutung jeder der Varianten von TypeDescriptor .
Syntax | Bedeutung |
---|---|
v | void ; nur gültig für Rückgabetypen |
Z | boolean |
B | byte |
S | short |
C | char |
ich | int |
J | long |
F | float |
D | double |
L voll/qualifiziert/Name ; | die Klasse fully.qualified.Name |
[ Beschreibung | Array of descriptor , rekursiv verwendbar für Arrays-of-Arrays, obwohl es ungültig ist, mehr als 255 Dimensionen zu haben. |
Artikel und verwandte Strukturen
Dieser Abschnitt enthält Definitionen für alle Elemente der obersten Ebene, die in einer .dex
-Datei vorkommen können.
header_item
erscheint im Kopfbereich
Ausrichtung: 4 Byte
Name | Format | Beschreibung |
---|---|---|
Magie | ubyte[8] = DEX_FILE_MAGIC | magischer Wert. Siehe Diskussion oben unter „ DEX_FILE_MAGIC “ für weitere Details. |
Prüfsumme | uint | adler32 Prüfsumme des Rests der Datei (alles außer magic und dieses Feld); Wird verwendet, um Dateibeschädigungen zu erkennen |
Unterschrift | ubyte[20] | SHA-1-Signatur (Hash) des Rests der Datei (alles außer magic , checksum und this field); verwendet, um Dateien eindeutig zu identifizieren |
Dateigröße | uint | Größe der gesamten Datei (einschließlich Header) in Byte |
header_size | uint = 0x70 | Größe des Headers (dieser gesamte Abschnitt) in Byte. Dies ermöglicht zumindest eine begrenzte Abwärts-/Aufwärtskompatibilität, ohne das Format ungültig zu machen. |
endian_tag | uint = ENDIAN_CONSTANT | Endianness-Tag. Siehe Diskussion oben unter " ENDIAN_CONSTANT und REVERSE_ENDIAN_CONSTANT " für weitere Details. |
link_size | uint | Größe des Linkabschnitts oder 0 , wenn diese Datei nicht statisch gelinkt ist |
link_off | uint | Versatz vom Anfang der Datei zum Linkabschnitt oder 0 , wenn link_size == 0 . Der Offset sollte, wenn er nicht Null ist, ein Offset in den Abschnitt link_data . Das Format der Daten, auf die verwiesen wird, wird von diesem Dokument nicht spezifiziert; Dieses Header-Feld (und das vorherige) werden als Hooks zur Verwendung durch Laufzeitimplementierungen belassen. |
map_off | uint | Versatz vom Anfang der Datei zum Kartenelement. Der Versatz, der nicht Null sein muss, sollte ein Versatz in den data sein, und die Daten sollten das unten durch „ map_list “ angegebene Format haben. |
string_ids_size | uint | Anzahl der Strings in der Liste der String-Identifikatoren |
string_ids_off | uint | Versatz vom Anfang der Datei zur Liste der String-Identifikatoren oder 0 , wenn string_ids_size == 0 (zugegebenermaßen ein seltsamer Grenzfall). Der Offset sollte, wenn er nicht Null ist, am Anfang des Abschnitts string_ids . |
type_ids_size | uint | Anzahl der Elemente in der Liste der Typidentifikatoren, höchstens 65535 |
type_ids_off | uint | Versatz vom Anfang der Datei zur Liste der Typidentifikatoren oder 0 , wenn type_ids_size == 0 (zugegebenermaßen ein seltsamer Grenzfall). Wenn der Offset nicht Null ist, sollte er am Anfang des Abschnitts type_ids . |
proto_ids_size | uint | Anzahl der Elemente in der Liste der Prototyp-Identifikatoren, höchstens 65535 |
proto_ids_off | uint | Versatz vom Anfang der Datei zur Liste der Prototyp-Identifikatoren oder 0 , wenn proto_ids_size == 0 (zugegebenermaßen ein seltsamer Grenzfall). Wenn der Offset nicht Null ist, sollte er am Anfang des Abschnitts proto_ids . |
field_ids_size | uint | Anzahl der Elemente in der Liste der Feldbezeichner |
field_ids_off | uint | Versatz vom Anfang der Datei zur Liste der Feldbezeichner oder 0 , wenn field_ids_size == 0 . Wenn der Offset nicht Null ist, sollte er am Anfang des Abschnitts field_ids . |
method_ids_size | uint | Anzahl der Elemente in der Liste der Methodenbezeichner |
method_ids_off | uint | Versatz vom Anfang der Datei zur Liste der Methodenbezeichner oder 0 , wenn method_ids_size == 0 . Wenn der Offset nicht Null ist, sollte er am Anfang des Abschnitts method_ids . |
class_defs_size | uint | Anzahl der Elemente in der Liste der Klassendefinitionen |
class_defs_off | uint | Versatz vom Anfang der Datei zur Liste der Klassendefinitionen oder 0 , wenn class_defs_size == 0 (zugegebenermaßen ein seltsamer Grenzfall). Wenn der Offset nicht Null ist, sollte er am Anfang des Abschnitts class_defs . |
Datengröße | uint | Größe des data in Byte. Muss ein gerades Vielfaches von sizeof(uint) sein. |
Daten_aus | uint | Versatz vom Beginn der Datei zum Beginn des data . |
map_list
erscheint im Datenbereich
referenziert von header_item
Ausrichtung: 4 Byte
Dies ist eine geordnete Liste des gesamten Inhalts einer Datei. Es enthält eine gewisse Redundanz in Bezug auf das header_item
, soll aber eine einfache Form sein, die verwendet werden kann, um eine ganze Datei zu durchlaufen. Ein gegebener Typ darf höchstens einmal in einer Karte erscheinen, aber es gibt keine Beschränkung, in welcher Reihenfolge Typen erscheinen dürfen, abgesehen von den Einschränkungen, die durch den Rest des Formats impliziert werden (z. B. muss zuerst ein header
-Abschnitt erscheinen, gefolgt von einer string_ids
Abschnitt usw.). Außerdem müssen die Zuordnungseinträge nach anfänglichem Offset sortiert werden und dürfen sich nicht überlappen.
Name | Format | Beschreibung |
---|---|---|
Größe | uint | Größe der Liste in Einträgen |
aufführen | map_item[Größe] | Elemente der Liste |
map_item-Format
Name | Format | Beschreibung |
---|---|---|
Typ | ukurz | Art der Artikel; siehe Tabelle unten |
ungebraucht | ukurz | (ungebraucht) |
Größe | uint | Anzahl der am angegebenen Offset zu findenden Elemente |
versetzt | uint | Versatz vom Anfang der Datei zu den fraglichen Elementen |
Typencodes
Gegenstandsart | Konstante | Wert | Elementgröße in 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 + (Artikelgröße * 12) |
Typ_Liste | TYPE_TYPE_LIST | 0x1001 | 4 + (Artikelgröße * 2) |
annotation_set_ref_list | TYPE_ANNOTATION_SET_REF_LIST | 0x1002 | 4 + (Artikelgröße * 4) |
annotation_set_item | TYPE_ANNOTATION_SET_ITEM | 0x1003 | 4 + (Artikelgröße * 4) |
class_data_item | TYPE_CLASS_DATA_ITEM | 0x2000 | implizit; parsen muss |
code_item | TYPE_CODE_ITEM | 0x2001 | implizit; parsen muss |
string_data_item | TYPE_STRING_DATA_ITEM | 0x2002 | implizit; parsen muss |
debug_info_item | TYPE_DEBUG_INFO_ITEM | 0x2003 | implizit; parsen muss |
annotation_item | TYPE_ANNOTATION_ITEM | 0x2004 | implizit; parsen muss |
encoded_array_item | TYPE_ENCODED_ARRAY_ITEM | 0x2005 | implizit; parsen muss |
annotations_directory_item | TYPE_ANNOTATIONS_DIRECTORY_ITEM | 0x2006 | implizit; parsen muss |
hiddenapi_class_data_item | TYPE_HIDDENAPI_CLASS_DATA_ITEM | 0xF000 | implizit; parsen muss |
string_id_item
erscheint im Abschnitt string_ids
Ausrichtung: 4 Byte
Name | Format | Beschreibung |
---|---|---|
string_data_off | uint | Versatz vom Anfang der Datei zu den Zeichenfolgendaten für dieses Element. Der Offset sollte sich an einer Stelle im data befinden, und die Daten sollten das unten durch " string_data_item " angegebene Format haben. Für den Versatz besteht keine Ausrichtungsanforderung. |
string_data_item
erscheint im Datenbereich
Ausrichtung: keine (Byte-ausgerichtet)
Name | Format | Beschreibung |
---|---|---|
utf16_size | uleb128 | Größe dieser Zeichenfolge in UTF-16-Codeeinheiten (was in vielen Systemen die "Zeichenfolgenlänge" ist). Das heißt, dies ist die decodierte Länge der Zeichenfolge. (Die codierte Länge ergibt sich aus der Position des 0 -Bytes.) |
Daten | ubyte[] | eine Reihe von MUTF-8-Codeeinheiten (auch bekannt als Oktette, auch bekannt als Bytes), gefolgt von einem Byte mit dem Wert 0 . Siehe "MUTF-8 (Modified UTF-8) Encoding" oben für Details und Diskussionen über das Datenformat. Hinweis: Es ist akzeptabel, eine Zeichenfolge zu haben, die (die codierte Form von) UTF-16-Ersatzcodeeinheiten (d. h. |
type_id_item
erscheint im Abschnitt type_ids
Ausrichtung: 4 Bytes
Name | Format | Beschreibung |
---|---|---|
descriptor_idx | uint | index in die string_ids Liste für die Deskriptorzeichenfolge dieses Typs. Die Zeichenfolge muss der oben definierten Syntax für TypeDescriptor entsprechen. |
proto_id_item
erscheint im Abschnitt proto_ids
Ausrichtung: 4 Bytes
Name | Format | Beschreibung |
---|---|---|
shorty_idx | uint | index in die string_ids -Liste für die Kurzform-Deskriptorzeichenfolge dieses Prototyps. Die Zeichenfolge muss der oben definierten Syntax für ShortyDescriptor entsprechen und dem Rückgabetyp und den Parametern dieses Elements entsprechen. |
return_type_idx | uint | index in die type_ids Liste für den Rückgabetyp dieses Prototyps |
parameter_off | uint | Versatz vom Anfang der Datei zur Liste der Parametertypen für diesen Prototyp oder 0 , wenn dieser Prototyp keine Parameter hat. Dieser Offset sollte, wenn er nicht Null ist, im data stehen, und die Daten dort sollten das unten durch "type_list" angegebene Format haben. Außerdem sollte in der Liste kein Verweis auf den Typ void vorhanden sein. |
field_id_item
erscheint im Abschnitt field_ids
Ausrichtung: 4 Byte
Name | Format | Beschreibung |
---|---|---|
class_idx | ukurz | index in die type_ids Liste für den Definierer dieses Felds. Dies muss ein Klassentyp sein und kein Array oder primitiver Typ. |
type_idx | ukurz | index in die type_ids Liste für den Typ dieses Felds |
name_idx | uint | index in die string_ids Liste für den Namen dieses Felds. Die Zeichenfolge muss der oben definierten Syntax für MemberName entsprechen. |
method_id_item
erscheint im Abschnitt method_ids
Ausrichtung: 4 Byte
Name | Format | Beschreibung |
---|---|---|
class_idx | ukurz | index in die type_ids Liste für den Definierer dieser Methode. Dies muss ein Klassen- oder Arraytyp sein und kein primitiver Typ. |
proto_idx | ukurz | index in die proto_ids Liste für den Prototyp dieser Methode |
name_idx | uint | index in die string_ids Liste für den Namen dieser Methode. Die Zeichenfolge muss der oben definierten Syntax für MemberName entsprechen. |
class_def_item
erscheint im Abschnitt class_defs
Ausrichtung: 4 Byte
Name | Format | Beschreibung |
---|---|---|
class_idx | uint | index in die type_ids Liste für diese Klasse. Dies muss ein Klassentyp sein und kein Array oder primitiver Typ. |
access_flags | uint | Zugriffsflags für die Klasse ( public , final usw.). Siehe " access_flags Definitionen" für Details. |
superclass_idx | uint | index in die type_ids Liste für die Superklasse oder den konstanten Wert NO_INDEX , wenn diese Klasse keine Superklasse hat (dh es ist eine Wurzelklasse wie Object ). Falls vorhanden, muss es sich um einen Klassentyp handeln und nicht um ein Array oder einen primitiven Typ. |
Schnittstellen_aus | uint | Versatz vom Anfang der Datei bis zur Liste der Schnittstellen oder 0 , wenn es keine gibt. Dieser Offset sollte sich im data befinden, und die Daten dort sollten das unten durch " type_list " angegebene Format haben. Jedes der Elemente der Liste muss ein Klassentyp sein (kein Array oder primitiver Typ), und es dürfen keine Duplikate vorhanden sein. |
source_file_idx | uint | index in die string_ids Liste für den Namen der Datei, die die ursprüngliche Quelle für (zumindest den größten Teil) dieser Klasse enthält, oder den speziellen Wert NO_INDEX , um einen Mangel an diesen Informationen darzustellen. Das debug_info_item jeder gegebenen Methode kann diese Quelldatei überschreiben, aber die Erwartung ist, dass die meisten Klassen nur aus einer Quelldatei stammen. |
Anmerkungen_aus | uint | Versatz vom Anfang der Datei zur Anmerkungsstruktur für diese Klasse oder 0 , wenn es keine Anmerkungen zu dieser Klasse gibt. Dieser Offset sollte sich, wenn er nicht Null ist, im data befinden, und die Daten dort sollten das unten durch " annotations_directory_item " angegebene Format haben, wobei sich alle Elemente auf diese Klasse als Definierer beziehen. |
class_data_off | uint | Versatz vom Anfang der Datei zu den zugeordneten Klassendaten für dieses Element oder 0 , wenn es keine Klassendaten für diese Klasse gibt. (Dies kann zum Beispiel der Fall sein, wenn diese Klasse eine Marker-Schnittstelle ist.) Der Offset sollte, wenn er nicht Null ist, im data stehen, und die Daten dort sollten das durch " class_data_item " unten angegebene Format haben. wobei sich alle Elemente auf diese Klasse als Definierer beziehen. |
static_values_off | uint | Offset vom Anfang der Datei bis zur Liste der Anfangswerte für static Felder oder 0 , wenn keine vorhanden sind (und alle static Felder mit 0 oder null initialisiert werden sollen). Dieser Offset sollte sich im data befinden, und die Daten dort sollten das unten durch " encoded_array_item " angegebene Format haben. Die Größe des Arrays darf nicht größer sein als die Anzahl der von dieser Klasse deklarierten static Felder, und die Elemente entsprechen den static Feldern in derselben Reihenfolge wie in der entsprechenden field_list . Der Typ jedes Array-Elements muss mit dem deklarierten Typ des entsprechenden Felds übereinstimmen. Wenn das Array weniger Elemente als static Felder enthält, werden die verbleibenden Felder mit einer typgerechten 0 oder null initialisiert. |
call_site_id_item
erscheint im Abschnitt call_site_ids
Ausrichtung: 4 Bytes
Name | Format | Beschreibung |
---|---|---|
call_site_off | uint | Versatz vom Anfang der Datei zum Aufrufen der Site-Definition. Der Offset sollte sich im Datenabschnitt befinden, und die Daten dort sollten das unten durch "call_site_item" angegebene Format haben. |
call_site_item
erscheint im Datenbereich
Ausrichtung: keine (Byte ausgerichtet)
Das call_site_item ist ein encoded_array_item, dessen Elemente den Argumenten entsprechen, die einer Bootstrap-Linker-Methode bereitgestellt werden. Die ersten drei Argumente sind:
- Ein Methoden-Handle, das die Bootstrap-Linker-Methode darstellt (VALUE_METHOD_HANDLE).
- Ein Methodenname, den der Bootstrap-Linker auflösen soll (VALUE_STRING).
- Ein Methodentyp, der dem Typ des aufzulösenden Methodennamens entspricht (VALUE_METHOD_TYPE).
Alle zusätzlichen Argumente sind konstante Werte, die an die Bootstrap-Linker-Methode übergeben werden. 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 | Beschreibung |
---|---|---|
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 | Wert | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
size | uint | size of the list, in entries |
list | type_item[size] | elements of the list |
type_item format
Name | Format | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Wert | Format | Arguments | Beschreibung |
---|---|---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Wert | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Wert | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
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 | Beschreibung |
---|---|---|
value | Class[] | the array of exception types thrown |