פורמט הפעלה של Dalvik

מסמך זה מתאר את הפריסה והתוכן של קובצי .dex , המשמשים לשמירה על קבוצה של הגדרות מחלקות ונתוני נלווים הקשורים אליהן.

מדריך לסוגים

שֵׁם תיאור
בייט 8 סיביות חתומות
ubyte 8-bit unsigned int
קצר 16-bit חתום int, little-endian
קצר 16-bit unsigned int, little-endian
int 32-bit חתום int, little-endian
uint 32-bit unsigned int, little-endian
ארוך 64-bit חתום int, little-endian
ulong int 64 סיביות לא חתום, little-endian
sleb128 חתום LEB128, באורך משתנה (ראה להלן)
uleb128 LEB128 לא חתום, באורך משתנה (ראה להלן)
uleb128p1 LEB128 פלוס 1 ללא חתימה, באורך משתנה (ראה להלן)

LEB128

LEB128 (" L ittle- En ndian B ase 128 ") הוא קידוד באורך משתנה עבור כמויות שלמים בחתימה שרירותית או ללא סימן. הפורמט הושאל ממפרט DWARF3 . בקובץ .dex , LEB128 משמש רק לקידוד כמויות של 32 סיביות.

כל ערך מקודד LEB128 מורכב מאחד עד חמישה בתים, המייצגים יחד ערך בודד של 32 סיביות. לכל בייט יש את הסיביות המשמעותיות ביותר שלו פרט לבייט הסופי ברצף, שהסיביות המשמעותית ביותר שלו ברורה. שבעת הסיביות הנותרות של כל בייט הן מטען, כאשר שבעת הסיביות הפחות משמעותיות של הכמות בבייט הראשון, שבעת הבאות בבייט השני וכן הלאה. במקרה של LEB128 חתום ( sleb128 ), סיבית המטען המשמעותית ביותר של הבית הסופי ברצף מורחב בסימן כדי לייצר את הערך הסופי. במקרה הבלתי חתום ( uleb128 ), כל סיביות שאינן מיוצגות במפורש מתפרשות כ 0 .

דיאגרמת סיביות של ערך LEB128 של שני בתים
בייט ראשון בייט שני
1 סיביות 6 סיביות 5 סיביות 4 סיביות 3 ביט 2 סיביות 1 ביט 0 0 סיביות 13 סיביות 12 סיביות 11 סיביות 10 סיביות 9 סיביות 8 סיביות 7

הגרסה uleb128p1 משמשת לייצוג ערך בסימן, כאשר הייצוג הוא של הערך פלוס אחד המקודד כ- uleb128 . זה הופך את הקידוד של -1 (לחילופין נחשב כערך ללא 0xffffffff ) - אבל שום מספר שלילי אחר - לבייט בודד, והוא שימושי בדיוק באותם מקרים שבהם המספר המיוצג חייב להיות לא שלילי או -1 (או 0xffffffff ), ושם לא מותרים ערכים שליליים אחרים (או כאשר לא סביר שיהיה צורך בערכים גדולים ללא סימנים).

להלן כמה דוגמאות לפורמטים:

רצף מקודד בתור sleb128 בתור uleb128 בתור uleb128p1
00 0 0 -1
01 1 1 0
-1 127 126
80 7f -128 16256 16255

פריסת קובץ

שֵׁם פוּרמָט תיאור
כּוֹתֶרֶת header_item הכותרת
string_ids string_id_item[] רשימת מזהי מחרוזת. אלו הם מזהים עבור כל המחרוזות המשמשות את הקובץ הזה, או למתן שמות פנימיים (למשל, מתארי סוג) או כאובייקטים קבועים שמתייחסים אליהם בקוד. רשימה זו חייבת להיות ממוינת לפי תוכן מחרוזת, תוך שימוש בערכי נקודת קוד UTF-16 (לא באופן רגיש לאזור), ואין לה להכיל ערכים כפולים.
type_ID type_id_item[] רשימת מזהי סוגים. אלו הם מזהים לכל הסוגים (מחלקות, מערכים או טיפוסים פרימיטיביים) אליהם מתייחס הקובץ הזה, בין אם הם מוגדרים בקובץ ובין אם לא. רשימה זו חייבת להיות ממוינת לפי string_id index, והיא לא יכולה להכיל ערכים כפולים.
proto_ids proto_id_item[] רשימת מזהי אב טיפוס של שיטה. אלו הם מזהים עבור כל אבות הטיפוס שאליהם הקובץ הזה מתייחס. יש למיין רשימה זו בסדר עיקרי מסוג החזרה (לפי type_id index), ולאחר מכן לפי רשימת ארגומנטים (סדר לקסיקוגרפי, ארגומנטים בודדים מסודרים לפי אינדקס type_id ). אסור שהרשימה תכיל ערכים כפולים.
field_ids field_id_item[] רשימת מזהי שדות. אלו הם מזהים לכל השדות אליהם מתייחס הקובץ הזה, בין אם הם מוגדרים בקובץ ובין אם לא. יש למיין את הרשימה הזו, כאשר הסוג המגדיר (לפי type_id index) הוא הסדר הראשי, שם השדה (לפי string_id index) הוא סדר הביניים, ו-type (by type_id index) הוא הסדר המינורי. אסור שהרשימה תכיל ערכים כפולים.
method_ids method_id_item[] רשימת מזהי שיטה. אלו הם מזהים לכל השיטות שהקובץ הזה מתייחס אליהן, בין אם מוגדרות בקובץ ובין אם לא. יש למיין את הרשימה הזו, כאשר הסוג המגדיר (לפי type_id index) הוא הסדר הראשי, שם השיטה (לפי string_id index) הוא סדר הביניים, ואב הטיפוס של השיטה (לפי מדד proto_id ) הוא הסדר המינורי. אסור שהרשימה תכיל ערכים כפולים.
class_defs class_def_item[] רשימת הגדרות מחלקה. יש לסדר את המחלקות כך שמחלקת העל והממשקים המיושמים של מחלקה נתונה יופיעו ברשימה לפני המחלקה המפנה. יתר על כן, אין תוקף להגדרה של מחלקה בעלת שם זהה להופיע יותר מפעם אחת ברשימה.
call_site_ids call_site_id_item[] רשימת מזהי אתרים להתקשר. אלו הם מזהים עבור כל אתרי השיחות שאליהם מתייחס קובץ זה, בין אם מוגדרים בקובץ ובין אם לא. יש למיין רשימה זו בסדר עולה של call_site_off .
method_handles method_handle_item[] רשימת מטפלים בשיטה. רשימה של כל נקודות האחיזה של השיטה שהקובץ הזה מתייחס אליהן, בין אם מוגדרות בקובץ ובין אם לא. רשימה זו אינה ממוינת ועשויה להכיל כפילויות אשר יתאימו באופן הגיוני למופעי טיפול שונים בשיטה.
נתונים ubyte[] אזור הנתונים, המכיל את כל נתוני התמיכה לטבלאות המפורטות למעלה. לפריטים שונים יש דרישות יישור שונות, ובתי ריפוד מוכנסים לפני כל פריט במידת הצורך כדי להשיג יישור נכון.
link_data ubyte[] נתונים המשמשים בקבצים מקושרים סטטית. פורמט הנתונים בסעיף זה אינו מצוין במסמך זה. קטע זה ריק בקבצים לא מקושרים, ויישומי זמן ריצה עשויים להשתמש בו כראות עיניהם.

