Ten dokument opisuje układ i zawartość plików .dex
, które są używane do przechowywania zestawu definicji klas i skojarzonych z nimi danych pomocniczych.
Przewodnik po typach
Nazwa | Opis |
---|---|
bajt | 8-bitowy z podpisem |
ubyte | 8-bitowa int bez znaku |
niski | 16-bitowy z podpisem, little-endian |
skrócić | 16-bitowy unsigned int, little-endian |
int | 32-bitowy z podpisem, little-endian |
nieskończoność | 32-bitowy unsigned int, little-endian |
długie | 64-bitowy podpisany int, little-endian |
ulong | 64-bitowy unsigned int, little-endian |
sleb128 | sygnowany LEB128, zmienna długość (patrz niżej) |
uleb128 | bez znaku LEB128, o zmiennej długości (patrz poniżej) |
uleb128p1 | bez znaku LEB128 plus 1 , o zmiennej długości (patrz poniżej) |
LEB128
LEB128 ("Little - Endian B ase 128 ") to kodowanie o zmiennej długości dla dowolnych liczb całkowitych ze znakiem lub bez znaku. Format został zapożyczony ze specyfikacji DWARF3 . W pliku .dex
LEB128 jest używany tylko do kodowania wielkości 32-bitowych.
Każda zakodowana wartość LEB128 składa się z jednego do pięciu bajtów, które razem reprezentują pojedynczą wartość 32-bitową. Każdy bajt ma ustawiony swój najbardziej znaczący bit, z wyjątkiem ostatniego bajtu w sekwencji, który ma swój najbardziej znaczący bit. Pozostałe siedem bitów każdego bajtu to ładunek, z najmniej znaczącymi siedmioma bitami ilości w pierwszym bajcie, kolejnymi siedmioma w drugim bajcie i tak dalej. W przypadku LEB128 ze znakiem ( sleb128
), najbardziej znaczący bit ładunku końcowego bajtu w sekwencji jest rozszerzony o znak, aby wytworzyć wartość końcową. W przypadku bez znaku ( uleb128
) wszelkie bity, które nie są jawnie reprezentowane, są interpretowane jako 0
.
Diagram bitowy dwubajtowej wartości LEB128 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Pierwszy bajt | Drugi bajt | ||||||||||||||
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 |
Wariant uleb128p1
służy do reprezentowania wartości ze znakiem, gdzie reprezentacją jest wartość plus jeden zakodowana jako uleb128
. To sprawia, że kodowanie -1
(alternatywnie uważane za wartość bez znaku 0xffffffff
) — ale żadnej innej liczby ujemnej — jest pojedynczym bajtem i jest przydatne dokładnie w tych przypadkach, w których reprezentowana liczba musi być nieujemna lub -1
(lub 0xffffffff
) i gdzie nie są dozwolone żadne inne wartości ujemne (lub gdy duże wartości bez znaku są mało prawdopodobne).
Oto kilka przykładów formatów:
Zakodowana sekwencja | Jak sleb128 | Jak uleb128 | Jako uleb128p1 |
---|---|---|---|
00 | 0 | 0 | -1 |
01 | 1 | 1 | 0 |
7f | -1 | 127 | 126 |
80 7f | -128 | 16256 | 16255 |
Układ pliku
Nazwa | Format | Opis |
---|---|---|
nagłówek | pozycja_nagłówka | Nagłówek |
string_ids | string_id_item[] | lista identyfikatorów ciągów. Są to identyfikatory wszystkich łańcuchów używanych przez ten plik, albo do wewnętrznego nazewnictwa (np. deskryptory typów), albo jako obiekty stałe, do których odwołuje się kod. Ta lista musi być posortowana według zawartości ciągu przy użyciu wartości punktów kodowych UTF-16 (nie w sposób zależny od ustawień regionalnych) i nie może zawierać żadnych zduplikowanych wpisów. |
identyfikatory typów | type_id_item[] | lista identyfikatorów typów. Są to identyfikatory dla wszystkich typów (klas, tablic lub typów pierwotnych), do których odwołuje się ten plik, niezależnie od tego, czy są w nim zdefiniowane, czy nie. Ta lista musi być posortowana według indeksu string_id i nie może zawierać zduplikowanych wpisów. |
proto_ids | proto_id_item[] | lista identyfikatorów prototypów metody. Są to identyfikatory wszystkich prototypów, do których odwołuje się ten plik. Ta lista musi być posortowana w kolejności głównej typu zwracanego (według indeksu type_id ), a następnie według listy argumentów (porządek leksykograficzny, poszczególne argumenty uporządkowane według indeksu type_id ). Lista nie może zawierać zduplikowanych wpisów. |
identyfikatory pola | pole_id_item[] | lista identyfikatorów pól. Są to identyfikatory dla wszystkich pól, do których odwołuje się ten plik, niezależnie od tego, czy są w nim zdefiniowane, czy nie. Ta lista musi być posortowana, gdzie typ definiujący (według indeksu type_id ) jest porządkiem głównym, nazwa pola (według indeksu string_id ) jest porządkiem pośrednim, a typ (według indeksu type_id ) jest porządkiem pomocniczym. Lista nie może zawierać zduplikowanych wpisów. |
identyfikatory_metod | metoda_id_item[] | lista identyfikatorów metod. Są to identyfikatory dla wszystkich metod, do których odwołuje się ten plik, niezależnie od tego, czy są w nim zdefiniowane, czy nie. Ta lista musi być posortowana, gdzie typ definiujący (według indeksu type_id ) jest porządkiem głównym, nazwa metody (według indeksu string_id ) jest porządkiem pośrednim, a prototyp metody (według indeksu proto_id ) jest porządkiem pomocniczym. Lista nie może zawierać zduplikowanych wpisów. |
class_defs | class_def_item[] | lista definicji klas. Klasy muszą być uporządkowane w taki sposób, aby nadklasa danej klasy i zaimplementowane interfejsy pojawiały się na liście wcześniej niż klasa odsyłająca. Ponadto niepoprawne jest, aby definicja klasy o tej samej nazwie pojawiała się na liście więcej niż raz. |
call_site_ids | call_site_id_item[] | Zadzwoń do listy identyfikatorów witryn. Są to identyfikatory wszystkich stron połączeń, do których odwołuje się ten plik, niezależnie od tego, czy są w nim określone, czy nie. Ta lista musi być posortowana w porządku rosnącym call_site_off . |
uchwyty_metod | method_handle_item[] | lista uchwytów metod. Lista wszystkich uchwytów metod, do których odwołuje się ten plik, niezależnie od tego, czy są w nim zdefiniowane, czy nie. Ta lista nie jest posortowana i może zawierać duplikaty, które logicznie odpowiadają różnym instancjom obsługi metod. |
dane | ubajt[] | obszar danych, zawierający wszystkie dane pomocnicze dla tabel wymienionych powyżej. Różne elementy mają różne wymagania dotyczące wyrównania, a bajty dopełniające są wstawiane przed każdym elementem, jeśli jest to konieczne do uzyskania prawidłowego wyrównania. |
link_dane | ubajt[] | dane używane w statycznie połączonych plikach. Format danych w tej sekcji nie został określony przez ten dokument. Ta sekcja jest pusta w niepowiązanych plikach, a implementacje środowiska wykonawczego mogą jej używać według własnego uznania. |
Definicje pól bitowych, łańcuchów i stałych
DEX_FILE_MAGIC
osadzone w header_item
Stała tablica/łańcuch DEX_FILE_MAGIC
to lista bajtów, które muszą pojawić się na początku pliku .dex
, aby został on rozpoznany jako taki. Wartość celowo zawiera znak nowej linii ( "\n"
lub 0x0a
) i bajt null ( "\0"
lub 0x00
), aby pomóc w wykrywaniu pewnych form uszkodzenia. Wartość koduje również numer wersji formatu jako trzy cyfry dziesiętne, które zgodnie z oczekiwaniami będą wzrastać w miarę rozwoju formatu.
ubyte[8] DEX_FILE_MAGIC = { 0x64 0x65 0x78 0x0a 0x30 0x33 0x39 0x00 } = "dex\n039\0"
Uwaga: w wersji Android 9.0 dodano obsługę wersji 039
formatu, która wprowadziła dwa nowe kody bajtowe const-method-handle
i const-method-type
. (Każdy z nich jest opisany w tabeli Podsumowanie zestawu kodów bajtowych ). W systemie Android 10 wersja 039
rozszerza format pliku DEX o ukryte informacje o interfejsie API, które mają zastosowanie tylko do plików DEX w ścieżce klasy rozruchowej.
Uwaga: w wersji Android 8.0 dodano obsługę wersji 038
formatu. Wersja 038
dodała nowe kody bajtowe ( invoke-polymorphic
i invoke-custom
) oraz dane dla uchwytów metod.
Uwaga: w wersji Androida 7.0 dodano obsługę wersji 037
formatu. Przed wersją 037
większość wersji Androida używała wersji 035
formatu. Jedyną różnicą między wersjami 035
i 037
jest dodanie metod domyślnych i dostosowanie invoke
.
Uwaga: co najmniej kilka wcześniejszych wersji tego formatu było używanych w powszechnie dostępnych publicznych wydaniach oprogramowania. Na przykład wersja 009
była używana w wersjach M3 platformy Android (listopad–grudzień 2007), a wersja 013
była używana w wersjach M5 platformy Android (luty–marzec 2008). Pod kilkoma względami te wcześniejsze wersje formatu znacznie różnią się od wersji opisanej w tym dokumencie.
ENDIAN_CONSTANT i REVERSE_ENDIAN_CONSTANT
osadzone w header_item
Stała ENDIAN_CONSTANT
służy do wskazania endianowości pliku, w którym się znajduje. Chociaż standardowy format .dex
jest little-endian, implementacje mogą zdecydować się na wymianę bajtów. Jeśli implementacja napotka nagłówek, którego endian_tag
to REVERSE_ENDIAN_CONSTANT
zamiast ENDIAN_CONSTANT
, będzie wiedziała, że plik został zastąpiony bajtami z oczekiwanej postaci.
uint ENDIAN_CONSTANT = 0x12345678; uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
osadzone w class_def_item i debug_info_item
Stała NO_INDEX
służy do wskazania braku wartości indeksu.
Uwaga: ta wartość nie jest zdefiniowana jako 0
, ponieważ w rzeczywistości jest to zazwyczaj prawidłowy indeks.
Wybrana wartość NO_INDEX
jest reprezentowana jako pojedynczy bajt w kodowaniu uleb128p1
.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
definicje flag_dostępu
osadzone w class_def_item, encoded_field, encoded_method i InnerClass
Pola bitowe tych flag są używane do wskazania dostępności i ogólnych właściwości klas i członków klasy.
Nazwa | Wartość | Dla klas (i adnotacji InnerClass ) | Dla pól | Dla metod |
---|---|---|---|---|
ACC_PUBLIC | 0x1 | public : widoczne wszędzie | public : widoczne wszędzie | public : widoczne wszędzie |
ACC_PRYWATNE | 0x2 | private : widoczne tylko dla zdefiniowania klasy | private : widoczne tylko dla zdefiniowania klasy | private : widoczne tylko dla zdefiniowania klasy |
ACC_PROTECTED | 0x4 | protected : widoczne dla pakietu i podklas | protected : widoczne dla pakietu i podklas | protected : widoczne dla pakietu i podklas |
ACC_STATIC | 0x8 | static : nie jest skonstruowany z zewnętrznym this odniesieniem | static : globalny do definiowania klasy | static : nie przyjmuje this argumentu |
ACC_FINAL | 0x10 | final : nie do podklasy | final : niezmienna po zbudowaniu | final : nie do zastąpienia |
ACC_SYNCHRONIZED | 0x20 | synchronized : skojarzona blokada automatycznie uzyskana w pobliżu wywołania tej metody. Uwaga: Jest to prawidłowe tylko wtedy, gdy ustawiono również | ||
ACC_VOLATILE | 0x40 | volatile : specjalne zasady dostępu pomagające w bezpieczeństwie wątków | ||
ACC_BRIDGE | 0x40 | metoda bridge, dodawana automatycznie przez kompilator jako most bezpieczny dla typu | ||
ACC_TRANSIENT | 0x80 | transient : nie do zapisania domyślna serializacja | ||
ACC_VARARGS | 0x80 | ostatni argument powinien być traktowany przez kompilator jako „odpoczynek” | ||
ACC_NATYWNY | 0x100 | native : zaimplementowany w natywnym kodzie | ||
ACC_INTERFACE | 0x200 | interface : wielokrotna implementacja klasy abstrakcyjnej | ||
ACC_ABSTRACT | 0x400 | abstract : nie można bezpośrednio tworzyć instancji | abstract : nie zaimplementowane przez tę klasę | |
ACC_STRICT | 0x800 | strictfp : ścisłe zasady arytmetyki zmiennoprzecinkowej | ||
ACC_SYNTHETIC | 0x1000 | nie zdefiniowane bezpośrednio w kodzie źródłowym | nie zdefiniowane bezpośrednio w kodzie źródłowym | nie zdefiniowane bezpośrednio w kodzie źródłowym |
ACC_ANNOTATION | 0x2000 | zadeklarowana jako klasa adnotacji | ||
ACC_ENUM | 0x4000 | zadeklarowany jako typ wyliczeniowy | zadeklarowana jako wartość wyliczana | |
(nie używany) | 0x8000 | |||
ACC_CONSTRUCTOR | 0x10000 | metoda konstruktora (inicjator klasy lub instancji) | ||
ACC_DECLARED_ ZSYNCHRONIZOWANY | 0x20000 | zadeklarowany synchronized .Uwaga: nie ma to wpływu na wykonanie (poza odzwierciedleniem tej flagi per se). |
InnerClass
i nie może nigdy być włączone w class_def_item
.
Kodowanie MUTF-8 (zmodyfikowane UTF-8)
W ramach ustępstwa na rzecz łatwiejszej obsługi starszych wersji, format .dex
koduje swoje dane ciągu w de facto standardowym zmodyfikowanym formacie UTF-8, zwanym dalej MUTF-8. Ten formularz jest identyczny ze standardowym UTF-8, z wyjątkiem:
- Używane są tylko kodowania jedno-, dwu- i trzybajtowe.
- Punkty kodowe z zakresu
U+10000
…U+10ffff
są zakodowane jako para zastępcza, z których każda jest reprezentowana jako trzybajtowa zakodowana wartość. - Punkt kodowy
U+0000
jest zakodowany w postaci dwubajtowej. - Zwykły bajt null (wartość
0
) wskazuje koniec ciągu, podobnie jak standardowa interpretacja języka C.
Pierwsze dwa powyższe elementy można podsumować w następujący sposób: MUTF-8 to format kodowania dla UTF-16, zamiast być bardziej bezpośrednim formatem kodowania znaków Unicode.
Ostatnie dwa powyższe elementy umożliwiają jednoczesne uwzględnienie punktu kodowego U+0000
w ciągu i manipulowanie nim jako ciągiem zakończonym znakiem NULL w stylu C.
Jednak specjalne kodowanie U+0000
oznacza, że w przeciwieństwie do normalnego UTF-8, wynik wywołania standardowej funkcji C strcmp()
na parze ciągów MUTF-8 nie zawsze wskazuje na poprawnie podpisany wynik porównania nierównych ciągów . Kiedy kolejność (nie tylko równość) jest problemem, najprostszym sposobem porównania ciągów MUTF-8 jest zdekodowanie ich znak po znaku i porównanie zdekodowanych wartości. (Możliwe są jednak również bardziej sprytne implementacje.)
Więcej informacji na temat kodowania znaków można znaleźć w dokumencie The Unicode Standard . MUTF-8 jest w rzeczywistości bliższy (stosunkowo mniej znanemu) kodowaniu CESU-8 niż UTF-8 per se.
kodowanie encoded_value
osadzone w annotation_element i encoded_array_item
encoded_value
to zakodowany fragment (prawie) dowolnych danych o hierarchicznej strukturze. Kodowanie ma być zarówno zwarte, jak i łatwe do przeanalizowania.
Nazwa | Format | Opis |
---|---|---|
(arg_wartości << 5) | typ wartości | ubyte | bajt wskazujący typ następnej value wraz z opcjonalnym argumentem wyjaśniającym w trzech bitach wyższego rzędu. Zobacz poniżej różne definicje value . W większości przypadków value_arg koduje długość bezpośrednio następującej value w bajtach, jako (size - 1) , np. 0 oznacza, że wartość wymaga jednego bajtu, a 7 oznacza, że wymaga ośmiu bajtów; istnieją jednak wyjątki, o których mowa poniżej. |
wartość | ubajt[] | bajty reprezentujące wartość, o zmiennej długości i różnie interpretowane dla różnych bajtów value_type , choć zawsze little-endian. Szczegółowe informacje można znaleźć w poniższych definicjach wartości. |
Formaty wartości
Wpisz imię | value_type | value_arg Format | Format value | Opis |
---|---|---|---|---|
VALUE_BYTE | 0x00 | (brak; musi być 0 ) | ubyte[1] | jednobajtowa wartość całkowita ze znakiem |
VALUE_SHORT | 0x02 | rozmiar - 1 (0…1) | ubajt[rozmiar] | dwubajtowa wartość całkowita ze znakiem, rozszerzona o znak |
VALUE_CHAR | 0x03 | rozmiar - 1 (0…1) | ubajt[rozmiar] | dwubajtowa liczba całkowita bez znaku, z rozszerzeniem o zero |
VALUE_INT | 0x04 | rozmiar - 1 (0…3) | ubajt[rozmiar] | czterobajtowa wartość całkowita ze znakiem, rozszerzona o znak |
VALUE_LONG | 0x06 | rozmiar - 1 (0…7) | ubajt[rozmiar] | ośmiobajtowa wartość całkowita ze znakiem, rozszerzona o znak |
VALUE_FLOAT | 0x10 | rozmiar - 1 (0…3) | ubajt[rozmiar] | czterobajtowy wzór bitowy, z rozszerzeniem o zero po prawej stronie i interpretowany jako 32-bitowa wartość zmiennoprzecinkowa IEEE754 |
VALUE_DOUBLE | 0x11 | rozmiar - 1 (0…7) | ubajt[rozmiar] | ośmiobajtowy wzór bitowy, z rozszerzeniem o zero po prawej stronie i interpretowany jako 64-bitowa wartość zmiennoprzecinkowa IEEE754 |
VALUE_METHOD_TYPE | 0x15 | rozmiar - 1 (0…3) | ubajt[rozmiar] | unsigned (zero-extended) czterobajtowa wartość całkowita, interpretowana jako indeks do sekcji proto_ids i reprezentująca wartość typu metody |
VALUE_METHOD_HANDLE | 0x16 | rozmiar - 1 (0…3) | ubajt[rozmiar] | unsigned (zero-extended) czterobajtowa wartość całkowita, interpretowana jako indeks do sekcji method_handles i reprezentująca wartość uchwytu metody |
VALUE_STRING | 0x17 | rozmiar - 1 (0…3) | ubajt[rozmiar] | unsigned (zero-extended) czterobajtowa wartość całkowita, interpretowana jako indeks w sekcji string_ids i reprezentująca wartość ciągu |
TYP WARTOŚCI | 0x18 | rozmiar - 1 (0…3) | ubajt[rozmiar] | unsigned (zero-extended) czterobajtowa wartość całkowita, interpretowana jako indeks w sekcji type_ids i reprezentująca wartość typu/klasy odzwierciedlającej |
VALUE_FIELD | 0x19 | rozmiar - 1 (0…3) | ubajt[rozmiar] | bez znaku (zero-rozszerzona) czterobajtowa wartość całkowita, interpretowana jako indeks w sekcji field_ids i reprezentująca wartość pola odzwierciedlającego |
VALUE_METHOD | 0x1a | rozmiar - 1 (0…3) | ubajt[rozmiar] | bez znaku (z rozszerzeniem o zero) czterobajtowa wartość całkowita, interpretowana jako indeks w sekcji method_ids i reprezentująca odzwierciedlającą wartość metody |
VALUE_ENUM | 0x1b | rozmiar - 1 (0…3) | ubajt[rozmiar] | unsigned (zero-extended) czterobajtowa wartość całkowita, interpretowana jako indeks do sekcji field_ids i reprezentująca wartość stałej typu wyliczanego |
VALUE_ARRAY | 0x1c | (brak; musi być 0 ) | zakodowana_tablica | tablica wartości w formacie określonym przez „ format encoded_array ” poniżej. Rozmiar value jest ukryty w kodowaniu. |
VALUE_ANNOTATION | 0x1d | (brak; musi być 0 ) | zakodowana_adnotacja | adnotację podrzędną w formacie określonym przez „format encoded_annotation ” poniżej. Rozmiar value jest ukryty w kodowaniu. |
VALUE_NULL | 0x1e | (brak; musi być 0 ) | (Żaden) | null wartość odniesienia |
VALUE_BOOLEAN | 0x1f | wartość logiczna (0…1) | (Żaden) | wartość jednobitowa; 0 dla false i 1 dla true . Bit jest reprezentowany w value_arg . |
encoded_array format
Nazwa | Format | Opis |
---|---|---|
rozmiar | uleb128 | liczba elementów w tablicy |
wartości | zakodowana_wartość[rozmiar] | seria sekwencji bajtów o size encoded_value w formacie określonym w tej sekcji, połączonych sekwencyjnie. |
format encoded_adnotation
Nazwa | Format | Opis |
---|---|---|
type_idx | uleb128 | typ adnotacji. Musi to być typ klasy (nie tablica lub prymitywny). |
rozmiar | uleb128 | liczba odwzorowań nazwa-wartość w tej adnotacji |
elementy | element_adnotacji[rozmiar] | elementy adnotacji, reprezentowane bezpośrednio w linii (nie jako przesunięcia). Elementy muszą być posortowane w kolejności rosnącej według indeksu string_id . |
format elementu adnotacji
Nazwa | Format | Opis |
---|---|---|
nazwa_idx | uleb128 | nazwa elementu, reprezentowana jako indeks w sekcji string_ids . Ciąg musi być zgodny ze składnią MemberName , zdefiniowaną powyżej. |
wartość | zakodowana_wartość | wartość elementu |
Składnia ciągów
W pliku .dex
istnieje kilka rodzajów elementów, które ostatecznie odnoszą się do ciągu. Poniższe definicje w stylu BNF wskazują akceptowalną składnię tych ciągów.
Prosta nazwa
SimpleName jest podstawą składni nazw innych rzeczy. Format .dex
pozwala na dużą swobodę geograficzną (znacznie większą niż większość popularnych języków źródłowych). W skrócie, prosta nazwa składa się z dowolnego znaku lub cyfry o niskim ASCII, kilku określonych symboli o niskim ASCII i większości punktów kodowych innych niż ASCII, które nie są znakami kontrolnymi, spacją ani znakami specjalnymi. Począwszy od wersji 040
format dodatkowo dopuszcza znaki spacji (kategoria Unicode Zs
). Należy zauważyć, że zastępcze punkty kodowe (w zakresie U+d800
… U+dfff
) nie są uważane za prawidłowe znaki nazwy per se, ale znaki uzupełniające Unicode są prawidłowe (które są reprezentowane przez ostatnią alternatywę reguły dla SimpleNameChar ) i powinny być reprezentowane w pliku jako pary zastępczych punktów kodowych w kodowaniu MUTF-8.
Prosta nazwa → | ||
SimpleNameChar ( SimpleNameChar )* | ||
ProstaNazwaChar → | ||
'A' … 'Z' | ||
| | 'a' … 'z' | |
| | '0' … '9' | |
| | ' ' | od wersji DEX 040 |
| | '$' | |
| | '-' | |
| | '_' | |
| | U+00a0 | od wersji DEX 040 |
| | U+00a1 … U+1fff | |
| | U+2000 … U+200a | od wersji DEX 040 |
| | U+2010 … U+2027 | |
| | U+202f | od wersji DEX 040 |
| | U+2030 … U+d7ff | |
| | U+e000 … U+ffef | |
| | U+10000 … U+10ffff |
Nazwa członka
używane przez field_id_item i method_id_item
MemberName to nazwa członka klasy, której członkami są pola, metody i klasy wewnętrzne.
Nazwa Członka → | |
Prosta nazwa | |
| | '<' Prosta nazwa '>' |
Pełna nazwa klasy
FullClassName to w pełni kwalifikowana nazwa klasy, zawierająca opcjonalny specyfikator pakietu, po którym następuje wymagana nazwa.
Pełna nazwa klasy → | |
Opcjonalny przedrostek pakietu Prosta nazwa | |
OpcjonalnyPrefiksPakietu → | |
( Prosta nazwa '/' )* |
TypDescriptor
używane przez type_id_item
TypeDescriptor jest reprezentacją dowolnego typu, w tym prymitywów, klas, tablic i void
. Zobacz poniżej znaczenie różnych wersji.
TypDescriptor → | |
'V' | |
| | Deskryptor typu pola |
Deskryptor typu pola → | |
NonArrayFieldTypeDescriptor | |
| | ( '[' * 1…255) NonArrayFieldTypeDescriptor |
NonArrayFieldTypeDescriptor → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' NazwaPełnejKlasy ';' |
ShortyDescriptor
używany przez proto_id_item
ShortyDescriptor jest krótką reprezentacją prototypu metody, w tym typów zwracanych i parametrów, z wyjątkiem tego, że nie ma rozróżnienia między różnymi typami referencyjnymi (klasami lub tablicami). Zamiast tego wszystkie typy odwołań są reprezentowane przez pojedynczy znak 'L'
.
Krótki opis → | |
ShortyReturnType ( ShortyFieldType )* | |
ShortyReturnType → | |
'V' | |
| | ShortyFieldType |
ShortyFieldType → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' |
TypeDescriptor Semantics
Takie jest znaczenie każdego z wariantów TypeDescriptor .
Składnia | Oznaczający |
---|---|
V | void ; ważne tylko dla typów zwrotów |
Z | boolean |
B | byte |
S | short |
C | char |
I | int |
J | long |
F | float |
D | double |
L w pełni/kwalifikowany/Nazwa ; | klasa w fully.qualified.Name |
[ deskryptor | tablica descriptor , używana rekurencyjnie dla tablic tablic, chociaż niepoprawne jest posiadanie więcej niż 255 wymiarów. |
Przedmioty i powiązane struktury
Ta sekcja zawiera definicje dla każdego elementu najwyższego poziomu, który może pojawić się w pliku .dex
.
pozycja_nagłówka
pojawia się w sekcji nagłówka
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
magia | ubyte[8] = DEX_FILE_MAGIC | magiczna wartość. Zobacz dyskusję powyżej w " DEX_FILE_MAGIC ", aby uzyskać więcej informacji. |
suma kontrolna | nieskończoność | suma kontrolna adler32 reszty pliku (wszystko oprócz magic i tego pola); używany do wykrywania uszkodzeń plików |
podpis | ubajt[20] | podpis SHA-1 (hash) reszty pliku (wszystko oprócz magic , checksum i tego pola); używane do jednoznacznej identyfikacji plików |
rozmiar pliku | nieskończoność | rozmiar całego pliku (łącznie z nagłówkiem), w bajtach |
rozmiar_nagłówka | jednostka = 0x70 | rozmiar nagłówka (całej sekcji), w bajtach. Pozwala to na co najmniej ograniczoną zgodność wstecz/do przodu bez unieważniania formatu. |
endian_tag | uint = ENDIAN_CONSTANT | tag endianowości. Zobacz dyskusję powyżej w sekcji „ ENDIAN_CONSTANT i REVERSE_ENDIAN_CONSTANT ”, aby uzyskać więcej informacji. |
link_size | nieskończoność | rozmiar sekcji linków lub 0 , jeśli plik nie jest połączony statycznie |
link_off | nieskończoność | przesunięcie od początku pliku do sekcji łącza lub 0 , jeśli link_size == 0 . Przesunięcie, jeśli jest niezerowe, powinno być przesunięciem w sekcji link_data . Format wskazanych danych pozostaje nieokreślony w tym dokumencie; to pole nagłówka (i poprzednie) są pozostawione jako zaczepy do użycia przez implementacje środowiska uruchomieniowego. |
map_off | nieskończoność | przesunięcie od początku pliku do elementu mapy. Przesunięcie, które musi być niezerowe, powinno być przesunięciem w sekcji data , a dane powinny być w formacie określonym przez „ map_list ” poniżej. |
string_ids_size | nieskończoność | liczba ciągów na liście identyfikatorów ciągów |
string_ids_off | nieskończoność | przesunięcie od początku pliku do listy identyfikatorów łańcuchów, lub 0 , jeśli string_ids_size == 0 (co prawda dziwny przypadek na krawędzi). Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji string_ids . |
type_ids_size | nieskończoność | liczba elementów na liście identyfikatorów typu, maksymalnie 65535 |
type_ids_off | nieskończoność | przesunięcie od początku pliku do listy identyfikatorów typów, lub 0 , jeśli type_ids_size == 0 (co prawda dziwny przypadek krawędzi). Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji type_ids . |
proto_ids_size | nieskończoność | liczba elementów na liście identyfikatorów prototypów, maksymalnie 65535 |
proto_ids_off | nieskończoność | przesunięcie od początku pliku do listy identyfikatorów prototypów, lub 0 , jeśli proto_ids_size == 0 (co prawda dziwny przypadek krawędzi). Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji proto_ids . |
field_ids_size | nieskończoność | liczba elementów na liście identyfikatorów pól |
field_ids_off | nieskończoność | przesunięcie od początku pliku do listy identyfikatorów pól lub 0 , jeśli field_ids_size == 0 . Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji field_ids . |
method_ids_size | nieskończoność | liczba elementów na liście identyfikatorów metod |
method_ids_off | nieskończoność | przesunięcie od początku pliku do listy identyfikatorów metod lub 0 , jeśli method_ids_size == 0 . Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji method_ids . |
class_defs_size | nieskończoność | liczba elementów na liście definicji klas |
class_defs_off | nieskończoność | przesunięcie od początku pliku do listy definicji klas, lub 0 , jeśli class_defs_size == 0 (co prawda dziwny przypadek krawędzi). Przesunięcie, jeśli jest niezerowe, powinno być na początku sekcji class_defs . |
rozmiar_danych | nieskończoność | Rozmiar sekcji data w bajtach. Musi być parzystą wielokrotnością sizeof(uint). |
data_off | nieskończoność | przesunięcie od początku pliku do początku sekcji data . |
lista_map
pojawia się w sekcji danych
odwołuje się do pozycji header_item
wyrównanie: 4 bajty
To jest lista całej zawartości pliku, w kolejności. Zawiera pewną nadmiarowość w odniesieniu do elementu header_item
, ale ma być łatwym do użycia formularzem do iteracji całego pliku. Dany typ musi pojawić sięna mapie co najwyżej raz, ale nie ma ograniczeń co do kolejności, w jakiej mogą pojawić się typy, poza ograniczeniami wynikającymi z reszty formatu (np. sekcja header
musi pojawić się jako pierwsza, a następnie string_ids
sekcja itp.). Dodatkowo wpisy mapy muszą być uporządkowane według początkowego przesunięcia i nie mogą się nakładać.
Nazwa | Format | Opis |
---|---|---|
rozmiar | nieskończoność | wielkość listy, we wpisach |
lista | element_mapy[rozmiar] | elementy listy |
format elementu mapy
Nazwa | Format | Opis |
---|---|---|
rodzaj | skrócić | rodzaj przedmiotów; Zobacz tabelę poniżej |
nie używany | skrócić | (nie używany) |
rozmiar | nieskończoność | liczba sztuk do znalezienia we wskazanym offsecie |
zrównoważyć | nieskończoność | przesunięcie od początku pliku do elementów, o których mowa |
Kody typu
Typ przedmiotu | Stały | Wartość | Rozmiar elementu w bajtach |
---|---|---|---|
pozycja_nagłówka | 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 |
lista_map | TYPE_MAP_LIST | 0x1000 | 4 + (element.rozmiar * 12) |
lista_typów | TYPE_TYPE_LIST | 0x1001 | 4 + (element.rozmiar * 2) |
annotation_set_ref_list | TYPE_ANNOTATION_SET_REF_LIST | 0x1002 | 4 + (element.rozmiar * 4) |
annotation_set_item | TYPE_ANNOTATION_SET_ITEM | 0x1003 | 4 + (element.rozmiar * 4) |
class_data_item | TYPE_CLASS_DATA_ITEM | 0x2000 | domniemany; musi parsować |
kod_elementu | TYPE_CODE_ITEM | 0x2001 | domniemany; musi parsować |
string_data_item | TYPE_STRING_DATA_ITEM | 0x2002 | domniemany; musi parsować |
debug_info_item | TYPE_DEBUG_INFO_ITEM | 0x2003 | domniemany; musi parsować |
adnotation_item | TYPE_ANNOTATION_ITEM | 0x2004 | domniemany; musi parsować |
encoded_array_item | TYPE_ENCODED_ARRAY_ITEM | 0x2005 | domniemany; musi parsować |
annotations_directory_item | TYPE_ANNOTATIONS_DIRECTORY_ITEM | 0x2006 | domniemany; musi parsować |
hiddenapi_class_data_item | TYPE_HIDDENAPI_CLASS_DATA_ITEM | 0xF000 | domniemany; musi parsować |
string_id_item
pojawia się w sekcji string_ids
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
string_data_off | nieskończoność | przesunięcie od początku pliku do danych ciągu dla tej pozycji. Przesunięcie powinno dotyczyć lokalizacji w sekcji data , a dane powinny być w formacie określonym przez „ string_data_item ” poniżej. Nie ma wymogu wyrównania dla odsunięcia. |
string_data_item
pojawia się w sekcji danych
wyrównanie: brak (wyrównane do bajtów)
Nazwa | Format | Opis |
---|---|---|
utf16_rozmiar | uleb128 | rozmiar tego ciągu w jednostkach kodu UTF-16 (co jest „długością ciągu” w wielu systemach). Oznacza to, że jest to zdekodowana długość ciągu. (Zakodowana długość jest implikowana przez pozycję bajtu 0 ). |
dane | ubajt[] | seria jednostek kodu MUTF-8 (aka oktety, aka bajty), po których następuje bajt o wartości 0 . Zobacz "MUTF-8 (Zmodyfikowane kodowanie UTF-8)" powyżej, aby uzyskać szczegółowe informacje i dyskusję na temat formatu danych. Uwaga: Dopuszczalne jest posiadanie ciągu, który zawiera (w zakodowanej formie) jednostki kodu zastępczego UTF-16 (tj. |
type_id_item
pojawia się w sekcji type_ids
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
deskryptor_idx | nieskończoność | indeks do listy string_ids dla ciągu deskryptora tego typu. Ciąg musi być zgodny ze składnią TypeDescriptor , zdefiniowaną powyżej. |
proto_id_item
pojawia się w sekcji proto_ids
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
shorty_idx | nieskończoność | indeks do listy string_ids dla krótkiego łańcucha deskryptora tego prototypu. Ciąg znaków musi być zgodny ze składnią ShortyDescriptor zdefiniowaną powyżej i musi odpowiadać typowi zwracanemu i parametrom tego elementu. |
return_type_idx | nieskończoność | indeks do listy type_ids dla zwracanego typu tego prototypu |
parametry_wyłączone | nieskończoność | przesunięcie od początku pliku do listy typów parametrów dla tego prototypu lub 0 , jeśli ten prototyp nie ma parametrów. To przesunięcie, jeśli nie jest zerowe, powinno znajdować się w sekcji data , a dane powinny być w formacie określonym przez "type_list" poniżej. Dodatkowo na liście nie powinno być odniesienia do typu void . |
field_id_item
pojawia się w sekcji field_ids
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
class_idx | skrócić | indeks do listy type_ids dla definiującego to pole. Musi to być typ klasy, a nie tablica lub typ pierwotny. |
type_idx | skrócić | indeks do listy type_ids typów dla typu tego pola |
nazwa_idx | nieskończoność | indeks do listy string_ids dla nazwy tego pola. Ciąg musi być zgodny ze składnią MemberName , zdefiniowaną powyżej. |
method_id_item
pojawia się w sekcji identyfikatory metod
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
class_idx | skrócić | indeks do listy type_ids dla definiującego tę metodę. Musi to być typ klasy lub tablicy, a nie typ pierwotny. |
proto_idx | skrócić | indeks do listy proto_ids dla prototypu tej metody |
nazwa_idx | nieskończoność | indeks do listy string_ids dla nazwy tej metody. Ciąg musi być zgodny ze składnią MemberName , zdefiniowaną powyżej. |
class_def_item
pojawia się w sekcji class_defs
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
class_idx | nieskończoność | indeks do listy type_ids dla tej klasy. Musi to być typ klasy, a nie tablica lub typ pierwotny. |
flagi_dostępu | nieskończoność | flagi dostępu dla klasy ( public , final , itp.). Więcej informacji można znaleźć w „Definicjach access_flags ”. |
superclass_idx | nieskończoność | indeks do listy type_ids dla nadklasy lub stałą wartość NO_INDEX , jeśli ta klasa nie ma nadklasy (tj. jest klasą główną, taką jak Object ). Jeśli jest obecny, musi to być typ klasy, a nie tablica lub typ pierwotny. |
interfejsy_wyłączone | nieskończoność | przesunięcie od początku pliku do listy interfejsów lub 0 , jeśli ich nie ma. To przesunięcie powinno znajdować się w sekcji data , a dane tam powinny być w formacie określonym przez " type_list " poniżej. Każdy z elementów listy musi być typem klasy (nie tablicą ani typem pierwotnym) i nie może być żadnych duplikatów. |
source_file_idx | nieskończoność | indeks do listy string_ids dla nazwy pliku zawierającego oryginalne źródło (przynajmniej większości) tej klasy lub specjalną wartość NO_INDEX reprezentującą brak tych informacji. Element debug_info_item dowolnej metody może przesłonić ten plik źródłowy, ale oczekuje się, że większość klas będzie pochodzić tylko z jednego pliku źródłowego. |
adnotacje_wyłączone | nieskończoność | przesunięcie od początku pliku do struktury adnotacji dla tej klasy lub 0 , jeśli nie ma adnotacji w tej klasie. To przesunięcie, jeśli jest niezerowe, powinno znajdować się w sekcji data , a dane tam powinny być w formacie określonym poniżej przez " annotations_directory_item " ze wszystkimi elementami odwołującymi się do tej klasy jako definiującym. |
class_data_off | nieskończoność | przesunięcie od początku pliku do skojarzonych danych klasy dla tej pozycji lub 0 , jeśli nie ma danych klasy dla tej klasy. (Może tak być, na przykład, jeśli ta klasa jest interfejsem znacznika.) Przesunięcie, jeśli jest niezerowe, powinno znajdować się w sekcji data , a dane tam powinny być w formacie określonym przez " class_data_item " poniżej, ze wszystkimi elementami odnoszącymi się do tej klasy jako definiującym. |
statyczne_wartości_wyłączone | nieskończoność | przesunięcie od początku pliku do listy wartości początkowych dla pól static lub 0 , jeśli ich nie ma (a wszystkie pola static mają być inicjowane wartością 0 lub null ). Przesunięcie to powinno znajdować się w sekcji data , a dane powinny być w formacie określonym poniżej w polu „ encoded_array_item ”. Rozmiar tablicy nie może być większy niż liczba pól static zadeklarowanych przez tę klasę, a elementy odpowiadają polom static w tej samej kolejności, co zadeklarowana w odpowiednim field_list . Typ każdego elementu tablicy musi być zgodny z zadeklarowanym typem odpowiadającego mu pola. Jeśli w tablicy jest mniej elementów niż pól static , pozostałe pola są inicjowane przy użyciu odpowiedniego dla typu 0 lub null . |
call_site_id_item
pojawia się w sekcji call_site_ids
wyrównanie: 4 bajty
Nazwa | Format | Opis |
---|---|---|
call_site_off | nieskończoność | przesunięcie od początku pliku, aby wywołać definicję witryny. Przesunięcie powinno znajdować się w sekcji danych, a dane powinny być w formacie określonym poniżej przez „call_site_item”. |
call_site_item
pojawia się w sekcji danych
wyrównanie: brak (wyrównanie do bajtów)
Call_site_item to encoded_array_item, którego elementy odpowiadają argumentom dostarczonym do metody konsolidatora ładowania początkowego. Pierwsze trzy argumenty to:
- Uchwyt metody reprezentujący metodę konsolidatora ładowania początkowego (VALUE_METHOD_HANDLE).
- Nazwa metody, którą konsolidator ładowania początkowego powinien rozwiązać (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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
size | uint | size of the list, in entries |
list | type_item[size] | elements of the list |
type_item format
Name | Format | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
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 | Opis |
---|---|---|
value | Class[] | the array of exception types thrown |