Bitfield, מחרוזת והגדרות קבועות

DEX_FILE_MAGIC

מוטבע ב-header_item

המערך/מחרוזת DEX_FILE_MAGIC היא רשימת הבתים שחייבים להופיע בתחילת קובץ .dex כדי שיוכר ככזה. הערך מכיל בכוונה שורה חדשה ( "\n" או 0x0a ) ובית null ( "\0" או 0x00 ) על מנת לסייע באיתור צורות מסוימות של שחיתות. הערך גם מקודד מספר גרסת פורמט כשלוש ספרות עשרוניות, שצפוי לעלות באופן מונוטוני עם הזמן ככל שהפורמט יתפתח.

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

הערה: תמיכה בגרסה 039 של הפורמט נוספה במהדורת אנדרואיד 9.0, שהציגה שני קודי בתים חדשים, const-method-handle ו- const-method-type . (כל אחד מהם מתואר בטבלת סיכום של ערכת קוד בתים .) באנדרואיד 10, גרסה 039 מרחיבה את פורמט קובץ ה-DEX כך שיכלול מידע API מוסתר שמתאים רק לקבצי DEX בנתיב מחלקת האתחול.

הערה: תמיכה בגרסה 038 של הפורמט נוספה במהדורת אנדרואיד 8.0. גרסה 038 הוסיפה בתים-קודים חדשים ( invoke-polymorphic ו- invoke-custom ) ונתונים עבור נקודות אחיזה של השיטה.

הערה: תמיכה בגרסה 037 של הפורמט נוספה במהדורת אנדרואיד 7.0. לפני גרסה 037 רוב הגרסאות של אנדרואיד השתמשו בגרסה 035 של הפורמט. ההבדל היחיד בין גרסאות 035 ו 037 הוא הוספת שיטות ברירת המחדל והתאמת ה- invoke .

הערה: לפחות כמה גרסאות קודמות של הפורמט שימשו במהדורות תוכנה ציבוריות זמינות. לדוגמה, גרסה 009 שימשה עבור מהדורות M3 של פלטפורמת אנדרואיד (נובמבר–דצמבר 2007), וגרסה 013 שימשה עבור מהדורות M5 של פלטפורמת אנדרואיד (פברואר–מרץ 2008). מכמה בחינות, גרסאות קודמות אלה של הפורמט שונות באופן משמעותי מהגרסה המתוארת במסמך זה.

ENDIAN_CONSTANT ו-REVERSE_ENDIAN_CONSTANT

מוטבע ב-header_item

הקבוע ENDIAN_CONSTANT משמש לציון הקצה של הקובץ שבו הוא נמצא. למרות שפורמט ה-. .dex הסטנדרטי הוא מעט נדיאני, יישומים עשויים לבחור לבצע החלפת בתים. אם יישום יתקל בכותרת שה- endian_tag שלה הוא REVERSE_ENDIAN_CONSTANT במקום ENDIAN_CONSTANT , הוא יידע שהקובץ הוחלף בתים מהצורה הצפויה.

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

NO_INDEX

מוטבע ב-class_def_item וב-debug_info_item

הקבוע NO_INDEX משמש לציון שערך אינדקס חסר.

הערה: ערך זה אינו מוגדר כ 0 , כי זה למעשה אינדקס חוקי.

הערך הנבחר עבור NO_INDEX ניתן לייצוג כבייט בודד בקידוד uleb128p1 .

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

הגדרות access_flags

מוטבע ב-class_def_item, encoded_field, encoded_method ו-InnerClass

שדות סיביות של דגלים אלה משמשים לציון הנגישות והמאפיינים הכוללים של מחלקות וחברי כיתה.

שֵׁם ערך לשיעורים (והערות InnerClass ) עבור שדות עבור שיטות
ACC_PUBLIC 0x1 public : גלוי בכל מקום public : גלוי בכל מקום public : גלוי בכל מקום
ACC_PRIVATE 0x2 * private : גלוי רק להגדרת המחלקה private : גלוי רק להגדרת המחלקה private : גלוי רק להגדרת המחלקה
ACC_PROTECTED 0x4 * protected : גלוי לחבילה ותתי מחלקות protected : גלוי לחבילה ותתי מחלקות protected : גלוי לחבילה ותתי מחלקות
ACC_STATIC 0x8 * static : אינו בנוי עם אסמכתא חיצונית this static : מחלקה גלובלית עד מגדירה static : לא לוקח this
ACC_FINAL 0x10 final : לא ניתן לסיווג משנה final : בלתי משתנה לאחר הבנייה final : לא ניתן לעקוף
ACC_SYNCHRONIZED 0x20 synchronized : מנעול משויך נרכש אוטומטית סביב קריאה לשיטה זו.

הערה: זה תקף להגדרה רק כאשר ACC_NATIVE מוגדר גם.

ACC_VOLATILE 0x40 volatile : כללי גישה מיוחדים כדי לסייע בבטיחות החוטים
ACC_BRIDGE 0x40 שיטת גשר, נוספה אוטומטית על ידי מהדר כגשר בטוח מסוג
ACC_TRANSIENT 0x80 transient : לא להישמר כברירת מחדל
ACC_VARARGS 0x80 יש להתייחס לארגומנט האחרון כאל ארגומנט "מנוחה" על ידי המהדר
ACC_NATIVE 0x100 native : מיושם בקוד מקורי
ACC_INTERFACE 0x200 interface : מחלקה מופשטת הניתנת ליישום כפול
ACC_ABSTRACT 0x400 abstract : לא ניתן לזיהוי ישיר abstract : לא מיושם על ידי מחלקה זו
ACC_STRICT 0x800 strictfp : כללים נוקשים לאריתמטיקה של נקודה צפה
ACC_SYNTHETIC 0x1000 לא מוגדר ישירות בקוד המקור לא מוגדר ישירות בקוד המקור לא מוגדר ישירות בקוד המקור
ACC_ANNOTATION 0x2000 הוכרז כמעמד ביאור
ACC_ENUM 0x4000 הוכרז כסוג מסופר הוכרז כערך מסופר
(לא בשימוש) 0x8000
ACC_CONSTRUCTOR 0x10000 שיטת בנאי (מאתחל מחלקה או מופע)
ACC_DECLARED_
מסונכרן
0x20000 הוכרז synchronized .

הערה: אין לכך השפעה על הביצוע (מלבד בשיקוף של דגל זה, כשלעצמו).

* מותר לפעול רק עבור הערות InnerClass , ואסור להפעיל אותו לעולם ב- class_def_item .

קידוד MUTF-8 (שינוי UTF-8).

כוויתור לתמיכה קלה יותר מדור קודם, פורמט ה-. .dex מקודד את נתוני המחרוזת שלו בצורת UTF-8 מתוקנת דה-פקטו, להלן MUTF-8. טופס זה זהה ל-UTF-8 הסטנדרטי, למעט:

  • נעשה שימוש רק בקידוד של אחד, שניים ושלושה בתים.
  • נקודות קוד בטווח U+10000U+10ffff מקודדות כזוג פונדקאות, שכל אחת מהן מיוצגת כערך מקודד של שלושה בתים.
  • נקודת הקוד U+0000 מקודדת בצורת שני בתים.
  • בית null רגיל (ערך 0 ) מציין את סוף המחרוזת, וכך גם הפירוש הסטנדרטי של שפת C.

ניתן לסכם את שני הפריטים הראשונים לעיל כך: MUTF-8 הוא פורמט קידוד עבור UTF-16, במקום להיות פורמט קידוד ישיר יותר עבור תווי Unicode.

שני הפריטים האחרונים לעיל מאפשרים בו זמנית לכלול את נקודת הקוד U+0000 במחרוזת ועדיין לתפעל אותה כמחרוזת עם סיומת אפס בסגנון C.

עם זאת, הקידוד המיוחד של U+0000 אומר שבניגוד ל-UTF-8 רגיל, התוצאה של קריאה לפונקציית C הסטנדרטית strcmp() על זוג מחרוזות MUTF-8 לא תמיד מציינת את התוצאה החתומה כהלכה של השוואה של מחרוזות לא שוות . כאשר סדר (לא רק שוויון) הוא דאגה, הדרך הפשוטה ביותר להשוות מחרוזות MUTF-8 היא לפענח אותן תו אחר תו, ולהשוות בין הערכים המפוענחים. (עם זאת, אפשר גם יישומים חכמים יותר.)

אנא עיין ב- Unicode Standard לקבלת מידע נוסף על קידוד תווים. MUTF-8 למעשה קרוב יותר לקידוד CESU-8 (הפחות מוכר יחסית) מאשר ל-UTF-8 כשלעצמו.

קידוד encoded_value

מוטבע ב-annotation_element וב-encoded_array_item

encoded_value הוא חלק מקודד של נתונים (כמעט) שרירותיים במבנה היררכי. הקידוד נועד להיות גם קומפקטי וגם פשוט לניתוח.

שֵׁם פוּרמָט תיאור
(value_arg << 5) | סוג_ערך ubyte בייט המציין את סוג value מיד לאחר מכן יחד עם ארגומנט הבהרה אופציונלי בשלושת הסיביות בסדר גבוה. ראה להלן את הגדרות value השונות. ברוב המקרים, value_arg מקודד את אורך value הבא מיד בבתים, שכן (size - 1) , למשל, 0 אומר שהערך דורש בית אחד, ו 7 אומר שהוא דורש שמונה בתים; עם זאת, ישנם חריגים כפי שצוין להלן.
ערך ubyte[] בתים המייצגים את הערך, משתנה באורך ומתפרשים בצורה שונה עבור בתים value_type שונים, אם כי תמיד little-endian. עיין בהגדרות הערכים השונות להלן לפרטים.

פורמטים של ערך

סוג שם value_type value_arg פורמט value פורמט תיאור
VALUE_BYTE 0x00 (אין; חייב להיות 0 ) ubyte[1] ערך מספר שלם של בית אחד חתום
VALUE_SHORT 0x02 גודל - 1 (0...1) ubyte [גודל] ערך מספר שלם בסימן שני בתים, מורחב בסימן
VALUE_CHAR 0x03 גודל - 1 (0...1) ubyte [גודל] ערך מספר שלם של שני בתים ללא סימן, מורחב אפס
VALUE_INT 0x04 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים חתום, מורחב בסימן
VALUE_LONG 0x06 מידה - 1 (0…7) ubyte [גודל] ערך מספר שלם בסימן שמונה בתים, מורחב בסימן
VALUE_FLOAT 0x10 גודל - 1 (0...3) ubyte [גודל] דפוס סיביות של ארבעה בתים, מורחב אפס ימינה , ומתפרש כערך IEEE754 32 סיביות נקודה צפה
VALUE_DOUBLE 0x11 מידה - 1 (0…7) ubyte [גודל] תבנית סיביות של שמונה בתים, מורחבת אפס ימינה , ומתפרשת כערך IEEE754 64 סיביות נקודה צפה
VALUE_METHOD_TYPE 0x15 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס למקטע proto_ids ומייצג ערך מסוג שיטה
VALUE_METHOD_HANDLE 0x16 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), המתפרש כאינדקס לתוך המקטע method_handles ומייצג ערך טיפול של מתודה
VALUE_STRING 0x17 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס למקטע string_ids ומייצג ערך מחרוזת
VALUE_TYPE 0x18 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס בקטע type_ids ומייצג ערך סוג/מחלקה משקף
VALUE_FIELD 0x19 גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס בקטע field_ids ומייצג ערך שדה רפלקטיבי
VALUE_METHOD 0x1a גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס בקטע method_ids ומייצג ערך שיטה רפלקטיבי
VALUE_ENUM 0x1b גודל - 1 (0...3) ubyte [גודל] ערך מספר שלם של ארבעה בתים ללא סימן (מורחב אפס), מתפרש כאינדקס בקטע field_ids ומייצג את הערך של קבוע טיפוס שנמנה
VALUE_ARRAY 0x1c (אין; חייב להיות 0 ) מערך_מקודד מערך של ערכים, בפורמט המצוין ב-" encoded_array format" להלן. גודל value משתמע בקידוד.
VALUE_ANNOTATION 0x1d (אין; חייב להיות 0 ) ביאור_מקודד ביאור משנה, בפורמט המצוין ב-" encoded_annotation format" להלן. גודל value משתמע בקידוד.
VALUE_NULL 0x1e (אין; חייב להיות 0 ) (אף אחד) ערך הפניה null
VALUE_BOOLEAN 0x1f בוליאני (0…1) (אף אחד) ערך סיביות אחד; 0 עבור false ו 1 עבור true . הביט מיוצג ב- value_arg .

תבנית_encoded_array

שֵׁם פוּרמָט תיאור
גודל uleb128 מספר האלמנטים במערך
ערכים ערך_מקודד[גודל] סדרה של רצפי בתים size encoded_value בפורמט שצוין בסעיף זה, משורשרים ברצף.

תבנית_encoded_annotation

שֵׁם פוּרמָט תיאור
type_idx uleb128 סוג ההערה. זה חייב להיות סוג מחלקה (לא מערך או פרימיטיבי).
גודל uleb128 מספר מיפויי שם-ערך בהערה זו
אלמנטים annotation_element[size] אלמנטים של ההערה, המיוצגים ישירות בשורה (לא כהיסטים). יש למיין את האלמנטים בסדר הולך וגדל לפי אינדקס string_id .

annotation_element format

שֵׁם פוּרמָט תיאור
name_idx uleb128 שם האלמנט, המיוצג כאינדקס במקטע string_ids . המחרוזת חייבת להתאים לתחביר של MemberName , שהוגדר לעיל.
ערך ערך_מקודד ערך אלמנט

תחביר מחרוזת

ישנם מספר סוגים של פריטים בקובץ .dex שמתייחסים בסופו של דבר למחרוזת. ההגדרות הבאות בסגנון BNF מציינות את התחביר המקובל עבור מחרוזות אלו.

שם פשוט

A SimpleName הוא הבסיס לתחביר של שמות של דברים אחרים. פורמט ה-. .dex מאפשר כאן כמות נכבדת של קו רוחב (הרבה יותר משפות המקור הנפוצות ביותר). בקצרה, שם פשוט מורכב מכל תו או ספרה אלפביתית נמוכה ASCII, כמה סמלים ספציפיים עם ASCII נמוכה, ורוב נקודות הקוד שאינן ASCII שאינן בקרה, רווח או תווים מיוחדים. החל מגרסה 040 הפורמט מאפשר בנוסף תווי רווח (קטגוריית Unicode Zs ). שימו לב שנקודות קוד פונדקאיות (בטווח U+d800U+dfff ) אינן נחשבות לתווי שם חוקיים, כשלעצמם, אך תווים משלימים של Unicode תקפים (אשר מיוצגים על ידי החלופה הסופית של הכלל עבור SimpleNameChar ), והם צריך להיות מיוצג בקובץ כזוגות של נקודות קוד סרוגייט בקידוד MUTF-8.

שם פשוט
SimpleNameChar ( SimpleNameChar )*
SimpleNameChar
'A''Z'
| 'a''z'
| '0''9'
| ' ' מאז גירסת DEX 040
| '$'
| '-'
| '_'
| U+00a0 מאז גירסת DEX 040
| U+00a1U+1fff
| U+2000U+200a מאז גירסת DEX 040
| U+2010U+2027
| U+202f מאז גירסת DEX 040
| U+2030U+d7ff
| U+e000U+ffef
| U+10000U+10ffff

שם חבר

בשימוש על ידי field_id_item ו-method_id_item

MemberName הוא שמו של חבר בכיתה, החברים הם שדות, שיטות ומחלקות פנימיות.

שם חבר
שם פשוט
| '<' SimpleName '>'

FullClassName

FullClassName הוא שם מחלקה מלא, כולל מפרט חבילה אופציונלי ואחריו שם נדרש.

FullClassName
OptionalPackagePrefix SimpleName
OptionalPackagePrefix
( SimpleName '/' )*

TypeDescriptor

בשימוש על ידי type_id_item

TypeDescriptor הוא הייצוג של כל סוג, כולל פרימיטיבים, מחלקות, מערכים ו- void . ראה להלן את המשמעות של הגרסאות השונות.

TypeDescriptor
'V'
| FieldTypeDescriptor
FieldTypeDescriptor
NonArrayFieldTypeDescriptor
| ( '[' * 1...255) NonArrayFieldTypeDescriptor
NonArrayFieldTypeDescriptor
'Z'
| 'B'
| 'S'
| 'C'
| 'I'
| 'J'
| 'F'
| 'D'
| 'L' FullClassName ';'

ShortyDescriptor

בשימוש על ידי proto_id_item

ShortyDescriptor הוא ייצוג הצורה הקצרה של אב טיפוס של מתודה, כולל סוגי החזר ופרמטרים, אלא שאין הבחנה בין סוגי הפניות שונים (מחלקה או מערך). במקום זאת, כל סוגי ההפניה מיוצגים על ידי תו 'L' בודד.

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

סמנטיקה של TypeDescriptor

זוהי המשמעות של כל אחת מהווריאציות של TypeDescriptor .

תחביר מַשְׁמָעוּת
V void ; תקף רק לסוגי החזרות
ז boolean
ב byte
ס short
ג char
אני int
י long
ו float
ד double
L מלא/מוסמך/שם ; שם fully.qualified.Name
[ מתאר array of descriptor , שמיש באופן רקורסיבי עבור מערכים-של-מערכים, אם כי זה לא חוקי שיש יותר מ-255 ממדים.

פריטים ומבנים קשורים

סעיף זה כולל הגדרות עבור כל אחד מהפריטים ברמה העליונה שעשויים להופיע בקובץ .dex .

header_item

מופיע בסעיף הכותרת

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
קֶסֶם ubyte[8] = DEX_FILE_MAGIC ערך קסם. ראה דיון למעלה תחת " DEX_FILE_MAGIC " לפרטים נוספים.
סכום בדיקה uint adler32 checksum של שאר הקובץ (הכל מלבד magic והשדה הזה); משמש לזיהוי פגמים בקבצים
חֲתִימָה ubyte[20] חתימת SHA-1 (hash) של שאר הקובץ (הכל מלבד magic , checksum ושדה זה); משמש לזיהוי ייחודי של קבצים
גודל הקובץ uint גודל הקובץ כולו (כולל הכותרת), בבתים
header_size uint = 0x70 גודל הכותרת (כל הקטע הזה), בבתים. זה מאפשר לפחות כמות מוגבלת של תאימות אחורה/קדימה מבלי לבטל את תוקף הפורמט.
endian_tag uint = ENDIAN_CONSTANT תג קצה. ראה דיון למעלה תחת " ENDIAN_CONSTANT ו- REVERSE_ENDIAN_CONSTANT " לפרטים נוספים.
קישור_גודל uint גודל של קטע הקישור, או 0 אם קובץ זה אינו מקושר סטטית
link_off uint היסט מתחילת הקובץ למקטע הקישור, או 0 אם link_size == 0 . ההיסט, אם אינו אפס, צריך להיות להיסט בקטע link_data . הפורמט של הנתונים שעליו הצביע לא מצוין במסמך זה; שדה הכותרת הזה (והקודם) נשארים כ-hooks לשימוש על ידי יישומי זמן ריצה.
map_off uint היסט מתחילת הקובץ לפריט המפה. ההיסט, שעליו להיות לא-אפס, צריך להיות להיסט בקטע data , והנתונים צריכים להיות בפורמט שצוין על ידי " map_list " למטה.
string_ids_size uint ספירת המחרוזות ברשימת מזהי המחרוזות
string_ids_off uint היסט מתחילת הקובץ לרשימת מזהי המחרוזות, או 0 אם string_ids_size == 0 (אומנם מקרה קצה מוזר). ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע string_ids .
type_ID_size uint ספירת הרכיבים ברשימת מזהי הסוג, לכל היותר 65535
type_ids_off uint היסט מתחילת הקובץ לרשימת מזהי הסוג, או 0 אם type_ids_size == 0 (אומנם מקרה קצה מוזר). ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע type_ids .
proto_ids_size uint ספירת האלמנטים ברשימת מזהי אב הטיפוס, לכל היותר 65535
proto_ids_off uint היסט מתחילת הקובץ לרשימת מזהי אב הטיפוס, או 0 אם proto_ids_size == 0 (אומנם מקרה קצה מוזר). ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע proto_ids .
field_ids_size uint ספירת האלמנטים ברשימת מזהי השדות
field_ids_off uint היסט מתחילת הקובץ לרשימת מזהי השדות, או 0 אם field_ids_size == 0 . ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע field_ids .
method_ids_size uint ספירת האלמנטים ברשימת מזהי השיטה
method_ids_off uint היסט מתחילת הקובץ לרשימת מזהי השיטה, או 0 אם method_ids_size == 0 . ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע method_ids .
class_defs_size uint ספירת האלמנטים ברשימת הגדרות המחלקה
class_defs_off uint offset מתחילת הקובץ לרשימת הגדרות המחלקה, או 0 אם class_defs_size == 0 (אומנם מקרה קצה מוזר). ההיסט, אם אינו אפס, צריך להיות לתחילת הקטע class_defs .
גודל_נתונים uint גודל מקטע data בבתים. חייב להיות כפול זוגי של sizeof(uint).
data_off uint היסט מתחילת הקובץ לתחילת קטע data .

map_list

מופיע בסעיף הנתונים

הפניה מ-header_item

יישור: 4 בתים

זוהי רשימה של כל התוכן של קובץ, לפי הסדר. הוא מכיל יתירות מסוימת ביחס ל- header_item אך נועד להיות טופס קל לשימוש כדי לחזור על קובץ שלם. סוג נתון חייב להופיע לכל היותר פעם אחת במפה, אבל אין הגבלה באיזה סוגי סדר יכולים להופיע, מלבד ההגבלות המשתמעות משאר הפורמט (למשל, קטע header חייב להופיע קודם, ואחריו string_ids סעיף וכו'). בנוסף, יש לסדר את כניסות המפה לפי היסט ראשוני ואסור לחפוף.

שֵׁם פוּרמָט תיאור
גודל uint גודל הרשימה, בערכים
רשימה map_item [גודל] מרכיבי הרשימה

תבנית map_item

שֵׁם פוּרמָט תיאור
סוּג קצר סוג הפריטים; ראה טבלה למטה
לא בשימוש קצר (לא בשימוש)
גודל uint ספירה של מספר הפריטים שניתן למצוא בהיסט המצוין
לְקַזֵז uint קיזוז מתחילת הקובץ לפריטים המדוברים

הקלד קודים

סוג פריט קָבוּעַ ערך גודל פריט בבתים
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+ (item.size * 12)
type_list TYPE_TYPE_LIST 0x1001 4+ (item.size * 2)
annotation_set_ref_list TYPE_ANNOTATION_SET_REF_LIST 0x1002 4+ (item.size * 4)
annotation_set_item TYPE_ANNOTATION_SET_ITEM 0x1003 4+ (item.size * 4)
class_data_item TYPE_CLASS_DATA_ITEM 0x2000 משתמע; חייב לנתח
code_item TYPE_CODE_ITEM 0x2001 משתמע; חייב לנתח
string_data_item TYPE_STRING_DATA_ITEM 0x2002 משתמע; חייב לנתח
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 משתמע; חייב לנתח
annotation_item TYPE_ANNOTATION_ITEM 0x2004 משתמע; חייב לנתח
פריט_מערך_מקודד TYPE_ENCODED_ARRAY_ITEM 0x2005 משתמע; חייב לנתח
annotations_directory_item TYPE_ANNOTATIONS_DIRECTORY_ITEM 0x2006 משתמע; חייב לנתח
hiddenapi_class_data_item TYPE_HIDDENAPI_CLASS_DATA_ITEM 0xF000 משתמע; חייב לנתח

string_id_item

מופיע בקטע string_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
string_data_off uint היסט מתחילת הקובץ לנתוני המחרוזת של פריט זה. ההיסט צריך להיות למיקום בקטע data , והנתונים צריכים להיות בפורמט שצוין ב-" string_data_item " למטה. אין דרישת יישור לקיזוז.

string_data_item

מופיע בסעיף הנתונים

יישור: אין (מיושר בייטים)

שֵׁם פוּרמָט תיאור
utf16_size uleb128 גודל מחרוזת זו, ביחידות קוד UTF-16 (שזהו "אורך המחרוזת" במערכות רבות). כלומר, זהו האורך המפוענח של המחרוזת. (האורך המקודד משתמע מהמיקום של ה 0 בתים.)
נתונים ubyte[] סדרה של יחידות קוד MUTF-8 (aka אוקטטים, aka בתים) ואחריה בתים של ערך 0 . ראה "קידוד MUTF-8 (שינוי UTF-8)" לעיל לפרטים ודיון על פורמט הנתונים.

הערה: מקובל לקבל מחרוזת הכוללת (הצורה המקודדת של) יחידות קוד פונדקאות UTF-16 (כלומר, U+d800U+dfff ) במנותק או לא בסדר ביחס לקידוד הרגיל של Unicode לתוך UTF-16. בשימושים ברמה גבוהה יותר של מחרוזות יש לדחות קידודים לא חוקיים כאלה, אם מתאים.

type_id_item

מופיע בקטע type_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
descriptor_idx uint אינדקס לרשימת string_ids עבור מחרוזת התיאור מסוג זה. המחרוזת חייבת להתאים לתחביר עבור TypeDescriptor , שהוגדר לעיל.

proto_id_item

מופיע בקטע proto_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
shorty_idx uint אינדקס לתוך רשימת string_ids עבור מחרוזת התיאור בצורת קצר של אב טיפוס זה. המחרוזת חייבת להתאים לתחביר של ShortyDescriptor , שהוגדר לעיל, ועליה להתאים לסוג ההחזרה ולפרמטרים של פריט זה.
return_type_idx uint אינדקס לרשימת type_ids עבור סוג ההחזר של אב טיפוס זה
parameters_off uint היסט מתחילת הקובץ לרשימת סוגי הפרמטרים של אב טיפוס זה, או 0 אם לאב טיפוס זה אין פרמטרים. היסט זה, אם אינו אפס, צריך להיות בקטע data , והנתונים שם צריכים להיות בפורמט שצוין ב- "type_list" למטה. בנוסף, לא אמורה להיות התייחסות לסוג void ברשימה.

field_id_item

מופיע בקטע field_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
class_idx קצר אינדקס לרשימת type_ids עבור המגדיר של שדה זה. זה חייב להיות סוג מחלקה, ולא מערך או סוג פרימיטיבי.
type_idx קצר אינדקס לרשימת type_ids עבור הסוג של שדה זה
name_idx uint אינדקס לרשימת string_ids עבור השם של שדה זה. המחרוזת חייבת להתאים לתחביר של MemberName , שהוגדר לעיל.

method_id_item

מופיע בקטע method_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
class_idx קצר אינדקס לרשימת type_ids עבור המגדיר של שיטה זו. זה חייב להיות סוג מחלקה או מערך, ולא סוג פרימיטיבי.
proto_idx קצר אינדקס לרשימת proto_ids עבור אב הטיפוס של שיטה זו
name_idx uint אינדקס לרשימת string_ids עבור השם של שיטה זו. המחרוזת חייבת להתאים לתחביר של MemberName , שהוגדר לעיל.

class_def_item

מופיע בקטע class_defs

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
class_idx uint אינדקס לרשימת type_ids עבור מחלקה זו. זה חייב להיות סוג מחלקה, ולא מערך או סוג פרימיטיבי.
דגלי_גישה uint דגלי גישה לכיתה ( public , final וכו'). ראה "הגדרות access_flags " לפרטים.
superclass_idx uint אינדקס לרשימת type_ids עבור מחלקת העל, או לערך הקבוע NO_INDEX אם למחלקה הזו אין מחלקה על (כלומר, זוהי מחלקת שורש כגון Object ). אם קיים, זה חייב להיות סוג מחלקה, ולא מערך או סוג פרימיטיבי.
ממשקים_כבוי uint היסט מתחילת הקובץ לרשימת הממשקים, או 0 אם אין כאלה. היסט זה צריך להיות בקטע data , והנתונים שם צריכים להיות בפורמט שצוין על ידי " type_list " למטה. כל אחד מהרכיבים ברשימה חייב להיות סוג מחלקה (לא מערך או סוג פרימיטיבי), ואסור שיהיו כפילויות.
source_file_idx uint אינדקס לתוך רשימת string_ids עבור שם הקובץ המכיל את המקור המקורי עבור (לפחות רוב) המחלקה הזו, או את הערך המיוחד NO_INDEX כדי לייצג חוסר במידע זה. ה- debug_info_item של כל שיטה נתונה עשוי לעקוף את קובץ המקור הזה, אבל הציפייה היא שרוב המחלקות יגיעו רק מקובץ מקור אחד.
הערות_כבוי uint offset מתחילת הקובץ למבנה ההערות עבור מחלקה זו, או 0 אם אין הערות במחלקה זו. היסט זה, אם אינו אפס, צריך להיות בקטע data , והנתונים שם צריכים להיות בפורמט שצוין על ידי " annotations_directory_item " למטה, כאשר כל הפריטים מתייחסים למחלקה הזו כמגדיר.
class_data_off uint קיזוז מתחילת הקובץ לנתוני המחלקה המשויכים לפריט זה, או 0 אם אין נתוני מחלקה עבור מחלקה זו. (זה יכול להיות המקרה, למשל, אם מחלקה זו היא ממשק סמן.) ההיסט, אם אינו אפס, צריך להיות בקטע data , והנתונים שם צריכים להיות בפורמט שצוין על ידי " class_data_item " למטה, כאשר כל הפריטים מתייחסים למחלקה זו כמגדיר.
סטטי_ערכים_כבוי uint היסט מתחילת הקובץ לרשימת הערכים ההתחלתיים עבור שדות static , או 0 אם אין כאלה (וכל השדות static יש לאתחל עם 0 או null ). היסט זה צריך להיות בקטע data , והנתונים שם צריכים להיות בפורמט שצוין ב- " encoded_array_item " למטה. גודל המערך לא יכול להיות גדול ממספר השדות static שהוכרזו על ידי מחלקה זו, והאלמנטים תואמים לשדות static באותו סדר כפי שהוכרז ב- field_list המקביל. הסוג של כל רכיב מערך חייב להתאים לסוג המוצהר של השדה המתאים לו. אם יש פחות אלמנטים במערך מאשר שדות static , אזי השדות שנותרו מאותחלים עם 0 או null לסוג.

call_site_id_item

מופיע בקטע call_site_ids

יישור: 4 בתים

שֵׁם פוּרמָט תיאור
call_site_off uint קיזוז מתחילת הקובץ להגדרת האתר. ההיסט צריך להיות בקטע הנתונים, והנתונים שם צריכים להיות בפורמט המצוין ב-"call_site_item" למטה.

call_site_item

מופיע בסעיף הנתונים

יישור: אין (מיושר בייט)

ה-call_site_item הוא פריט_array_encoded שהרכיבים שלו תואמים לארגומנטים שסופקו לשיטת bootstrap Linker. שלושת הטיעונים הראשונים הם:

  1. ידית שיטה המייצגת את שיטת הקישור של bootstrap (VALUE_METHOD_HANDLE).
  2. שם שיטה שמקשר האתחול צריך לפתור (VALUE_STRING).
  3. סוג שיטה המתאים לסוג שם השיטה שיש לפתור (VALUE_METHOD_TYPE).

כל ארגומנט נוסף הוא ערכים קבועים המועברים לשיטת bootstrap Linker. These arguments are passed in order and without any type conversions.

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

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

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

method_handle_item

appears in the method_handles section

alignment: 4 bytes

שֵׁם פוּרמָט תיאור
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 תיאור
METHOD_HANDLE_TYPE_STATIC_PUT 0x00 Method handle is a static field setter (accessor)
METHOD_HANDLE_TYPE_STATIC_GET 0x01 Method handle is a static field getter (accessor)
METHOD_HANDLE_TYPE_INSTANCE_PUT 0x02 Method handle is an instance field setter (accessor)
METHOD_HANDLE_TYPE_INSTANCE_GET 0x03 Method handle is an instance field getter (accessor)
METHOD_HANDLE_TYPE_INVOKE_STATIC 0x04 Method handle is a static method invoker
METHOD_HANDLE_TYPE_INVOKE_INSTANCE 0x05 Method handle is an instance method invoker
METHOD_HANDLE_TYPE_INVOKE_CONSTRUCTOR 0x06 Method handle is a constructor method invoker
METHOD_HANDLE_TYPE_INVOKE_DIRECT 0x07 Method handle is a direct method invoker
METHOD_HANDLE_TYPE_INVOKE_INTERFACE 0x08 Method handle is an interface method invoker

class_data_item

referenced from class_def_item

appears in the data section

alignment: none (byte-aligned)

שֵׁם פוּרמָט תיאור
static_fields_size uleb128 the number of static fields defined in this item
instance_fields_size uleb128 the number of instance fields defined in this item
direct_methods_size uleb128 the number of direct methods defined in this item
virtual_methods_size uleb128 the number of virtual methods defined in this item
static_fields encoded_field[static_fields_size] the defined static fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order.
instance_fields encoded_field[instance_fields_size] the defined instance fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order.
direct_methods encoded_method[direct_methods_size] the defined direct (any of static , private , or constructor) methods, represented as a sequence of encoded elements. The methods must be sorted by method_idx in increasing order.
virtual_methods encoded_method[virtual_methods_size] the defined virtual (none of static , private , or constructor) methods, represented as a sequence of encoded elements. This list should not include inherited methods unless overridden by the class that this item represents. The methods must be sorted by method_idx in increasing order. The method_idx of a virtual method must not be the same as any direct method.

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

encoded_field format

שֵׁם פוּרמָט תיאור
field_idx_diff uleb128 index into the field_ids list for the identity of this field (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.
access_flags uleb128 access flags for the field ( public , final , etc.). See " access_flags Definitions" for details.

encoded_method format

שֵׁם פוּרמָט תיאור
method_idx_diff uleb128 index into the method_ids list for the identity of this method (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly.
access_flags uleb128 access flags for the method ( public , final , etc.). See " access_flags Definitions" for details.
code_off uleb128 offset from the start of the file to the code structure for this method, or 0 if this method is either abstract or native . The offset should be to a location in the data section. The format of the data is specified by " code_item " below.

type_list

referenced from class_def_item and proto_id_item

appears in the data section

alignment: 4 bytes

שֵׁם פוּרמָט תיאור
size uint size of the list, in entries
list type_item[size] elements of the list

type_item format

שֵׁם פוּרמָט תיאור
type_idx ushort index into the type_ids list

code_item

referenced from encoded_method

appears in the data section

alignment: 4 bytes

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
type_idx uleb128 index into the type_ids list for the type of the exception to catch
addr uleb128 bytecode address of the associated exception handler

debug_info_item

referenced from code_item

appears in the data section

alignment: none (byte-aligned)

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

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

The header is as follows:

שֵׁם פוּרמָט תיאור
line_start uleb128 the initial value for the state machine's line register. Does not represent an actual positions entry.
parameters_size uleb128 the number of parameter names that are encoded. There should be one per method parameter, excluding an instance method's this , if any.
parameter_names uleb128p1[parameters_size] string index of the method parameter name. An encoded value of NO_INDEX indicates that no name is available for the associated parameter. The type descriptor and signature are implied from the method descriptor and signature.

The byte code values are as follows:

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

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

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

Special opcodes

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

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

adjusted_opcode = opcode - DBG_FIRST_SPECIAL

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

annotations_directory_item

referenced from class_def_item

appears in the data section

alignment: 4 bytes

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
size uint size of the list, in entries
list annotation_set_ref_item[size] elements of the list

annotation_set_ref_item format

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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

שֵׁם פוּרמָט תיאור
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)

שֵׁם פוּרמָט תיאור
visibility ubyte intended visibility of this annotation (see below)
annotation encoded_annotation encoded annotation contents, in the format described by " encoded_annotation format" under " encoded_value encoding" above.

Visibility values

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

שֵׁם Value תיאור
VISIBILITY_BUILD 0x00 intended only to be visible at build time (eg, during compilation of other code)
VISIBILITY_RUNTIME 0x01 intended to visible at runtime
VISIBILITY_SYSTEM 0x02 intended to visible at runtime, but only to the underlying system (and not to regular user code)

encoded_array_item

referenced from class_def_item

appears in the data section

alignment: none (byte-aligned)

שֵׁם פוּרמָט תיאור
value encoded_array bytes representing the encoded array value, in the format specified by " encoded_array Format" under " encoded_value Encoding" above.

hiddenapi_class_data_item

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

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

שֵׁם פוּרמָט תיאור
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:

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

System annotations

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

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

dalvik.annotation.AnnotationDefault

appears on methods in annotation interfaces

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

שֵׁם פוּרמָט תיאור
value Annotation the default bindings for this annotation, represented as an annotation of this type. The annotation need not include all names defined by the annotation; missing names simply do not have defaults.

dalvik.annotation.EnclosingClass

appears on classes

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

שֵׁם פוּרמָט תיאור
value מעמד the class which most closely lexically scopes this class

dalvik.annotation.EnclosingMethod

appears on classes

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

שֵׁם פוּרמָט תיאור
value Method the method which most closely lexically scopes this class

dalvik.annotation.InnerClass

appears on classes

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

שֵׁם פוּרמָט תיאור
name String the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null .
accessFlags 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.)

שֵׁם פוּרמָט תיאור
value Class[] array of the member classes

dalvik.annotation.MethodParameters

appears on methods

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

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

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

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

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

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

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

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

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

dalvik.annotation.Signature

appears on classes, fields, and methods

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

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

שֵׁם פוּרמָט תיאור
value String[] the signature of this class or member, as an array of strings that is to be concatenated together

dalvik.annotation.Throws

appears on methods

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

שֵׁם פוּרמָט תיאור
value Class[] the array of exception types thrown