فرمت اجرایی دالویک

این سند طرح و محتویات فایل‌های .dex را توصیف می‌کند که برای نگهداری مجموعه‌ای از تعاریف کلاس و داده‌های کمکی مرتبط با آنها استفاده می‌شوند.

راهنمای انواع

نام توضیحات
بایت 8 بیتی امضا شده
یوبایت 8 بیتی بدون علامت
کوتاه 16 بیتی امضا شده، کمی اندین
کوتاه 16 بیتی بدون علامت، کمی اندین
بین المللی 32 بیتی امضا شده، کمی اندین
unint 32 بیتی بدون علامت، کمی اندین
طولانی 64 بیتی امضا شده، کمی اندین
طولانی 64 بیتی بدون علامت، کمی اندین
sleb128 امضا شده LEB128، با طول متغیر (به زیر مراجعه کنید)
uleb128 LEB128 بدون امضا، با طول متغیر (به زیر مراجعه کنید)
uleb128p1 بدون علامت LEB128 به علاوه 1 ، با طول متغیر (به زیر مراجعه کنید)

LEB128

LEB128 (" L ittle- Endian 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
7f -1 127 126
80 7f -128 16256 16255

طرح بندی فایل

نام قالب توضیحات
هدر header_item هدر
string_ids string_id_item[] لیست شناسه رشته ها اینها شناسه‌هایی برای تمام رشته‌هایی هستند که توسط این فایل استفاده می‌شوند، یا برای نام‌گذاری داخلی (مثلاً توصیف‌کننده‌های نوع) یا به‌عنوان اشیاء ثابت که با کد ارجاع می‌شوند. این فهرست باید بر اساس محتویات رشته، با استفاده از مقادیر نقطه کد UTF-16 (نه به روشی حساس به محلی)، و نباید حاوی هیچ ورودی تکراری باشد.
type_ids type_id_item[] لیست شناسه های نوع اینها شناسه‌هایی برای همه انواع (کلاس‌ها، آرایه‌ها یا انواع اولیه) هستند که توسط این فایل به آنها اشاره می‌شود، چه در فایل تعریف شده باشند یا نه. این لیست باید بر اساس فهرست string_id مرتب شود و نباید حاوی هیچ ورودی تکراری باشد.
proto_ids proto_id_item[] لیست شناسه های نمونه اولیه روش. اینها شناسه‌های همه نمونه‌های اولیه هستند که توسط این فایل به آنها ارجاع شده است. این فهرست باید به ترتیب اصلی نوع بازگشتی (براساس نمایه type_id ) و سپس بر اساس فهرست آرگومان (ترتیب واژگان نگاری، آرگومان های فردی مرتب شده بر اساس نمایه type_id ) مرتب شود. لیست نباید حاوی هیچ ورودی تکراری باشد.
field_ids field_id_item[] لیست شناسه های فیلد اینها شناسه‌هایی برای تمام فیلدهای ارجاع شده توسط این فایل هستند، خواه در فایل تعریف شده باشند یا نه. این لیست باید مرتب شود، که در آن نوع تعیین کننده (براساس شاخص type_id ) ترتیب اصلی، نام فیلد (براساس فهرست string_id ) ترتیب میانی و نوع (بر اساس شاخص type_id ) ترتیب فرعی است. لیست نباید حاوی هیچ ورودی تکراری باشد.
روش_ids method_id_item[] لیست شناسه های روش اینها شناسه‌هایی برای همه روش‌های ارجاع‌شده توسط این فایل هستند، خواه در فایل تعریف شده باشند یا نه. این لیست باید مرتب شود، که در آن نوع تعریف کننده (براساس شاخص type_id ) ترتیب اصلی، نام روش (براساس شاخص string_id ) ترتیب میانی و نمونه اولیه روش (بر اساس شاخص proto_id ) ترتیب فرعی است. لیست نباید حاوی هیچ ورودی تکراری باشد.
class_defs class_def_item[] لیست تعاریف کلاس کلاس ها باید به گونه ای مرتب شوند که سوپرکلاس کلاس معین و رابط های پیاده سازی شده زودتر از کلاس ارجاع دهنده در لیست ظاهر شوند. علاوه بر این، برای یک تعریف برای یک کلاس با همان نام که بیش از یک بار در لیست ظاهر شود نامعتبر است.
call_site_ids call_site_id_item[] تماس با لیست شناسه های سایت اینها شناسه‌هایی برای همه سایت‌های تماسی هستند که توسط این فایل به آنها اشاره می‌شود، چه در فایل تعریف شده باشند یا نه. این لیست باید به ترتیب صعودی call_site_off مرتب شود.
روش_دسته ها method_handle_item[] لیست دسته های روش فهرستی از تمام دسته‌های متد که توسط این فایل به آنها ارجاع شده است، خواه در فایل تعریف شده باشند یا نه. این لیست مرتب نشده است و ممکن است حاوی موارد تکراری باشد که به طور منطقی با نمونه های دسته روش های مختلف مطابقت دارند.
داده ها یوبایت[] ناحیه داده، حاوی تمام داده های پشتیبانی برای جداول فهرست شده در بالا. آیتم های مختلف نیازهای تراز متفاوتی دارند و در صورت لزوم برای دستیابی به تراز مناسب، بایت های padding قبل از هر آیتم درج می شوند.
پیوند_داده یوبایت[] داده‌های مورد استفاده در فایل‌های مرتبط استاتیک فرمت داده های این بخش توسط این سند مشخص نشده است. این بخش در فایل‌های بدون پیوند خالی است و پیاده‌سازی‌های زمان اجرا ممکن است آن‌طور که صلاح می‌دانند از آن استفاده کنند.

قالب کانتینر

نسخه 41 فرمت کانتینری جدیدی را برای داده های DEX با هدف صرفه جویی در فضا معرفی می کند. این فرمت کانتینری اجازه می دهد تا چندین فایل DEX منطقی در یک فایل فیزیکی واحد ترکیب شوند. فرمت جدید عمدتاً فقط الحاق ساده فایل ها در قالب قبلی است، با برخی تفاوت ها:

  • file_size اندازه فایل منطقی است، نه فایل فیزیکی. می توان از آن برای تکرار روی تمام فایل های منطقی موجود در کانتینر استفاده کرد.
  • فایل های منطقی dex ممکن است به هر داده بعدی در ظرف (اما نه قبل از آن) اشاره کنند. این به فایل‌های dex اجازه می‌دهد تا داده‌هایی مانند رشته‌ها را بین خود به اشتراک بگذارند.
  • همه افست ها نسبت به فایل فیزیکی هستند. هیچ افست نسبت به هدر نیست. این تضمین می کند که بخش هایی با افست می توانند بین فایل های منطقی به اشتراک گذاشته شوند.
  • هدر دو فیلد جدید برای توصیف محدوده های ظرف اضافه می کند. این یک بررسی سازگاری اضافی است و انتقال کد به قالب جدید را آسان‌تر می‌کند.
  • data_size و data_off اکنون استفاده نشده است. داده ها می توانند در چندین فایل منطقی پخش شوند و لازم نیست به هم پیوسته باشند.

بیت فیلد، رشته و تعاریف ثابت

DEX_FILE_MAGIC

در header_item تعبیه شده است

آرایه/رشته ثابت DEX_FILE_MAGIC لیست بایت هایی است که باید در ابتدای یک فایل .dex ظاهر شود تا بتوان آن را به عنوان آن تشخیص داد. این مقدار عمداً حاوی یک خط جدید ( "\n" یا 0x0a ) و یک بایت تهی ( "\0" یا 0x00 ) است تا به شناسایی اشکال خاصی از فساد کمک کند. این مقدار همچنین یک شماره نسخه قالب را به صورت سه رقم اعشاری رمزگذاری می‌کند، که انتظار می‌رود در طول زمان و با تکامل قالب به طور یکنواخت افزایش یابد.

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

توجه: پشتیبانی از نسخه 040 فرمت در نسخه Android 10.0 اضافه شد که مجموعه کاراکترهای مجاز را در SimpleNames گسترش داد.

توجه: پشتیبانی از فرمت 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 برای نشان دادن endianness فایلی که در آن یافت می شود استفاده می شود. اگرچه فرمت استاندارد .dex بسیار کم است، اما ممکن است پیاده سازی ها مبادله بایت را انتخاب کنند. اگر پیاده‌سازی به سرآیندی برخورد کند که endian_tag آن به جای ENDIAN_CONSTANT REVERSE_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 روش bridge که به صورت خودکار توسط کامپایلر به عنوان پل ایمن نوع اضافه می شود
ACC_TRANSIENT 0x80 transient : با سریال سازی پیش فرض ذخیره نمی شود
ACC_VARARGS 0x80 آخرین آرگومان باید توسط کامپایلر به عنوان آرگومان "استراحت" در نظر گرفته شود
ACC_NATIVE 0x100 native : در کد بومی پیاده سازی شده است
ACC_INTERFACE 0x200 interface : کلاس انتزاعی قابل پیاده سازی چند برابری
ACC_ABSTRACT 0x400 abstract : مستقیماً قابل اثبات نیست abstract : توسط این کلاس اجرا نشده است
ACC_STRICT 0x800 strictfp : قوانین سختگیرانه برای محاسبات ممیز شناور
ACC_SYNTHETIC 0x1000 به طور مستقیم در کد منبع تعریف نشده است به طور مستقیم در کد منبع تعریف نشده است به طور مستقیم در کد منبع تعریف نشده است
ACC_ANNOTATION 0x2000 به عنوان یک کلاس حاشیه نویسی اعلام شد
ACC_ENUM 0x4000 به عنوان یک نوع برشماری اعلام شد به عنوان یک مقدار شمارش شده اعلام شد
(استفاده نشده) 0x8000
ACC_CONSTRUCTOR 0x10000 روش سازنده (کلاس یا نمونه اولیه)
ACC_DECLARED_
همگام
0x20000 synchronized اعلام شد .

توجه: این هیچ تأثیری در اجرا ندارد (به غیر از انعکاس این پرچم، فی نفسه).

* فقط برای حاشیه نویسی های InnerClass مجاز است و هرگز نباید در یک class_def_item روشن باشد.

رمزگذاری UTF-8 اصلاح شده

به عنوان امتیازی برای پشتیبانی آسان تر قدیمی، فرمت .dex داده های رشته ای خود را در یک فرم استاندارد تغییر یافته UTF-8 که از این به بعد MUTF-8 نامیده می شود، رمزگذاری می کند. این فرم با استاندارد UTF-8 یکسان است، به جز:

  • فقط از کدهای یک، دو و سه بایتی استفاده می شود.
  • نقاط کد در محدوده U+10000U+10ffff به عنوان یک جفت جایگزین رمزگذاری می‌شوند که هر کدام به صورت یک مقدار رمزگذاری شده سه بایتی نمایش داده می‌شوند.
  • نقطه کد U+0000 به صورت دو بایتی کدگذاری شده است.
  • یک بایت تهی ساده (مقدار 0 ) پایان یک رشته را نشان می دهد، همانطور که تفسیر زبان استاندارد C است.

دو مورد اول در بالا را می توان به این صورت خلاصه کرد: MUTF-8 یک فرمت رمزگذاری برای UTF-16 است، به جای اینکه یک فرمت رمزگذاری مستقیم تر برای کاراکترهای یونیکد باشد.

دو مورد آخر بالا به طور همزمان امکان گنجاندن نقطه کد U+0000 را در یک رشته و همچنان آن را به عنوان یک رشته تهی به سبک C دستکاری می کنند.

با این حال، رمزگذاری ویژه U+0000 به این معنی است که بر خلاف UTF-8 معمولی، نتیجه فراخوانی تابع استاندارد C strcmp() روی یک جفت رشته MUTF-8 همیشه نشان دهنده نتیجه امضا شده مناسب از مقایسه رشته های نابرابر نیست. هنگامی که مرتب سازی (نه فقط برابری) یک نگرانی است، ساده ترین راه برای مقایسه رشته های MUTF-8 رمزگشایی آنها کاراکتر به کاراکتر و مقایسه مقادیر رمزگشایی شده است. (با این حال، پیاده سازی های هوشمندانه تری نیز امکان پذیر است.)

لطفاً برای اطلاعات بیشتر در مورد رمزگذاری کاراکتر به استاندارد یونیکد مراجعه کنید. MUTF-8 در واقع به رمزگذاری (نسبتا کمتر شناخته شده) CESU-8 نزدیکتر از UTF-8 فی نفسه است.

رمزگذاری encoded_value

در annotation_element و encoded_array_item تعبیه شده است

encoded_value قطعه ای رمزگذاری شده از داده های (تقریباً) دلخواه با ساختار سلسله مراتبی است. رمزگذاری قرار است هم فشرده و هم ساده برای تجزیه باشد.

نام قالب توضیحات
(value_arg << 5) | value_type یوبایت بایت که نوع value بلافاصله بعدی را به همراه یک آرگومان شفاف کننده اختیاری در سه بیت مرتبه بالا نشان می دهد. برای تعاریف مختلف value به زیر مراجعه کنید. در بیشتر موارد، value_arg طول value بلافاصله پس از آن را در بایت رمزگذاری می کند، به عنوان (size - 1) ، به عنوان مثال، 0 به این معنی است که مقدار به یک بایت نیاز دارد، و 7 به این معنی است که به هشت بایت نیاز دارد. با این حال، استثناهایی وجود دارد که در زیر ذکر شده است.
ارزش یوبایت[] بایت ها نشان دهنده مقدار، متغیر در طول و تفسیر متفاوت برای بایت های مختلف value_type ، هر چند همیشه اندکی اند. برای جزئیات بیشتر به تعاریف مختلف مقادیر زیر مراجعه کنید.

فرمت های ارزش

نام را تایپ کنید value_type فرمت value_arg فرمت value توضیحات
VALUE_BYTE 0x00 (هیچ کدام؛ باید 0 باشد) یوبایت[1] مقدار عدد صحیح یک بایتی امضا شده
VALUE_SHORT 0x02 اندازه - 1 (0…1) یوبایت[اندازه] مقدار عدد صحیح دو بایتی امضا شده، علامت گسترش یافته
VALUE_CHAR 0x03 اندازه - 1 (0…1) یوبایت[اندازه] مقدار عدد صحیح دو بایتی بدون علامت، صفر بسط داده شده
VALUE_INT 0x04 اندازه - 1 (0…3) یوبایت[اندازه] مقدار عدد صحیح چهار بایت امضا شده، علامت گسترش یافته
VALUE_LONG 0x06 اندازه - 1 (0…7) یوبایت[اندازه] مقدار عدد صحیح هشت بایتی امضا شده، علامت گسترش یافته
VALUE_FLOAT 0x10 اندازه - 1 (0…3) یوبایت[اندازه] الگوی بیت چهار بایتی، به سمت راست با صفر گسترش یافته و به عنوان یک مقدار ممیز شناور 32 بیتی IEEE754 تفسیر می شود.
VALUE_DOUBLE 0x11 اندازه - 1 (0…7) یوبایت[اندازه] الگوی بیت هشت بایتی، به سمت راست با صفر گسترش یافته و به عنوان یک مقدار ممیز شناور 64 بیتی IEEE754 تفسیر می شود.
VALUE_METHOD_TYPE 0x15 اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایت بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش proto_ids تفسیر شده و یک مقدار نوع روش را نشان می دهد.
VALUE_METHOD_HANDLE 0x16 اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایتی بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش method_handles تفسیر می شود و یک مقدار دسته متد را نشان می دهد
VALUE_STRING 0x17 اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایت بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش string_ids تفسیر می شود و یک مقدار رشته را نشان می دهد
VALUE_TYPE 0x18 اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایت بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش type_ids تفسیر می شود و یک مقدار نوع/کلاس بازتابی را نشان می دهد.
VALUE_FIELD 0x19 اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایت بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش field_ids تفسیر می شود و یک مقدار میدان بازتابی را نشان می دهد
VALUE_METHOD 0x1a اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایتی بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش method_ids تفسیر می شود و یک مقدار متد بازتابنده را نشان می دهد.
VALUE_ENUM 0x1b اندازه - 1 (0…3) یوبایت[اندازه] مقدار صحیح چهار بایت بدون علامت (صفر توسعه یافته) که به عنوان یک شاخص در بخش field_ids تفسیر می شود و مقدار یک نوع ثابت برشماری شده را نشان می دهد.
VALUE_ARRAY 0x1c (هیچ کدام؛ باید 0 باشد) encoded_array آرایه ای از مقادیر، در قالب مشخص شده توسط "فرمت encoded_array " در زیر. اندازه value در رمزگذاری ضمنی است.
VALUE_ANNOTATION 0x1d (هیچ کدام؛ باید 0 باشد) encoded_annotation یک حاشیه نویسی فرعی، در قالب مشخص شده توسط "فرمت encoded_annotation " در زیر. اندازه value در رمزگذاری ضمنی است.
VALUE_NULL 0x1e (هیچ کدام؛ باید 0 باشد) (هیچ کدام) مقدار مرجع null
VALUE_BOOLEAN 0x1f بولی (0…1) (هیچ کدام) مقدار یک بیتی؛ 0 برای false و 1 برای true . بیت در value_arg نشان داده می شود.

فرمت encoded_array

نام قالب توضیحات
اندازه uleb128 تعداد عناصر در آرایه
ارزش ها encoded_value[اندازه] یک سری توالی بایت size encoded_value در قالب مشخص شده توسط این بخش، به صورت متوالی به هم پیوسته اند.

فرمت encoded_annotation

نام قالب توضیحات
type_idx uleb128 نوع حاشیه نویسی این باید یک نوع کلاس (نه آرایه یا ابتدایی) باشد.
اندازه uleb128 تعداد نگاشت نام-مقدار در این حاشیه نویسی
عناصر annotation_element[اندازه] عناصر حاشیه نویسی که مستقیماً در خط نشان داده می شوند (نه به صورت افست). عناصر باید به ترتیب افزایش با شاخص string_id مرتب شوند.

فرمت annotation_element

نام قالب توضیحات
name_idx uleb128 نام عنصر، به عنوان یک شاخص در بخش string_ids نمایش داده می شود. رشته باید با دستور MemberName که در بالا تعریف شده است مطابقت داشته باشد.
ارزش encoded_value مقدار عنصر

نحو رشته

انواع مختلفی از آیتم در یک فایل .dex وجود دارد که در نهایت به یک رشته اشاره دارد. تعاریف زیر به سبک BNF بیانگر نحو قابل قبول برای این رشته ها است.

SimpleName

یک SimpleName مبنایی برای نحو نام چیزهای دیگر است. قالب .dex در اینجا اجازه می دهد تا عرض جغرافیایی مناسبی داشته باشید (بسیار بیشتر از اکثر زبان های مبدأ رایج). به طور خلاصه، یک نام ساده شامل هر کاراکتر یا رقم الفبایی کم ASCII، چند نماد خاص با ASCII پایین، و اکثر نقاط کد غیر ASCII است که کنترل، فاصله یا کاراکترهای خاص نیستند. با شروع از نسخه 040 فرمت علاوه بر این به کاراکترهای فاصله (دسته یونیکد Zs ) اجازه می دهد. توجه داشته باشید که نقاط کد جایگزین (در محدوده U+d800U+dfff ) به خودی خود کاراکترهای نام معتبر در نظر گرفته نمی‌شوند، اما نویسه‌های تکمیلی یونیکد معتبر هستند (که با جایگزین نهایی قانون برای SimpleNameChar نشان داده می‌شوند)، و باید در یک فایل به‌عنوان جفت نقاط کد جایگزین8 در MUTF- نمایش داده شوند.

SimpleName
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
| '<' 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
D double
L به طور کامل / واجد شرایط / نام ; کلاس fully.qualified.Name
[ توصیفگر آرایه descriptor ، قابل استفاده به صورت بازگشتی برای آرایه‌های آرایه‌ها، اگرچه داشتن بیش از 255 بعد نامعتبر است.

اقلام و ساختارهای مرتبط

این بخش شامل تعاریفی برای هر یک از موارد سطح بالایی است که ممکن است در یک فایل .dex ظاهر شوند.

header_item

در قسمت هدر ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
سحر و جادو ubyte[8] = DEX_FILE_MAGIC ارزش جادویی برای جزئیات بیشتر به بحث بالا در " DEX_FILE_MAGIC " مراجعه کنید.
چک جمع unint adler32 checksum بقیه فایل (همه چیز به جز magic و این فیلد)؛ برای تشخیص خرابی فایل استفاده می شود
امضا یوبایت[20] امضای SHA-1 (هش) بقیه فایل (همه چیز به جز magic ، checksum و این فیلد). برای شناسایی منحصر به فرد فایل ها استفاده می شود
فایل_اندازه unint

اندازه کل فایل (از جمله هدر)، بر حسب بایت (نسخه 40 یا قبل از آن)

فاصله بر حسب بایت از ابتدای این هدر تا هدر بعدی یا تا انتهای کل فایل (کانتینر). (نسخه 41 یا بالاتر)

سربرگ_اندازه unint

اندازه هدر (کل این بخش)، بر حسب بایت. این اجازه می دهد تا حداقل مقدار محدودی از سازگاری به عقب و جلو بدون نامعتبر کردن قالب.

باید 0x70 (112) بایت (v40 یا قبل از آن) باشد

باید 0x78 (120) بایت (نسخه 41 یا بالاتر) باشد

endian_tag واحد = ENDIAN_CONSTANT برچسب endianness برای جزئیات بیشتر به بحث بالا در زیر " ENDIAN_CONSTANT و REVERSE_ENDIAN_CONSTANT " مراجعه کنید.
پیوند_اندازه unint اندازه بخش پیوند یا 0 اگر این فایل به صورت ایستا پیوند داده نشده باشد
link_off unint از ابتدای فایل به قسمت پیوند یا 0 اگر link_size == 0 . افست، اگر غیر صفر باشد، باید به یک افست در بخش link_data باشد. قالب داده های اشاره شده توسط این سند مشخص نشده است. این فیلد هدر (و قسمت قبلی) به عنوان قلاب برای استفاده توسط پیاده‌سازی زمان اجرا باقی می‌ماند.
map_off unint از ابتدای فایل تا آیتم نقشه افست شود. آفست، که باید غیر صفر باشد، باید به یک افست در بخش data باشد، و داده ها باید در قالب مشخص شده توسط " map_list " در زیر باشد.
string_ids_size unint تعداد رشته ها در لیست شناسه رشته ها
string_ids_off unint از ابتدای فایل به لیست شناسه‌های رشته یا 0 اگر string_ids_size == 0 (البته یک مورد لبه عجیب است). افست، اگر غیر صفر باشد، باید در ابتدای بخش string_ids باشد.
type_ids_size unint تعداد عناصر موجود در لیست شناسه نوع، حداکثر 65535
type_ids_off unint از ابتدای فایل به لیست شناسه‌های نوع یا 0 اگر type_ids_size == 0 (البته یک مورد لبه عجیب است). افست، اگر غیر صفر باشد، باید در ابتدای بخش type_ids باشد.
proto_ids_size unint تعداد عناصر موجود در لیست شناسه های نمونه اولیه، حداکثر 65535
proto_ids_off unint از ابتدای فایل به لیست شناسه‌های نمونه اولیه یا 0 اگر proto_ids_size == 0 (البته یک مورد لبه عجیب است). افست، اگر غیر صفر باشد، باید در ابتدای بخش proto_ids باشد.
field_ids_size unint تعداد عناصر در لیست شناسه های فیلد
field_ids_off unint از ابتدای فایل به لیست شناسه‌های فیلد یا 0 اگر field_ids_size == 0 . افست، اگر غیر صفر باشد، باید به ابتدای بخش field_ids باشد.
method_ids_size unint تعداد عناصر در لیست شناسه های متد
method_ids_off unint از ابتدای فایل به لیست شناسه های متد یا 0 اگر method_ids_size == 0 تغییر می کند. افست، اگر غیر صفر باشد، باید در ابتدای بخش method_ids باشد.
class_defs_size unint تعداد عناصر در لیست تعاریف کلاس
class_defs_off unint از ابتدای فایل به لیست تعاریف کلاس، یا 0 اگر class_defs_size == 0 (البته یک مورد لبه عجیب است). افست، اگر غیر صفر باشد، باید در ابتدای بخش class_defs باشد.
داده_اندازه unint

اندازه بخش data بر حسب بایت باید مضربی زوج از sizeof(uint) باشد. (نسخه 40 یا قبل از آن)

استفاده نشده (نسخه 41 یا جدیدتر)

داده_خاموش unint

از شروع فایل تا شروع بخش data (نسخه 40 یا قبل از آن) افست شود

استفاده نشده (نسخه 41 یا جدیدتر)

ظرف_اندازه unint

این زمینه وجود ندارد می توان آن را برابر با file_size فرض کرد. (نسخه 40 یا قبل از آن)

اندازه کل فایل (شامل سرصفحه های دیگر dex و داده های آنها). (نسخه 41 یا بالاتر)

header_offset unint

این زمینه وجود ندارد می توان آن را برابر با 0 فرض کرد. (نسخه 40 یا قبل از آن)

از ابتدای فایل تا ابتدای این هدر افست شود. (نسخه 41 یا بالاتر)

map_list

در بخش داده ظاهر می شود

از header_item ارجاع شده است

تراز: 4 بایت

این لیستی از کل محتویات یک فایل به ترتیب است. این شامل مقداری افزونگی با توجه به header_item است، اما در نظر گرفته شده است که فرمی آسان برای استفاده برای تکرار در کل فایل باشد. یک نوع معین باید حداکثر یک بار در نقشه ظاهر شود، اما هیچ محدودیتی برای اینکه انواع ترتیب ممکن است در آن ظاهر شوند وجود ندارد، به غیر از محدودیت‌هایی که در بقیه قالب‌ها وجود دارد (مثلاً یک بخش header باید ابتدا ظاهر شود، سپس یک بخش string_ids و غیره). علاوه بر این، ورودی های نقشه باید بر اساس افست اولیه مرتب شوند و نباید با هم تداخل داشته باشند.

نام قالب توضیحات
اندازه unint اندازه لیست، در ورودی ها
فهرست نقشه_آیتم[اندازه] عناصر لیست

قالب نقشه_آیتم

نام قالب توضیحات
نوع کوتاه نوع اقلام؛ جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
اندازه unint شمارش تعداد آیتم هایی که در افست مشخص شده یافت می شوند
جبران unint از ابتدای فایل تا موارد مورد نظر جبران شود

کدها را تایپ کنید

نوع مورد ثابت ارزش اندازه مورد بر حسب بایت
header_item TYPE_HEADER_ITEM 0x0000 0x70
string_id_item TYPE_STRING_ID_ITEM 0x0001 0x04
type_id_item TYPE_TYPE_ID_ITEM 0x0002 0x04
proto_id_item TYPE_PROTO_ID_ITEM 0x0003 0x0c
field_id_item TYPE_FIELD_ID_ITEM 0x0004 0x08
method_id_item TYPE_METHOD_ID_ITEM 0x0005 0x08
class_def_item TYPE_CLASS_DEF_ITEM 0x0006 0x20
call_site_id_item TYPE_CALL_SITE_ID_ITEM 0x0007 0x04
method_handle_item TYPE_METHOD_HANDLE_ITEM 0x0008 0x08
map_list TYPE_MAP_LIST 0x1000 4 + (اندازه مورد * 12)
type_list TYPE_TYPE_LIST 0x1001 4 + (اندازه مورد * 2)
annotation_set_ref_list TYPE_ANNOTATION_SET_REF_LIST 0x1002 4 + (اندازه مورد * 4)
annotation_set_item TYPE_ANNOTATION_SET_ITEM 0x1003 4 + (اندازه مورد * 4)
class_data_item TYPE_CLASS_DATA_ITEM 0x2000 ضمنی باید تجزیه شود
code_item TYPE_CODE_ITEM 0x2001 ضمنی باید تجزیه شود
string_data_item TYPE_STRING_DATA_ITEM 0x2002 ضمنی باید تجزیه شود
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 ضمنی باید تجزیه شود
annotation_item TYPE_ANNOTATION_ITEM 0x2004 ضمنی باید تجزیه شود
encoded_array_item 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 unint از ابتدای فایل به داده های رشته ای برای این آیتم افست شود. افست باید در مکانی در بخش data باشد و داده ها باید در قالب مشخص شده توسط " string_data_item " در زیر باشد. هیچ نیازی به تراز برای افست وجود ندارد.

string_data_item

در بخش داده ظاهر می شود

تراز: هیچ (تراز بایت)

نام قالب توضیحات
utf16_size uleb128 اندازه این رشته، در واحدهای کد UTF-16 (که در بسیاری از سیستم ها "طول رشته" است). یعنی این طول رمزگشایی شده رشته است. (طول رمزگذاری شده با موقعیت 0 بایت مشخص می شود.)
داده ها یوبایت[] یک سری از واحدهای کد MUTF-8 (با نام مستعار octets، aka bytes) به دنبال آن یک بایت با مقدار 0 . برای جزئیات و بحث در مورد قالب داده، به "رمزگذاری MUTF-8 (تغییر یافته UTF-8)" در بالا مراجعه کنید.

توجه: وجود رشته ای که شامل (شکل رمزگذاری شده) واحدهای کد جایگزین UTF-16 (یعنی U+d800U+dfff ) باشد، به صورت مجزا یا خارج از نظم با توجه به رمزگذاری معمول یونیکد در UTF-16 قابل قبول است. رد کردن چنین رمزگذاری‌های نامعتبر، در صورت لزوم، بستگی به استفاده‌های سطح بالاتر از رشته‌ها دارد.

type_id_item

در قسمت type_ids ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
descriptor_idx unint در لیست string_ids برای رشته توصیفگر از این نوع فهرست کنید. رشته باید با نحو برای TypeDescriptor که در بالا تعریف شده است مطابقت داشته باشد.

proto_id_item

در بخش proto_ids ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
shorty_idx unint در لیست string_ids برای رشته توصیفگر فرم کوتاه این نمونه اولیه فهرست کنید. رشته باید با نحو برای ShortyDescriptor که در بالا تعریف شده است مطابقت داشته باشد و باید با نوع بازگشتی و پارامترهای این مورد مطابقت داشته باشد.
return_type_idx unint در لیست type_ids برای نوع برگشتی این نمونه اولیه فهرست کنید
parameters_off unint از ابتدای فایل به لیست انواع پارامترهای این نمونه اولیه یا 0 در صورتی که این نمونه اولیه هیچ پارامتری نداشته باشد، افست شود. این افست، اگر غیر صفر باشد، باید در بخش data باشد، و داده‌ها باید در قالبی باشند که توسط "type_list" در زیر مشخص شده است. علاوه بر این، نباید هیچ اشاره ای به نوع void در لیست وجود داشته باشد.

field_id_item

در قسمت field_ids ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
class_idx کوتاه در لیست type_ids برای تعریف کننده این فیلد فهرست کنید. این باید یک نوع کلاس باشد و نه یک آرایه یا نوع اولیه.
type_idx کوتاه در لیست type_ids برای نوع این فیلد فهرست کنید
name_idx unint در لیست string_ids برای نام این فیلد فهرست کنید. رشته باید با دستور MemberName که در بالا تعریف شده است مطابقت داشته باشد.

method_id_item

در قسمت method_ids ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
class_idx کوتاه در لیست type_ids برای تعریف کننده این روش فهرست کنید. این باید یک نوع کلاس یا آرایه باشد و نه یک نوع اولیه.
proto_idx کوتاه برای نمونه اولیه این روش در لیست proto_ids فهرست کنید
name_idx unint نام این روش را در لیست string_ids قرار دهید. رشته باید با دستور MemberName که در بالا تعریف شده است مطابقت داشته باشد.

class_def_item

در بخش class_defs ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
class_idx unint در لیست type_ids برای این کلاس فهرست کنید. این باید یک نوع کلاس باشد و نه یک آرایه یا نوع اولیه.
access_flags unint پرچم های دسترسی برای کلاس ( public ، final ، و غیره). برای جزئیات بیشتر به "تعاریف access_flags " مراجعه کنید.
superclass_idx unint در لیست type_ids برای سوپرکلاس، یا مقدار ثابت NO_INDEX اگر این کلاس فاقد سوپرکلاس باشد (یعنی یک کلاس ریشه مانند Object باشد) فهرست کنید. در صورت وجود، این باید یک نوع کلاس باشد، نه یک آرایه یا نوع اولیه.
interfaces_off unint از ابتدای فایل به لیست اینترفیس ها یا 0 در صورتی که هیچ کدام وجود ندارد، افست شود. این افست باید در بخش data باشد، و داده‌های موجود در آن باید در قالبی باشد که توسط " type_list " در زیر مشخص شده است. هر یک از عناصر لیست باید یک نوع کلاس باشد (نه یک آرایه یا نوع اولیه)، و نباید هیچ تکراری وجود داشته باشد.
source_file_idx unint در لیست string_ids برای نام فایل حاوی منبع اصلی (حداقل اکثر) این کلاس، یا مقدار ویژه NO_INDEX برای نشان دادن کمبود این اطلاعات، فهرست کنید. debug_info_item هر روشی ممکن است این فایل منبع را لغو کند، اما انتظار این است که بیشتر کلاس‌ها فقط از یک فایل منبع آمده باشند.
annotations_off unint از ابتدای فایل به ساختار حاشیه نویسی برای این کلاس، یا 0 در صورتی که حاشیه نویسی در این کلاس وجود نداشته باشد، جبران شود. این افست، اگر غیر صفر باشد، باید در بخش data باشد، و داده‌ها باید در قالبی باشد که توسط " annotations_directory_item " در زیر مشخص شده است و همه موارد به این کلاس به عنوان تعریف کننده اشاره می‌کنند.
class_data_off unint از ابتدای فایل به داده های کلاس مرتبط برای این آیتم یا 0 در صورتی که داده کلاسی برای این کلاس وجود نداشته باشد، جبران شود. (ممکن است به عنوان مثال، اگر این کلاس یک رابط نشانگر باشد.) افست، اگر غیر صفر باشد، باید در بخش data باشد، و داده های موجود باید در قالب مشخص شده توسط " class_data_item " در زیر باشد، و همه موارد به این کلاس به عنوان تعریف کننده اشاره می کنند.
static_values_off unint از ابتدای فایل به لیست مقادیر اولیه برای فیلدهای static ، یا 0 در صورت وجود هیچ (و همه فیلدهای static باید با 0 یا null مقداردهی اولیه شوند). این افست باید در بخش data باشد، و داده‌های موجود باید در قالبی باشد که توسط " encoded_array_item " در زیر مشخص شده است. اندازه آرایه نباید بیشتر از تعداد فیلدهای static اعلام شده توسط این کلاس باشد و عناصر به همان ترتیبی که در field_list مربوطه اعلام شده با فیلدهای static مطابقت دارند. نوع هر عنصر آرایه باید با نوع اعلام شده فیلد مربوطه آن مطابقت داشته باشد. اگر عناصر کمتری در آرایه وجود داشته باشد تا زمینه های static وجود داشته باشد ، قسمت های باقیمانده با یک نوع مناسب 0 یا null تنظیم می شوند.

call_site_id_item

در بخش call_site_ids ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
call_site_off unint از شروع پرونده برای تماس با سایت تماس بگیرید. افست باید در بخش داده باشد و داده های موجود در قالب مشخص شده توسط "call_site_item" در زیر وجود دارد.

call_site_item

در بخش داده ظاهر می شود

تراز: هیچ (بایت تراز)

call_site_item یک encoded_array_item است که عناصر آن با آرگومان های ارائه شده به یک روش پیوند دهنده بوت استرپ مطابقت دارد. سه استدلال اول عبارتند از:

  1. دسته روش که نشان دهنده روش پیوند دهنده بوت استرپ (Value_Method_Handle) است.
  2. یک نام متد که پیوند دهنده بوت استرپ باید حل کند (Value_String).
  3. یک نوع متد متناسب با نوع نام روش حل شده (Value_Method_Type).

هرگونه آرگومان اضافی مقادیر ثابت است که به روش پیوند Bootstrap منتقل می شوند. این استدلال ها به ترتیب و بدون هیچ نوع تبدیل منتقل می شوند.

دسته روش که نشان دهنده روش اتصال دهنده bootstrap است باید دارای نوع برگشتی java.lang.invoke.CallSite باشد. سه نوع پارامتر اول عبارتند از:

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

انواع پارامتر هر آرگومان اضافی از مقادیر ثابت آنها تعیین می شود.

method_handle_item

در بخش Method_Handles ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
method_handle_type کوتاه نوع دسته روش ؛ جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
field_or_method_id کوتاه شناسه فیلد یا روش بسته به اینکه آیا نوع دسته روش یک دسترسی یا یک روش فراخوانی است
استفاده نشده کوتاه (استفاده نشده)

کدهای نوع دسته روش

ثابت ارزش توضیحات
method_handle_type_static_put 0x00 Method Hode یک تنظیم کننده فیلد استاتیک (Accessor) است
method_handle_type_static_get 0x01 Method Handle یک Field Static (Accessor) است
method_handle_type_instance_put 0x02 Method Handle یک قسمت نمونه (Accessor) است
method_handle_type_instance_get 0x03 Method Handle یک Field Field (Accessor) است
method_handle_type_invoke_static 0x04 Method Handle یک روش استاتیک است
method_handle_type_invoke_instance 0x05 Method Handle یک روش نمونه است
method_handle_type_invoke_constructor 0x06 Method Handle یک روش سازنده است
method_handle_type_invoke_direct 0x07 Method Handle یک روش مستقیم است
method_handle_type_invoke_interface 0x08 Method Handle یک روش رابط است

class_data_item

ارجاع شده از class_def_item

در بخش داده ظاهر می شود

تراز: هیچکدام (بایت هماهنگ)

نام قالب توضیحات
static_fields_size uleb128 تعداد زمینه های استاتیک تعریف شده در این مورد
sustance_fields_size uleb128 تعداد قسمتهای نمونه تعریف شده در این مورد
direct_methods_size uleb128 تعداد روشهای مستقیم تعریف شده در این مورد
virtual_methods_size uleb128 تعداد روشهای مجازی تعریف شده در این مورد
static_fields ended_field [static_fields_size] زمینه های استاتیک تعریف شده ، به عنوان دنباله ای از عناصر رمزگذاری شده نشان داده شده است. زمینه ها باید توسط field_idx به منظور افزایش نظم طبقه بندی شوند.
fields_fields ended_field [sustance_fields_size] زمینه های نمونه تعریف شده ، به عنوان دنباله ای از عناصر رمزگذاری شده نشان داده شده است. زمینه ها باید توسط field_idx به منظور افزایش نظم طبقه بندی شوند.
Direct_Methods ended_method [Direct_Methods_Size] تعریف مستقیم (هر یک از روشهای static ، private یا سازنده) ، به عنوان دنباله ای از عناصر رمزگذاری شده نشان داده شده است. روشها باید با افزایش نظم توسط method_idx طبقه بندی شوند.
virtual_methods ended_method [virtual_methods_size] روشهای مجازی تعریف شده (هیچ یک از static ، private یا سازنده) ، به عنوان دنباله ای از عناصر رمزگذاری شده نشان داده شده است. این لیست نباید شامل روشهای ارثی باشد ، مگر اینکه توسط کلاس که این مورد نشان می دهد ، نادیده گرفته شود. روشها باید با افزایش نظم توسط method_idx طبقه بندی شوند. method_idx یک روش مجازی نباید مانند هر روش مستقیم باشد.

توجه: همه موارد field_id و method_id همه عناصر باید به همان کلاس تعریف کننده مراجعه کنند.

قالب ended_field

نام قالب توضیحات
field_idx_diff uleb128 برای شناسایی هویت این قسمت (شامل نام و توصیف کننده) به لیست field_ids (شامل نام و توصیف کننده) است که به عنوان تفاوت از شاخص عنصر قبلی در لیست نشان داده شده است. شاخص عنصر اول در یک لیست به طور مستقیم نشان داده شده است.
access_flags uleb128 دسترسی به پرچم ها برای این زمینه ( public ، final و غیره). برای جزئیات بیشتر به "تعاریف access_flags " مراجعه کنید.

قالب ended_method

نام قالب توضیحات
method_idx_diff uleb128 برای هویت این روش به لیست method_ids فهرست کنید (شامل نام و توصیف کننده) است که به عنوان تفاوت از شاخص عنصر قبلی در لیست نشان داده شده است. شاخص عنصر اول در یک لیست به طور مستقیم نشان داده شده است.
access_flags uleb128 برای روش ( public ، final و غیره) به پرچم ها دسترسی پیدا کنید. برای جزئیات بیشتر به "تعاریف access_flags " مراجعه کنید.
code_off uleb128 از شروع پرونده به ساختار کد برای این روش جبران کنید ، 0 اگر این روش abstract یا native باشد. افست باید به مکانی در بخش data باشد. قالب داده ها توسط " code_item " در زیر مشخص شده است.

لیست_ه

ارجاع شده از class_def_item و proto_id_item

در بخش داده ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
اندازه unint اندازه لیست ، در ورودی ها
فهرست Type_item [اندازه] عناصر لیست

قالب_تیم

نام قالب توضیحات
type_idx کوتاه فهرست در لیست type_ids

code_item

ارجاع شده از encoded_method

در بخش داده ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
Registrs_Size کوتاه تعداد ثبت های مورد استفاده در این کد
ins_size کوتاه تعداد کلمات آرگومان های دریافتی به روشی که این کد برای آن وجود دارد
outs_size کوتاه تعداد کلمات فضای آرگومان خروجی مورد نیاز این کد برای دعوت روش
سعی کنید_ کوتاه تعداد try_item S برای این مثال. اگر غیر صفر باشد ، پس از آن به عنوان آرایه tries درست بعد از این insns ظاهر می شوند.
debug_info_off unint دنباله از شروع پرونده به اطلاعات اشکال زدایی (شماره خط + اطلاعات متغیر محلی) برای این کد ، یا 0 اگر اطلاعاتی وجود ندارد. در صورت غیر صفر ، افست باید به مکانی در بخش data باشد. قالب داده ها توسط " debug_info_item " در زیر مشخص شده است.
insns_size unint اندازه لیست دستورالعمل ها ، در واحدهای کد 16 بیتی
بدنام ushort [insns_size] آرایه واقعی بایت کد. قالب کد در یک آرایه insns توسط سند همراه Dalvik Bytecode مشخص شده است. توجه داشته باشید که اگرچه این به عنوان مجموعه ای از ushort تعریف شده است ، اما برخی از ساختارهای داخلی وجود دارند که تراز چهار بایت را ترجیح می دهند. همچنین ، اگر این اتفاق در یک فایل تغییر یافته Endian باشد ، مبادله فقط در نمونه های ushort فردی انجام می شود و نه در ساختارهای داخلی بزرگتر.
بالشتک ushort (اختیاری) = 0 دو بایت بالشتک برای tries چهار بایت هم تراز شده است. این عنصر فقط در صورتی وجود دارد که tries_size غیر صفر باشد و insns_size عجیب است.
تلاش می کند try_item [tries_size] (اختیاری) آرایه ای که نشان می دهد استثنائات کد در کجا گرفتار شده و نحوه رسیدگی به آنها را نشان می دهد. عناصر آرایه باید در محدوده و به ترتیب از آدرس کم به بالا ، غیر همپوشانی باشند. این عنصر فقط در صورتی وجود دارد که tries_size غیر صفر باشد.
کنترل کننده ها ended_catch_handler_list (اختیاری) بایت هایی که لیستی از لیست های انواع صید و آدرس های کنترل کننده مرتبط را نشان می دهد. هر try_item یک جبران بایت در این ساختار دارد. این عنصر فقط در صورتی وجود دارد که tries_size غیر صفر باشد.

قالب try_item

نام قالب توضیحات
start_addr unint آدرس بلوک کد تحت پوشش این ورودی را شروع کنید. آدرس تعداد واحدهای کد 16 بیتی برای شروع اولین دستورالعمل تحت پوشش است.
insn_count کوتاه تعداد واحدهای کد 16 بیتی تحت پوشش این ورودی. آخرین واحد کد تحت پوشش (شامل) start_addr + insn_count - 1 است.
handler_off کوتاه از ابتدای برنامه encoded_catch_hander_list به encoded_catch_handler برای این ورودی ، بایت را جبران کنید. این باید یک جبران برای شروع یک encoded_catch_handler باشد.

قالب ended_catch_handler_list

نام قالب توضیحات
اندازه uleb128 اندازه این لیست ، در ورودی ها
فهرست ended_catch_handler [handlers_size] لیست واقعی لیست های کنترل کننده ، که مستقیماً (نه به عنوان جبران) ارائه می شود ، و به صورت متوالی هماهنگ می شوند

قالب ended_catch_handler

نام قالب توضیحات
اندازه Sleb128 تعداد انواع صید در این لیست. اگر غیر مثبت باشد ، این منفی از تعداد انواع صید است و صید ها توسط یک کنترل کننده همه گیر دنبال می شوند. به عنوان مثال: size 0 به این معنی است که همه چیز صید وجود دارد اما صید صریح تایپ شده وجود ندارد. size 2 به این معنی است که دو صید صریح تایپ شده و بدون همه وجود دارد. و size -1 به این معنی است که یک گرفتن تایپ شده به همراه همه چیز وجود دارد.
کنترل کننده ها ended_type_addr_pair [abs (اندازه)] جریان abs(size) موارد رمزگذاری شده ، یکی برای هر نوع گرفتار ، به این ترتیب که انواع باید آزمایش شوند.
CATCH_ALL_ADDR uleb128 (اختیاری) آدرس bytecode از کنترل کننده همه گیر. این عنصر فقط در صورتی وجود دارد که size مثبت باشد.

قالب ended_type_addr_pair

نام قالب توضیحات
type_idx uleb128 برای نوع استثناء در لیست type_ids فهرست کنید
آدرس uleb128 آدرس bytecode از کنترل کننده استثنا مرتبط

debug_info_item

از code_item ارجاع شده است

در بخش داده ظاهر می شود

تراز: هیچکدام (بایت هماهنگ)

هر debug_info_item یک دستگاه حالت کدگذاری شده با کادوی با الهام از DWARF3 را تعریف می کند که در صورت تفسیر ، جدول موقعیت ها و (به طور بالقوه) اطلاعات متغیر محلی را برای یک code_item منتشر می کند. دنباله با یک هدر با طول متغیر شروع می شود (طول آن به تعداد پارامترهای روش بستگی دارد) ، توسط دستگاه های دستگاه BYTECODES دنبال می شود و با یک بایت DBG_END_SEQUENCE به پایان می رسد.

دستگاه دولتی از پنج ثبت نام تشکیل شده است. ثبت address نشان دهنده جبران دستورالعمل در insns_item مرتبط در واحدهای کد 16 بیتی است. ثبت address در ابتدای هر دنباله debug_info از 0 شروع می شود و فقط باید یکنواخت افزایش یابد. ثبت line نشان دهنده آنچه شماره خط منبع باید با ورودی جدول موقعیت های بعدی ساطع شده توسط دستگاه دولتی همراه باشد. این در هدر دنباله آغاز می شود و ممکن است در جهت های مثبت یا منفی تغییر کند اما هرگز نباید کمتر از 1 باشد. رجیستری source_file فایل منبع را نشان می دهد که ورودی های شماره خط به آن مراجعه می کنند. این به مقدار source_file_idx در class_def_item اولیه می شود. دو متغیر دیگر ، prologue_end و epilogue_begin ، پرچم های بولی هستند (به صورت false ) که نشان می دهد موقعیت بعدی ساطع شده باید یک روش پیشرو یا اپیولوژ در نظر گرفته شود. دستگاه دولتی همچنین باید نام و نوع آخرین متغیر محلی را در هر ثبت برای کد DBG_RESTART_LOCAL ردیابی کند.

هدر به شرح زیر است:

نام قالب توضیحات
خط_ uleb128 مقدار اولیه برای ثبت line دستگاه حالت. ورود به موقعیت های واقعی را نشان نمی دهد.
parameters_size uleb128 تعداد نام پارامترهای رمزگذاری شده. در صورت this ، باید یک پارامتر در هر روش وجود داشته باشد.
parameter_names ULEB128P1 [PARATERS_SIZE] شاخص رشته نام پارامتر روش. مقدار رمزگذاری شده NO_INDEX نشان می دهد که هیچ نامی برای پارامتر مرتبط در دسترس نیست. توصیف کننده و امضای نوع از توصیف کننده روش و امضای آن دلالت دارد.

مقادیر کد بایت به شرح زیر است:

نام ارزش قالب استدلال ها توضیحات
DBG_END_SEQUENCE 0x00 (هیچ کدام) یک دنباله اطلاعات اشکال زدایی را برای یک code_item خاتمه می دهد
dbg_advance_pc 0x01 uleb128 addr_diff addr_diff : مبلغی را برای اضافه کردن به آدرس ثبت نام کنید ثبت نام آدرس را بدون انتشار ورودی موقعیت ها پیشرفت می کند
dbg_advance_line 0x02 sleb128 line_diff line_diff : مبلغی را برای تغییر ثبت خط توسط ثبت نام خط را بدون انتشار ورودی موقعیت پیشرفت می کند
dbg_start_local 0x03 ULEB128 Register_num
ULEB128P1 name_idx
uleb128p1 type_idx
register_num : ثبت نام کنید که حاوی محلی باشد
name_idx : فهرست رشته نام
type_idx : نوع شاخص از نوع
یک متغیر محلی را در آدرس فعلی معرفی می کند. یا name_idx یا type_idx ممکن است NO_INDEX باشد تا نشان دهد که این مقدار ناشناخته است.
dbg_start_local_extended 0x04 ULEB128 Register_num
ULEB128P1 name_idx
uleb128p1 type_idx
uleb128p1 sig_idx
register_num : ثبت نام کنید که حاوی محلی باشد
name_idx : فهرست رشته نام
type_idx : نوع شاخص از نوع
sig_idx : شاخص رشته از نوع امضای
یک محلی را با یک نوع امضای در آدرس فعلی معرفی می کند. هر یک از name_idx ، type_idx یا sig_idx ممکن است NO_INDEX باشد تا نشان دهد که این مقدار ناشناخته است. (اگر sig_idx -1 باشد ، هرچند ، داده های مشابه می توانند با استفاده از Opcode DBG_START_LOCAL با کارآمدتر نشان داده شوند.)

توجه: بحث در زیر " dalvik.annotation.Signature " را در زیر برای احتیاط در مورد رسیدگی به امضاها مشاهده کنید.

dbg_end_local 0x05 ULEB128 Register_num register_num : ثبت نام کنید محلی یک متغیر محلی در حال حاضر زندگی را به عنوان خارج از محدوده در آدرس فعلی نشان می دهد
dbg_restart_local 0x06 ULEB128 Register_num register_num : برای راه اندازی مجدد ثبت نام کنید دوباره یک متغیر محلی را در آدرس فعلی معرفی می کند. نام و نوع همان آخرین محلی است که در ثبت نام مشخص شده است.
dbg_set_prologue_end 0x07 (هیچ کدام) ثبت دستگاه prologue_end حالت را تنظیم می کند ، نشان می دهد که ورودی موقعیت بعدی که اضافه می شود باید پایان یک روش پیش نویس در نظر گرفته شود (یک مکان مناسب برای یک نقطه شکست روش). ثبت نام prologue_end توسط هر opcode خاص ( >= 0x0a ) پاک می شود.
dbg_set_epilogue_begin 0x08 (هیچ کدام) ثبت دستگاه حالت epilogue_begin را تنظیم می کند ، نشان می دهد که ورود موقعیت بعدی که اضافه می شود باید آغاز یک روش Epilogue (مکانی مناسب برای تعلیق اجرای قبل از خروج روش) در نظر گرفته شود. رجیستری epilogue_begin توسط هر opcode خاص ( >= 0x0a ) پاک می شود.
dbg_set_file 0x09 ULEB128P1 name_idx name_idx : فهرست رشته نام پرونده منبع ؛ NO_INDEX اگر ناشناخته باشد نشان می دهد که تمام ورودی های شماره خط بعدی به جای نام پیش فرض مشخص شده در code_item ، به این نام پرونده منبع مراجعه می کنند
کد های خاص 0x0a… 0xff (هیچ کدام) ثبت نام line و address را پیشرفت می کند ، یک موقعیت را منتشر می کند و prologue_end و epilogue_begin پاک می کند. برای توضیحات به زیر مراجعه کنید.

کد های خاص

Opcodes با مقادیر بین 0x0a و 0xff (فراگیر) هر دو line و address را با مقدار کمی منتقل می کنند و سپس یک جدول موقعیت جدید را منتشر می کنند. فرمول افزایش به شرح زیر است:

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

ارجاع شده از class_def_item

در بخش داده ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
class_annotations_off unint از ابتدای پرونده به حاشیه نویسی های ساخته شده به طور مستقیم در کلاس ، یا 0 اگر کلاس حاشیه ای مستقیم نداشته باشد ، جبران کنید. در صورت غیر صفر ، افست باید به مکانی در بخش data باشد. قالب داده ها توسط " annotation_set_item " در زیر مشخص شده است.
fields_size unint تعداد زمینه های حاشیه نویسی شده توسط این مورد
Annotated_Methods_Size unint تعداد روشهای حاشیه نویسی شده توسط این مورد
Annotated_Parameters_Size unint تعداد پارامتر متد لیستی که توسط این مورد حاشیه نویسی شده است
Annotations Field_annotations field_annotation [fields_size] (اختیاری) لیست حاشیه نویسی های میدانی مرتبط. عناصر لیست باید توسط field_idx به ترتیب در حال افزایش مرتب شوند.
method_annotations method_annotation [methods_size] (اختیاری) لیست حاشیه نویسی روش مرتبط. عناصر لیست باید به ترتیب توسط method_idx مرتب شوند.
parameter_annotations parameter_annotation [parameters_size] (اختیاری) لیست حاشیه نویسی پارامتر روش مرتبط. عناصر لیست باید به ترتیب توسط method_idx مرتب شوند.

توجه: همه موارد field_id و method_id همه عناصر باید به همان کلاس تعریف کننده مراجعه کنند.

FIELD_ANNOTATION

نام قالب توضیحات
field_idx unint برای شناسایی هویت این قسمت که در آن حاشیه نویسی می شود ، به لیست field_ids فهرست شوید
Annotations_Off unint از ابتدای پرونده به لیست حاشیه نویسی های این قسمت جبران کنید. افست باید به مکانی در بخش data باشد. قالب داده ها توسط " annotation_set_item " در زیر مشخص شده است.

قالب_نوتینگ

نام قالب توضیحات
method_idx unint برای هویت روش حاشیه نویسی به لیست method_ids فهرست شوید
Annotations_Off unint از شروع پرونده به لیست حاشیه نویسی برای روش جبران کنید. افست باید به مکانی در بخش data باشد. قالب داده ها توسط " annotation_set_item " در زیر مشخص شده است.

فرمت پارامتر_نوتیک

نام قالب توضیحات
method_idx unint برای هویت روشی که پارامترهای آن در حال حاشیه نویسی هستند ، به لیست method_ids فهرست شوید
Annotations_Off unint از شروع پرونده به لیست حاشیه نویسی برای پارامترهای روش جبران کنید. افست باید به مکانی در بخش data باشد. قالب داده ها توسط " annotation_set_ref_list " در زیر مشخص شده است.

Annotation_Set_Ref_List

ارجاع شده از parameter_annotations_item

در بخش داده ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
اندازه unint اندازه لیست ، در ورودی ها
فهرست Annotation_set_ref_item [اندازه] عناصر لیست

Annotation_set_ref_item فرمت

نام قالب توضیحات
Annotations_Off unint در صورت عدم حاشیه نویسی برای این عنصر ، از شروع پرونده به مجموعه حاشیه نویسی ارجاع شده یا 0 جبران کنید. در صورت غیر صفر ، افست باید به مکانی در بخش data باشد. قالب داده ها توسط " annotation_set_item " در زیر مشخص شده است.

Annotation_set_item

ارجاع شده از Annotations_directory_item ، field_annotations_item ، method_annotations_item ، و حاشیه نویسی_Set_Ref_Item

در بخش داده ظاهر می شود

تراز: 4 بایت

نام قالب توضیحات
اندازه unint اندازه مجموعه ، در ورودی ها
ورودی ها حاشیه نویسی_OFF_ITEM [اندازه] عناصر مجموعه عناصر باید به ترتیب در حال افزایش type_idx شوند.

Annotation_Off_Item

نام قالب توضیحات
حاشیه نویسی_ف unint از ابتدای پرونده به حاشیه نویسی جبران کنید. افست باید به مکانی در بخش data باشد و قالب داده ها در آن مکان توسط " annotation_item " در زیر مشخص شده است.

حاشیه نویسی_ITEM

ارجاع شده از Annotation_set_item

در بخش داده ظاهر می شود

تراز: هیچکدام (بایت هماهنگ)

نام قالب توضیحات
دید یوبایت دید در نظر گرفته شده از این حاشیه نویسی (به تصویر زیر مراجعه کنید)
حاشیه نویسی رمزگذاری شده_نوتیک محتوای حاشیه نویسی رمزگذاری شده ، در قالب شرح داده شده توسط "قالب encoded_annotation " در زیر "رمزگذاری encoded_value " در بالا.

مقادیر دید

این گزینه ها برای قسمت visibility در annotation_item است:

نام ارزش توضیحات
Visibility_Build 0x00 در نظر گرفته شده فقط در زمان ساخت قابل مشاهده است (به عنوان مثال ، در هنگام تدوین کد دیگر)
دیدنی_ 0x01 در زمان اجرا قابل مشاهده است
Visibility_System 0x02 در نظر گرفته شده در زمان اجرا قابل مشاهده است ، اما فقط به سیستم زیرین (و نه کد کاربر معمولی)

ended_array_item

ارجاع شده از class_def_item

در بخش داده ظاهر می شود

تراز: هیچکدام (بایت هماهنگ)

نام قالب توضیحات
ارزش رمزگذاری شده_آرایه بایت های نمایانگر مقدار آرایه رمزگذاری شده ، در قالب مشخص شده توسط "فرمت encoded_array " در زیر "رمزگذاری encoded_value " در بالا.

hiddenapi_class_data_item

این بخش شامل داده هایی در مورد رابط های محدود شده توسط هر کلاس است.

توجه: ویژگی API پنهان در Android 10.0 معرفی شده است و فقط برای پرونده های DEX کلاس در مسیر کلاس بوت کاربرد دارد. لیست پرچم های شرح داده شده در زیر ممکن است در نسخه های آینده اندروید گسترش یابد. برای اطلاعات بیشتر ، به محدودیت های رابط های غیر SDK مراجعه کنید.

نام قالب توضیحات
اندازه unint اندازه کل بخش
جبران می کند uint [] آرایه ای از جبران های فهرست شده توسط class_idx . ورود به آرایه صفر در index class_idx به این معنی است که یا هیچ داده ای برای این class_idx وجود ندارد ، یا تمام پرچم های API پنهان صفر هستند. در غیر این صورت ، ورودی آرایه غیر صفر است و از ابتدای بخش به آرایه ای از پرچم های API پنهان برای این class_idx جبران می شود.
پرچم ها uleb128 [] آرایه های جمع شده از پرچم های API پنهان برای هر کلاس. مقادیر پرچم احتمالی در جدول زیر شرح داده شده است. پرچم ها به همان ترتیب رمزگذاری می شوند که زمینه ها و روش ها در داده های کلاس رمزگذاری می شوند.

انواع پرچم محدودیت:

نام ارزش توضیحات
لیست سفید 0 رابط هایی که می توانند آزادانه مورد استفاده قرار گیرند و به عنوان بخشی از شاخص بسته بندی فریم ورک رسمی Android که به طور رسمی مستند شده اند پشتیبانی می شوند.
چلپلیست 1 رابط های غیر SDK که بدون در نظر گرفتن سطح API هدف برنامه قابل استفاده هستند.
لیست سیاه 2 رابط های غیر SDK که بدون در نظر گرفتن سطح API هدف برنامه قابل استفاده نیستند. دسترسی به یکی از این رابط ها باعث ایجاد خطای زمان اجرا می شود.
greylist - max - o 3 رابط های غیر SDK که می توانند برای Android 8.x و پایین استفاده شوند مگر اینکه محدود شوند.
greylist - max - p 4 رابط های غیر SDK که می توانند برای Android 9.x استفاده شوند مگر اینکه محدود شوند.
greylist - max - q 5 رابط های غیر SDK که می توانند برای Android 10.x استفاده شوند مگر اینکه محدود شوند.
greylist - max - r 6 رابط های غیر SDK که می توانند برای Android 11.x استفاده شوند ، مگر اینکه محدود شوند.

حاشیه نویسی سیستم

حاشیه نویسی سیستم برای نشان دادن قطعات مختلف اطلاعات بازتابی در مورد کلاس ها (و روش ها و زمینه ها) استفاده می شود. این اطلاعات به طور کلی فقط به طور غیرمستقیم توسط کد مشتری (غیر سیستم) قابل دسترسی است.

حاشیه نویسی سیستم در پرونده های .dex به عنوان حاشیه نویسی با دیدنی در VISIBILITY_SYSTEM نشان داده شده است.

dalvik.annotation.annotationDefault

در روشهای رابط حاشیه نویسی ظاهر می شود

حاشیه نویسی AnnotationDefault به هر رابط حاشیه نویسی پیوست شده است که مایل به نشان دادن اتصالات پیش فرض است.

نام قالب توضیحات
ارزش حاشیه نویسی اتصالات پیش فرض برای این حاشیه نویسی ، به عنوان حاشیه نویسی از این نوع نشان داده شده است. نیازی به حاشیه نویسی شامل تمام نام های تعریف شده توسط حاشیه نویسی نیست. نام های گمشده به سادگی پیش فرض ندارند.

dalvik.annotation.enclosingclass

در کلاس ها ظاهر می شود

حاشیه نویسی EnclosingClass به هر کلاس متصل می شود که یا به عنوان عضو کلاس دیگری ، به خودی خود تعریف می شود ، یا ناشناس است اما در یک بدنه روش تعریف نشده است (به عنوان مثال ، یک کلاس داخلی مصنوعی). هر کلاس که این حاشیه نویسی را داشته باشد نیز باید حاشیه نویسی InnerClass داشته باشد. علاوه بر این ، یک کلاس نباید هم دارای یک EnclosingClass و هم حاشیه EnclosingMethod باشد.

نام قالب توضیحات
ارزش کلاس کلاس که از نزدیک از نظر واژگونی این کلاس را انتخاب می کند

dalvik.annotation.enclosingmethod

در کلاس ها ظاهر می شود

حاشیه نویسی EnclosingMethod به هر کلاس وصل شده است که در داخل یک بدنه روش تعریف شده است. هر کلاس که این حاشیه نویسی را داشته باشد نیز باید حاشیه نویسی InnerClass داشته باشد. علاوه بر این ، یک کلاس نباید هم دارای یک EnclosingClass و هم حاشیه EnclosingMethod باشد.

نام قالب توضیحات
ارزش روش روشی که از نزدیک از نظر واژگونی این کلاس را انتخاب می کند

dalvik.annotation.innerclass

در کلاس ها ظاهر می شود

حاشیه نویسی InnerClass به هر کلاس متصل می شود که در دامنه واژگانی تعریف کلاس دیگر تعریف شده است. هر کلاس که این حاشیه نویسی را داشته باشد نیز باید دارای حاشیه نویسی EnclosingClass یا حاشیه نویسی EnclosingMethod باشد.

نام قالب توضیحات
نام رشته نام ساده این کلاس در ابتدا اعلام شده است (شامل پیشوند بسته ای نیست). اگر این کلاس ناشناس باشد ، نام آن null است.
AccessFlags بین المللی پرچم های دسترسی در ابتدا اعلام شده کلاس (که ممکن است به دلیل عدم تطابق بین مدل های اجرای زبان منبع و ماشین مجازی هدف با پرچم های مؤثر متفاوت باشد)

dalvik.annotation.MemberClasses

در کلاس ها ظاهر می شود

حاشیه نویسی MemberClasses به هر کلاس متصل می شود که کلاس های عضو را اعلام می کند. (کلاس عضو یک کلاس داخلی مستقیم است که نام دارد.)

نام قالب توضیحات
ارزش کلاس [] مجموعه ای از کلاس های عضو

dalvik.annotation.methodparameters

در روش ها ظاهر می شود

توجه: این حاشیه نویسی پس از Android 7.1 اضافه شد. حضور آن در نسخه های قبلی اندرویدی نادیده گرفته می شود.

حاشیه نویسی MethodParameters اختیاری است و می تواند برای ارائه ابرداده پارامتر مانند نام پارامترها و اصلاح کننده ها استفاده شود.

هنگامی که ابرداده پارامتر در زمان اجرا لازم نیست ، حاشیه نویسی را می توان با خیال راحت از یک روش یا سازنده حذف کرد. java.lang.reflect.Parameter.isNamePresent() می تواند برای بررسی اینکه آیا ابرداده برای یک پارامتر وجود دارد ، استفاده شود و روش های بازتاب مرتبط مانند java.lang.reflect.Parameter.getName() اگر اطلاعات موجود نباشد به رفتار پیش فرض در زمان اجرا باز می گردد.

در صورت شامل ابرداده پارامتر ، کامپایلرها باید اطلاعاتی را برای کلاسهای تولید شده مانند عناصر شامل شوند ، زیرا ابرداده پارامتر شامل این است که آیا یک پارامتر مصنوعی یا اجباری است یا خیر.

حاشیه نویسی MethodParameters فقط پارامترهای روش فردی را توصیف می کند. بنابراین ، کامپایلرها ممکن است حاشیه نویسی را کاملاً برای سازندگان و روشهایی که هیچ پارامتری ندارند ، به دلیل اندازه کد و راندمان زمان اجرا حذف کنند.

آرایه های مستند شده در زیر باید به همان اندازه برای ساختار method_id_item DEX مرتبط با روش باشد ، در غیر این صورت یک java.lang.reflect.MalformedParametersException در زمان اجرا پرتاب می شود.

یعنی: method_id_item.proto_idx -> proto_id_item.parameters_off -> type_list.size باید همان names().length و accessFlags().length .

از آنجا که MethodParameters تمام پارامترهای روش رسمی را توصیف می کند ، حتی آنهایی که به طور صریح یا ضمنی در کد منبع اعلام نشده اند ، اندازه آرایه ها ممکن است با امضای یا سایر اطلاعات ابرداده متفاوت باشد که فقط بر روی پارامترهای صریح اعلام شده در کد منبع استوار است. MethodParameters همچنین هیچ اطلاعاتی در مورد پارامترهای گیرنده حاشیه نویسی نوع که در امضای روش واقعی وجود ندارند ، شامل نمی شود.

نام قالب توضیحات
نام ها رشته[] نام پارامترهای رسمی برای روش مرتبط. آرایه نباید تهی باشد اما در صورت عدم وجود پارامتر رسمی ، باید خالی باشد. اگر پارامتر رسمی با آن شاخص نامی نداشته باشد ، باید یک مقدار در آرایه تهی باشد.
اگر رشته های نام پارامتر خالی هستند یا حاوی "" ، "؛" ، "[" یا "/" هستند ، سپس java.lang.reflect.MalformedParametersException در زمان اجرا پرتاب می شود.
AccessFlags بین المللی[] پرچم های دسترسی پارامترهای رسمی برای روش مرتبط. آرایه نباید تهی باشد اما در صورت عدم وجود پارامتر رسمی ، باید خالی باشد.
مقدار کمی ماسک با مقادیر زیر است:
  • 0x0010: نهایی ، پارامتر نهایی اعلام شد
  • 0x1000: مصنوعی ، پارامتر توسط کامپایلر معرفی شد
  • 0x8000: اجباری ، پارامتر مصنوعی است اما همچنین با مشخصات زبان دلالت دارد
اگر هر بیت در خارج از این مجموعه تنظیم شود ، یک java.lang.reflect.MalformedParametersException در زمان اجرا پرتاب می شود.

dalvik.annotation.Signature

در کلاس ها ، زمینه ها و روش ها ظاهر می شود

حاشیه نویسی Signature به هر کلاس ، فیلد یا روشی که از نظر نوع پیچیده تری تعریف شده است از آنچه توسط یک type_id_item قابل نمایش است ، ضمیمه شده است. قالب .dex فرمت امضاها را تعریف نمی کند. این صرفاً به معنای این است که بتوانیم هرگونه امضایی را که یک زبان منبع برای اجرای موفقیت آمیز معناشناسی آن زبان نیاز دارد ، نشان دهد. به این ترتیب ، امضاها به طور کلی توسط پیاده سازی دستگاه های مجازی تجزیه نمی شوند (یا تأیید می شوند). امضاها به سادگی به API ها و ابزارهای سطح بالاتر (مانند اشکال زدایی) واگذار می شوند. بنابراین ، هرگونه استفاده از امضای باید نوشته شود تا هیچ فرضیه ای در مورد فقط دریافت امضاهای معتبر انجام ندهد ، و صریحاً خود را در برابر احتمال ورود به امضای غیرقانونی به صورت غیرقانونی محافظت می کند.

از آنجا که رشته های امضای تمایل به محتوای تکثیر زیادی دارند ، حاشیه نویسی Signature به عنوان مجموعه ای از رشته ها تعریف می شود ، جایی که عناصر تکراری به طور طبیعی به همان داده های اساسی اشاره می کنند و امضای آن برای هماهنگی همه رشته های موجود در آرایه است. هیچ قانونی در مورد چگونگی جدا کردن یک امضا به رشته های جداگانه وجود ندارد. این کاملاً مربوط به ابزارهایی است که پرونده های .dex را تولید می کنند.

نام قالب توضیحات
ارزش رشته[] امضای این کلاس یا عضو ، به عنوان مجموعه ای از رشته ها که باید با هم جمع شوند

dalvik.annotation.throws

در روش ها ظاهر می شود

حاشیه نویسی Throws به هر روش متصل می شود که اعلام می شود یک یا چند نوع استثنا را پرتاب می کند.

نام قالب توضیحات
ارزش کلاس [] مجموعه ای از انواع استثنائی پرتاب شده
،

این سند طرح و محتوای پرونده های .dex را که برای نگه داشتن مجموعه ای از تعاریف کلاس و داده های کمکی مرتبط با آنها استفاده می شود ، توصیف می کند.

راهنمای انواع

نام توضیحات
بایت 8 بیتی امضا شده int
یوبایت int بدون امضا 8 بیتی
کوتاه 16 بیتی امضا شده int ، اندکی کوچک
کوتاه int بدون امضا 16 بیتی ، اندکی کوچک
بین المللی 32 بیتی امضا شده int ، اندکی کوچک
unint 32 بیتی بدون امضاء ، اندکی کوچک
طولانی 64 بیتی امضا شده int ، اندکی کوچک
طولانی int بدون امضا 64 بیتی ، اندکی کوچک
Sleb128 LEB128 امضا شده ، طول متغیر (به تصویر زیر مراجعه کنید)
uleb128 LEB128 بدون امضا ، طول متغیر (به تصویر زیر مراجعه کنید)
uleb128p1 امضا نشده LEB128 به علاوه 1 ، طول متغیر (به تصویر زیر مراجعه کنید)

LEB128

LEB128 (" l ittle- e 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
7f -1 127 126
80 7f -128 16256 16255

طرح بندی فایل

نام قالب توضیحات
هدر header_item هدر
string_ids string_id_item [] لیست شناسه های رشته ای. اینها شناسه هایی برای تمام رشته های مورد استفاده در این پرونده ، یا برای نامگذاری داخلی (به عنوان مثال ، توصیف کننده های نوع) یا به عنوان اشیاء ثابت است که توسط کد به آنها گفته می شود. این لیست باید با استفاده از مقادیر نقطه کد UTF-16 (نه به روش حساس به محلی) بر اساس محتوای رشته ای طبقه بندی شود و نباید شامل هیچ ورودی کپی باشد.
type_ids type_id_item [] لیست شناسه ها را تایپ کنید. اینها شناسه هایی برای انواع (کلاس ها ، آرایه ها یا انواع ابتدایی) است که توسط این پرونده به آنها اشاره شده است ، چه در پرونده تعریف شده باشد یا خیر. این لیست باید بر اساس فهرست string_id مرتب شود ، و نباید شامل هیچ ورودی کپی باشد.
proto_ids proto_id_item [] لیست شناسه های نمونه اولیه روش. اینها شناسه هایی برای کلیه نمونه های اولیه است که توسط این پرونده به آنها اشاره شده است. این لیست باید در نوع برگشتی (براساس شاخص type_id ) مرتب سازی شود ، و سپس توسط لیست آرگومان (ترتیب واژگونی ، آرگومان های فردی که توسط شاخص type_id سفارش داده شده است). این لیست نباید حاوی هیچ ورودی تکراری باشد.
field_ids field_id_item [] لیست شناسه های میدانی. اینها شناسه هایی برای همه زمینه های ذکر شده توسط این پرونده است ، چه در پرونده تعریف شده باشد یا خیر. این لیست باید مرتب شود ، جایی که نوع تعیین کننده (بر اساس فهرست type_id ) ترتیب اصلی ، نام فیلد (توسط string_id شاخص) سفارش واسطه است و نوع (بر اساس فهرست type_id ) نظم جزئی است. این لیست نباید حاوی هیچ ورودی تکراری باشد.
Method_ids method_id_item [] لیست شناسه های روش. اینها شناسه هایی برای کلیه روشهای ذکر شده توسط این پرونده است ، چه در پرونده تعریف شده باشد یا خیر. این لیست باید مرتب شود ، جایی که نوع تعیین کننده (بر اساس شاخص type_id ) ترتیب اصلی ، نام روش (توسط string_id شاخص) ترتیب واسطه است و نمونه اولیه روش (توسط شاخص proto_id ) نظم جزئی است. این لیست نباید حاوی هیچ ورودی تکراری باشد.
class_defs class_def_item [] لیست تعاریف کلاس. کلاس ها باید به گونه ای سفارش داده شوند که سوپر کلاس کلاس و رابط های اجرا شده در لیست زودتر از کلاس مراجعه کننده در لیست ظاهر شوند. علاوه بر این ، برای تعریف یک کلاس مشابه بیش از یک بار در لیست نامعتبر است.
call_site_ids call_site_id_item [] با لیست شناسه های سایت تماس بگیرید. اینها شناسه هایی برای کلیه سایتهای تماس است که توسط این پرونده به آنها اشاره شده است ، چه در پرونده تعریف شده باشد یا خیر. این لیست باید به ترتیب صعودی call_site_off مرتب شود.
method_handles method_handle_item [] لیست دسته روش ها. لیستی از کلیه دسته های روش اشاره شده توسط این پرونده ، چه در پرونده تعریف شده باشد یا خیر. این لیست طبقه بندی نشده است و ممکن است حاوی کپی باشد که به طور منطقی با نمونه های دسته مختلف مطابقت خواهد داشت.
داده ها اوبیت [] data area, containing all the support data for the tables listed above. Different items have different alignment requirements, and padding bytes are inserted before each item if necessary to achieve proper alignment.
link_data ubyte[] data used in statically linked files. The format of the data in this section is left unspecified by this document. This section is empty in unlinked files, and runtime implementations may use it as they see fit.

قالب کانتینر

Version 41 introduces a new container format for DEX data with the goal to save space. This container format allows several logical DEX files to be combined into a single physical file. The new format is mostly just naive concatenation of files in the previous format, with some differences:

  • The file_size is the size of the logical file, not the physical file. It can be used to iterate over all the logical files in the container.
  • Logical dex files may reference any later data in the container (but not earlier). This allows dex files to share data, such as strings, between them.
  • All offsets are relative to the physical file. No offset is relative to the header. This is ensures that sections with offsets can be shared between logical files.
  • The header adds two new fields to describe the bounds of the container. This is an additional consistency check and makes porting code to the new format easier.
  • The data_size and data_off are now unused. Data can be spread across multiple logical files and does not have to be contiguous.

Bitfield, string, and constant definitions

DEX_FILE_MAGIC

Embedded in header_item

The constant array/string DEX_FILE_MAGIC is the list of bytes that must appear at the beginning of a .dex file in order for it to be recognized as such. The value intentionally contains a newline ( "\n" or 0x0a ) and a null byte ( "\0" or 0x00 ) in order to help in the detection of certain forms of corruption. The value also encodes a format version number as three decimal digits, which is expected to increase monotonically over time as the format evolves.

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

Note: Support for version 040 of the format was added in the Android 10.0 release, which extended the set of allowed characters in SimpleNames .

Note: Support for version 039 of the format was added in the Android 9.0 release, which introduced two new bytecodes, const-method-handle and const-method-type . (These are each described in the Summary of bytecode set table.) In Android 10, version 039 extends the DEX file format to include hidden API information that's only applicable to DEX files on the boot class path.

Note: Support for version 038 of the format was added in the Android 8.0 release. Version 038 added new bytecodes ( invoke-polymorphic and invoke-custom ) and data for method handles.

Note: Support for version 037 of the format was added in the Android 7.0 release. Prior to version 037 most versions of Android have used version 035 of the format. The only difference between versions 035 and 037 is the addition of default methods and the adjustment of the invoke .

Note: At least a couple earlier versions of the format have been used in widely available public software releases. For example, version 009 was used for the M3 releases of the Android platform (November–December 2007), and version 013 was used for the M5 releases of the Android platform (February–March 2008). In several respects, these earlier versions of the format differ significantly from the version described in this document.

ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT

Embedded in header_item

The constant ENDIAN_CONSTANT is used to indicate the endianness of the file in which it is found. Although the standard .dex format is little-endian, implementations may choose to perform byte-swapping. Should an implementation come across a header whose endian_tag is REVERSE_ENDIAN_CONSTANT instead of ENDIAN_CONSTANT , it would know that the file has been byte-swapped from the expected form.

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

NO_INDEX

Embedded in class_def_item and debug_info_item

The constant NO_INDEX is used to indicate that an index value is absent.

Note: This value isn't defined to be 0 , because that is in fact typically a valid index.

The chosen value for NO_INDEX is representable as a single byte in the uleb128p1 encoding.

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

access_flags definitions

Embedded in class_def_item, encoded_field, encoded_method, and InnerClass

Bitfields of these flags are used to indicate the accessibility and overall properties of classes and class members.

نام ارزش For Classes (and InnerClass annotations) For Fields For Methods
ACC_PUBLIC 0x1 public : visible everywhere public : visible everywhere public : visible everywhere
ACC_PRIVATE 0x2 * private : only visible to defining class private : only visible to defining class private : only visible to defining class
ACC_PROTECTED 0x4 * protected : visible to package and subclasses protected : visible to package and subclasses protected : visible to package and subclasses
ACC_STATIC 0x8 * static : is not constructed with an outer this reference static : global to defining class static : does not take a this argument
ACC_FINAL 0x10 final : not subclassable final : immutable after construction final : not overridable
ACC_SYNCHRONIZED 0x20 synchronized : associated lock automatically acquired around call to this method.

Note: This is only valid to set when ACC_NATIVE is also set.

ACC_VOLATILE 0x40 volatile : special access rules to help with thread safety
ACC_BRIDGE 0x40 bridge method, added automatically by compiler as a type-safe bridge
ACC_TRANSIENT 0x80 transient : not to be saved by default serialization
ACC_VARARGS 0x80 last argument should be treated as a "rest" argument by compiler
ACC_NATIVE 0x100 native : implemented in native code
ACC_INTERFACE 0x200 interface : multiply-implementable abstract class
ACC_ABSTRACT 0x400 abstract : not directly instantiable abstract : unimplemented by this class
ACC_STRICT 0x800 strictfp : strict rules for floating-point arithmetic
ACC_SYNTHETIC 0x1000 not directly defined in source code not directly defined in source code not directly defined in source code
ACC_ANNOTATION 0x2000 declared as an annotation class
ACC_ENUM 0x4000 declared as an enumerated type declared as an enumerated value
(استفاده نشده) 0x8000
ACC_CONSTRUCTOR 0x10000 constructor method (class or instance initializer)
ACC_DECLARED_
همگام
0x20000 declared synchronized .

Note: This has no effect on execution (other than in reflection of this flag, per se).

* Only allowed on for InnerClass annotations, and must not ever be on in a class_def_item .

Modified UTF-8 encoding

As a concession to easier legacy support, the .dex format encodes its string data in a de facto standard modified UTF-8 form, hereafter referred to as MUTF-8. This form is identical to standard UTF-8, except:

  • Only the one-, two-, and three-byte encodings are used.
  • Code points in the range U+10000U+10ffff are encoded as a surrogate pair, each of which is represented as a three-byte encoded value.
  • The code point U+0000 is encoded in two-byte form.
  • A plain null byte (value 0 ) indicates the end of a string, as is the standard C language interpretation.

The first two items above can be summarized as: MUTF-8 is an encoding format for UTF-16, instead of being a more direct encoding format for Unicode characters.

The final two items above make it simultaneously possible to include the code point U+0000 in a string and still manipulate it as a C-style null-terminated string.

However, the special encoding of U+0000 means that, unlike normal UTF-8, the result of calling the standard C function strcmp() on a pair of MUTF-8 strings does not always indicate the properly signed result of comparison of unequal strings. When ordering (not just equality) is a concern, the most straightforward way to compare MUTF-8 strings is to decode them character by character, and compare the decoded values. (However, more clever implementations are also possible.)

Please refer to The Unicode Standard for further information about character encoding. MUTF-8 is actually closer to the (relatively less well-known) encoding CESU-8 than to UTF-8 per se.

encoded_value encoding

Embedded in annotation_element and encoded_array_item

An encoded_value is an encoded piece of (nearly) arbitrary hierarchically structured data. The encoding is meant to be both compact and straightforward to parse.

نام قالب توضیحات
(value_arg << 5) | value_type یوبایت byte indicating the type of the immediately subsequent value along with an optional clarifying argument in the high-order three bits. See below for the various value definitions. In most cases, value_arg encodes the length of the immediately-subsequent value in bytes, as (size - 1) , eg, 0 means that the value requires one byte, and 7 means it requires eight bytes; however, there are exceptions as noted below.
ارزش ubyte[] bytes representing the value, variable in length and interpreted differently for different value_type bytes, though always little-endian. See the various value definitions below for details.

Value formats

نام را تایپ کنید value_type value_arg Format value Format توضیحات
VALUE_BYTE 0x00 (none; must be 0 ) ubyte[1] signed one-byte integer value
VALUE_SHORT 0x02 size - 1 (0…1) ubyte[size] signed two-byte integer value, sign-extended
VALUE_CHAR 0x03 size - 1 (0…1) ubyte[size] unsigned two-byte integer value, zero-extended
VALUE_INT 0x04 size - 1 (0…3) ubyte[size] signed four-byte integer value, sign-extended
VALUE_LONG 0x06 size - 1 (0…7) ubyte[size] signed eight-byte integer value, sign-extended
VALUE_FLOAT 0x10 size - 1 (0…3) ubyte[size] four-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 32-bit floating point value
VALUE_DOUBLE 0x11 size - 1 (0…7) ubyte[size] eight-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 64-bit floating point value
VALUE_METHOD_TYPE 0x15 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the proto_ids section and representing a method type value
VALUE_METHOD_HANDLE 0x16 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_handles section and representing a method handle value
VALUE_STRING 0x17 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the string_ids section and representing a string value
VALUE_TYPE 0x18 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the type_ids section and representing a reflective type/class value
VALUE_FIELD 0x19 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing a reflective field value
VALUE_METHOD 0x1a size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_ids section and representing a reflective method value
VALUE_ENUM 0x1b size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing the value of an enumerated type constant
VALUE_ARRAY 0x1c (none; must be 0 ) encoded_array an array of values, in the format specified by " encoded_array format" below. The size of the value is implicit in the encoding.
VALUE_ANNOTATION 0x1d (none; must be 0 ) encoded_annotation a sub-annotation, in the format specified by " encoded_annotation format" below. The size of the value is implicit in the encoding.
VALUE_NULL 0x1e (none; must be 0 ) (هیچ کدام) null reference value
VALUE_BOOLEAN 0x1f boolean (0…1) (هیچ کدام) one-bit value; 0 for false and 1 for true . The bit is represented in the value_arg .

encoded_array format

نام قالب توضیحات
اندازه uleb128 تعداد عناصر در آرایه
ارزش ها encoded_value[size] a series of size encoded_value byte sequences in the format specified by this section, concatenated sequentially.

encoded_annotation format

نام قالب توضیحات
type_idx uleb128 type of the annotation. This must be a class (not array or primitive) type.
اندازه uleb128 number of name-value mappings in this annotation
عناصر annotation_element[size] elements of the annotation, represented directly in-line (not as offsets). Elements must be sorted in increasing order by string_id index.

annotation_element format

نام قالب توضیحات
name_idx uleb128 element name, represented as an index into the string_ids section. The string must conform to the syntax for MemberName , defined above.
ارزش encoded_value element value

String syntax

There are several kinds of item in a .dex file which ultimately refer to a string. The following BNF-style definitions indicate the acceptable syntax for these strings.

SimpleName

A SimpleName is the basis for the syntax of the names of other things. The .dex format allows a fair amount of latitude here (much more than most common source languages). In brief, a simple name consists of any low-ASCII alphabetic character or digit, a few specific low-ASCII symbols, and most non-ASCII code points that are not control, space, or special characters. Starting from version 040 the format additionally allows space characters (Unicode Zs category). Note that surrogate code points (in the range U+d800U+dfff ) are not considered valid name characters, per se, but Unicode supplemental characters are valid (which are represented by the final alternative of the rule for SimpleNameChar ), and they should be represented in a file as pairs of surrogate code points in the MUTF-8 encoding.

SimpleName
SimpleNameChar ( SimpleNameChar )*
SimpleNameChar
'A''Z'
| 'a''z'
| '0''9'
| ' ' since DEX version 040
| '$'
| '-'
| '_'
| U+00a0 since DEX version 040
| U+00a1U+1fff
| U+2000U+200a since DEX version 040
| U+2010U+2027
| U+202f since DEX version 040
| U+2030U+d7ff
| U+e000U+ffef
| U+10000U+10ffff

MemberName

used by field_id_item and method_id_item

A MemberName is the name of a member of a class, members being fields, methods, and inner classes.

MemberName
SimpleName
| '<' SimpleName '>'

FullClassName

A FullClassName is a fully qualified class name, including an optional package specifier followed by a required name.

FullClassName
OptionalPackagePrefix SimpleName
OptionalPackagePrefix
( SimpleName '/' )*

TypeDescriptor

Used by type_id_item

A TypeDescriptor is the representation of any type, including primitives, classes, arrays, and void . See below for the meaning of the various versions.

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

ShortyDescriptor

Used by proto_id_item

A ShortyDescriptor is the short form representation of a method prototype, including return and parameter types, except that there is no distinction between various reference (class or array) types. Instead, all reference types are represented by a single 'L' character.

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

TypeDescriptor semantics

This is the meaning of each of the variants of TypeDescriptor .

نحو معنی
V void only valid for return types
ز boolean
ب byte
اس short
سی char
من int
جی long
اف float
D double
L fully/qualified/Name ; the class fully.qualified.Name
[ descriptor array of descriptor , usable recursively for arrays-of-arrays, though it is invalid to have more than 255 dimensions.

Items and related structures

This section includes definitions for each of the top-level items that may appear in a .dex file.

header_item

Appears in the header section

Alignment: 4 bytes

نام قالب توضیحات
سحر و جادو ubyte[8] = DEX_FILE_MAGIC magic value. See discussion above under " DEX_FILE_MAGIC " for more details.
چک جمع unint adler32 checksum of the rest of the file (everything but magic and this field); used to detect file corruption
امضا ubyte[20] SHA-1 signature (hash) of the rest of the file (everything but magic , checksum , and this field); used to uniquely identify files
فایل_اندازه unint

size of the entire file (including the header), in bytes (v40 or earlier)

distance in bytes from the start of this header to the next header or to the end of the whole file (the container). (نسخه 41 یا بالاتر)

header_size unint

size of the header (this entire section), in bytes. This allows for at least a limited amount of backwards/forwards compatibility without invalidating the format.

must be 0x70 (112) bytes (v40 or earlier)

must be 0x78 (120) bytes (v41 or later)

endian_tag uint = ENDIAN_CONSTANT endianness tag. See discussion above under " ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT " for more details.
link_size unint size of the link section, or 0 if this file isn't statically linked
link_off unint offset from the start of the file to the link section, or 0 if link_size == 0 . The offset, if non-zero, should be to an offset into the link_data section. The format of the data pointed at is left unspecified by this document; this header field (and the previous) are left as hooks for use by runtime implementations.
map_off unint offset from the start of the file to the map item. The offset, which must be non-zero, should be to an offset into the data section, and the data should be in the format specified by " map_list " below.
string_ids_size unint count of strings in the string identifiers list
string_ids_off unint offset from the start of the file to the string identifiers list, or 0 if string_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the string_ids section.
type_ids_size unint count of elements in the type identifiers list, at most 65535
type_ids_off unint offset from the start of the file to the type identifiers list, or 0 if type_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the type_ids section.
proto_ids_size unint count of elements in the prototype identifiers list, at most 65535
proto_ids_off unint offset from the start of the file to the prototype identifiers list, or 0 if proto_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the proto_ids section.
field_ids_size unint count of elements in the field identifiers list
field_ids_off unint offset from the start of the file to the field identifiers list, or 0 if field_ids_size == 0 . The offset, if non-zero, should be to the start of the field_ids section.
method_ids_size unint count of elements in the method identifiers list
method_ids_off unint offset from the start of the file to the method identifiers list, or 0 if method_ids_size == 0 . The offset, if non-zero, should be to the start of the method_ids section.
class_defs_size unint count of elements in the class definitions list
class_defs_off unint offset from the start of the file to the class definitions list, or 0 if class_defs_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the class_defs section.
data_size unint

Size of data section in bytes. Must be an even multiple of sizeof(uint). (نسخه 40 یا قبل از آن)

Unused (v41 or later)

data_off unint

offset from the start of the file to the start of the data section (v40 or earlier)

Unused (v41 or later)

ظرف_اندازه unint

this field does not exist. It can be assumed to be equal to file_size . (نسخه 40 یا قبل از آن)

size of the entire file (including other dex headers and their data). (نسخه 41 یا بالاتر)

header_offset unint

this field does not exist. It can be assumed to be equal to 0 . (نسخه 40 یا قبل از آن)

offset from the start of the file to the start of this header. (نسخه 41 یا بالاتر)

map_list

Appears in the data section

Referenced from header_item

Alignment: 4 bytes

This is a list of the entire contents of a file, in order. It contains some redundancy with respect to the header_item but is intended to be an easy form to use to iterate over an entire file. A given type must appear at most once in a map, but there is no restriction on what order types may appear in, other than the restrictions implied by the rest of the format (eg, a header section must appear first, followed by a string_ids section, etc.). Additionally, the map entries must be ordered by initial offset and must not overlap.

نام قالب توضیحات
اندازه unint size of the list, in entries
فهرست map_item[size] elements of the list

map_item format

نام قالب توضیحات
نوع کوتاه type of the items; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
اندازه unint count of the number of items to be found at the indicated offset
جبران unint offset from the start of the file to the items in question

Type codes

نوع مورد ثابت ارزش Item Size In Bytes
header_item TYPE_HEADER_ITEM 0x0000 0x70
string_id_item TYPE_STRING_ID_ITEM 0x0001 0x04
type_id_item TYPE_TYPE_ID_ITEM 0x0002 0x04
proto_id_item TYPE_PROTO_ID_ITEM 0x0003 0x0c
field_id_item TYPE_FIELD_ID_ITEM 0x0004 0x08
method_id_item TYPE_METHOD_ID_ITEM 0x0005 0x08
class_def_item TYPE_CLASS_DEF_ITEM 0x0006 0x20
call_site_id_item TYPE_CALL_SITE_ID_ITEM 0x0007 0x04
method_handle_item TYPE_METHOD_HANDLE_ITEM 0x0008 0x08
map_list TYPE_MAP_LIST 0x1000 4 + (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 implicit; must parse
code_item TYPE_CODE_ITEM 0x2001 implicit; must parse
string_data_item TYPE_STRING_DATA_ITEM 0x2002 implicit; must parse
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 implicit; must parse
annotation_item TYPE_ANNOTATION_ITEM 0x2004 implicit; must parse
encoded_array_item TYPE_ENCODED_ARRAY_ITEM 0x2005 implicit; must parse
annotations_directory_item TYPE_ANNOTATIONS_DIRECTORY_ITEM 0x2006 implicit; must parse
hiddenapi_class_data_item TYPE_HIDDENAPI_CLASS_DATA_ITEM 0xF000 implicit; must parse

string_id_item

Appears in the string_ids section

Alignment: 4 bytes

نام قالب توضیحات
string_data_off unint offset from the start of the file to the string data for this item. The offset should be to a location in the data section, and the data should be in the format specified by " string_data_item " below. There is no alignment requirement for the offset.

string_data_item

Appears in the data section

Alignment: none (byte-aligned)

نام قالب توضیحات
utf16_size uleb128 size of this string, in UTF-16 code units (which is the "string length" in many systems). That is, this is the decoded length of the string. (The encoded length is implied by the position of the 0 byte.)
داده ها ubyte[] a series of MUTF-8 code units (aka octets, aka bytes) followed by a byte of value 0 . See "MUTF-8 (Modified UTF-8) Encoding" above for details and discussion about the data format.

Note: It is acceptable to have a string which includes (the encoded form of) UTF-16 surrogate code units (that is, U+d800U+dfff ) either in isolation or out-of-order with respect to the usual encoding of Unicode into UTF-16. It is up to higher-level uses of strings to reject such invalid encodings, if appropriate.

type_id_item

Appears in the type_ids section

Alignment: 4 bytes

نام قالب توضیحات
descriptor_idx unint index into the string_ids list for the descriptor string of this type. The string must conform to the syntax for TypeDescriptor , defined above.

proto_id_item

Appears in the proto_ids section

Alignment: 4 bytes

نام قالب توضیحات
shorty_idx unint index into the string_ids list for the short-form descriptor string of this prototype. The string must conform to the syntax for ShortyDescriptor , defined above, and must correspond to the return type and parameters of this item.
return_type_idx unint index into the type_ids list for the return type of this prototype
parameters_off unint offset from the start of the file to the list of parameter types for this prototype, or 0 if this prototype has no parameters. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by "type_list" below. Additionally, there should be no reference to the type void in the list.

field_id_item

Appears in the field_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this field. This must be a class type, and not an array or primitive type.
type_idx کوتاه index into the type_ids list for the type of this field
name_idx unint index into the string_ids list for the name of this field. The string must conform to the syntax for MemberName , defined above.

method_id_item

Appears in the method_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this method. This must be a class or array type, and not a primitive type.
proto_idx کوتاه index into the proto_ids list for the prototype of this method
name_idx unint index into the string_ids list for the name of this method. The string must conform to the syntax for MemberName , defined above.

class_def_item

Appears in the class_defs section

Alignment: 4 bytes

نام قالب توضیحات
class_idx unint index into the type_ids list for this class. This must be a class type, and not an array or primitive type.
access_flags unint access flags for the class ( public , final , etc.). See " access_flags Definitions" for details.
superclass_idx unint index into the type_ids list for the superclass, or the constant value NO_INDEX if this class has no superclass (ie, it is a root class such as Object ). If present, this must be a class type, and not an array or primitive type.
interfaces_off unint offset from the start of the file to the list of interfaces, or 0 if there are none. This offset should be in the data section, and the data there should be in the format specified by " type_list " below. Each of the elements of the list must be a class type (not an array or primitive type), and there must not be any duplicates.
source_file_idx unint index into the string_ids list for the name of the file containing the original source for (at least most of) this class, or the special value NO_INDEX to represent a lack of this information. The debug_info_item of any given method may override this source file, but the expectation is that most classes will only come from one source file.
annotations_off unint offset from the start of the file to the annotations structure for this class, or 0 if there are no annotations on this class. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by " annotations_directory_item " below, with all items referring to this class as the definer.
class_data_off unint offset from the start of the file to the associated class data for this item, or 0 if there is no class data for this class. (This may be the case, for example, if this class is a marker interface.) The offset, if non-zero, should be in the data section, and the data there should be in the format specified by " class_data_item " below, with all items referring to this class as the definer.
static_values_off unint offset from the start of the file to the list of initial values for static fields, or 0 if there are none (and all static fields are to be initialized with 0 or null ). This offset should be in the data section, and the data there should be in the format specified by " encoded_array_item " below. The size of the array must be no larger than the number of static fields declared by this class, and the elements correspond to the static fields in the same order as declared in the corresponding field_list . The type of each array element must match the declared type of its corresponding field. If there are fewer elements in the array than there are static fields, then the leftover fields are initialized with a type-appropriate 0 or null .

call_site_id_item

Appears in the call_site_ids section

Alignment: 4 bytes

نام قالب توضیحات
call_site_off unint offset from the start of the file to call site definition. The offset should be in the data section, and the data there should be in the format specified by "call_site_item" below.

call_site_item

Appears in the data section

Alignment: none (byte aligned)

The call_site_item is an encoded_array_item whose elements correspond to the arguments provided to a bootstrap linker method. The first three arguments are:

  1. A method handle representing the bootstrap linker method (VALUE_METHOD_HANDLE).
  2. A method name that the bootstrap linker should resolve (VALUE_STRING).
  3. 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:

  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 کوتاه type of the method handle; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
field_or_method_id کوتاه Field or method id depending on whether the method handle type is an accessor or a method invoker
استفاده نشده کوتاه (استفاده نشده)

Method handle type codes

ثابت ارزش توضیحات
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 and method_id instances 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

نام قالب توضیحات
اندازه unint size of the list, in entries
فهرست type_item[size] elements of the list

type_item format

نام قالب توضیحات
type_idx کوتاه index into the type_ids list

code_item

Referenced from encoded_method

Appears in the data section

Alignment: 4 bytes

نام قالب توضیحات
registers_size کوتاه the number of registers used by this code
ins_size کوتاه the number of words of incoming arguments to the method that this code is for
outs_size کوتاه the number of words of outgoing argument space required by this code for method invocation
tries_size کوتاه the number of try_item s for this instance. If non-zero, then these appear as the tries array just after the insns in this instance.
debug_info_off unint 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 unint 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 instances and not on the larger internal structures.
بالشتک 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.
تلاش می کند 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.
کنترل کننده ها 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 unint start address of the block of code covered by this entry. The address is a count of 16-bit code units to the start of the first covered instruction.
insn_count کوتاه number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 .
handler_off کوتاه offset in bytes from the start of the associated encoded_catch_hander_list to the encoded_catch_handler for this entry. This must be an offset to the start of an encoded_catch_handler .

encoded_catch_handler_list format

نام قالب توضیحات
اندازه uleb128 size of this list, in entries
فهرست encoded_catch_handler[handlers_size] actual list of handler lists, represented directly (not as offsets), and concatenated sequentially

encoded_catch_handler format

نام قالب توضیحات
اندازه sleb128 number of catch types in this list. If non-positive, then this is the negative of the number of catch types, and the catches are followed by a catch-all handler. For example: A size of 0 means that there is a catch-all but no explicitly typed catches. A size of 2 means that there are two explicitly typed catches and no catch-all. And a size of -1 means that there is one typed catch along with a catch-all.
کنترل کننده ها 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
آدرس 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:

نام ارزش قالب استدلال ها توضیحات
DBG_END_SEQUENCE 0x00 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 unint 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 unint count of fields annotated by this item
annotated_methods_size unint count of methods annotated by this item
annotated_parameters_size unint 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 and method_id instances must refer to the same defining class.

field_annotation format

نام قالب توضیحات
field_idx unint index into the field_ids list for the identity of the field being annotated
annotations_off unint 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 unint index into the method_ids list for the identity of the method being annotated
annotations_off unint 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 unint index into the method_ids list for the identity of the method whose parameters are being annotated
annotations_off unint 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

نام قالب توضیحات
اندازه unint size of the list, in entries
فهرست annotation_set_ref_item[size] elements of the list

annotation_set_ref_item format

نام قالب توضیحات
annotations_off unint 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

نام قالب توضیحات
اندازه uint size of the set, in entries
ورودی ها annotation_off_item[size] عناصر مجموعه 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)

نام قالب توضیحات
دید یوبایت intended visibility of this annotation (see below)
حاشیه نویسی 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 :

نام ارزش توضیحات
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)

نام قالب توضیحات
ارزش 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 .

نام قالب توضیحات
اندازه uint total size of the section
جبران می کند 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 .
پرچم ها 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:

نام ارزش توضیحات
لیست سفید 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 .
لیست سیاه 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.

نام قالب توضیحات
ارزش حاشیه نویسی 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.

نام قالب توضیحات
ارزش کلاس 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.

نام قالب توضیحات
ارزش روش 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.

نام قالب توضیحات
نام رشته the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null .
accessFlags بین المللی the originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine)

dalvik.annotation.MemberClasses

Appears on classes

A MemberClasses annotation is attached to each class which declares member classes. (A member class is a direct inner class that has a name.)

نام قالب توضیحات
ارزش 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.

نام قالب توضیحات
نام ها رشته[] The names of formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. A value in the array must be null if the formal parameter with that index has no name.
If parameter name strings are empty or contain '.', ';', '[' or '/' then a java.lang.reflect.MalformedParametersException will be thrown at runtime.
accessFlags بین المللی[] The access flags of the formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters.
The value is a bit mask with the following values:
  • 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.

نام قالب توضیحات
ارزش رشته[] 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.

نام قالب توضیحات
ارزش Class[] the array of exception types thrown
،

This document describes the layout and contents of .dex files, which are used to hold a set of class definitions and their associated adjunct data.

Guide to types

نام توضیحات
بایت 8-bit signed int
یوبایت 8-bit unsigned int
کوتاه 16-bit signed int, little-endian
کوتاه 16-bit unsigned int, little-endian
بین المللی 32-bit signed int, little-endian
uint 32-bit unsigned int, little-endian
طولانی 64-bit signed int, little-endian
طولانی 64-bit unsigned int, little-endian
sleb128 signed LEB128, variable-length (see below)
uleb128 unsigned LEB128, variable-length (see below)
uleb128p1 unsigned LEB128 plus 1 , variable-length (see below)

LEB128

LEB128 (" L ittle- E ndian B ase 128 ") is a variable-length encoding for arbitrary signed or unsigned integer quantities. The format was borrowed from the DWARF3 specification. In a .dex file, LEB128 is only ever used to encode 32-bit quantities.

Each LEB128 encoded value consists of one to five bytes, which together represent a single 32-bit value. Each byte has its most significant bit set except for the final byte in the sequence, which has its most significant bit clear. The remaining seven bits of each byte are payload, with the least significant seven bits of the quantity in the first byte, the next seven in the second byte and so on. In the case of a signed LEB128 ( sleb128 ), the most significant payload bit of the final byte in the sequence is sign-extended to produce the final value. In the unsigned case ( uleb128 ), any bits not explicitly represented are interpreted as 0 .

Bitwise diagram of a two-byte LEB128 value
بایت اول Second byte
1 bit 6 bit 5 bit 4 بیت 3 بیت 2 بیت 1 بیت 0 0 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7

The variant uleb128p1 is used to represent a signed value, where the representation is of the value plus one encoded as a uleb128 . This makes the encoding of -1 (alternatively thought of as the unsigned value 0xffffffff ) — but no other negative number — a single byte, and is useful in exactly those cases where the represented number must either be non-negative or -1 (or 0xffffffff ), and where no other negative values are allowed (or where large unsigned values are unlikely to be needed).

Here are some examples of the formats:

Encoded Sequence As sleb128 As uleb128 As uleb128p1
00 0 0 -1
01 1 1 0
7f -1 127 126
80 7f -128 16256 16255

طرح بندی فایل

نام قالب توضیحات
هدر header_item هدر
string_ids string_id_item[] string identifiers list. These are identifiers for all the strings used by this file, either for internal naming (eg, type descriptors) or as constant objects referred to by code. This list must be sorted by string contents, using UTF-16 code point values (not in a locale-sensitive manner), and it must not contain any duplicate entries.
type_ids type_id_item[] type identifiers list. These are identifiers for all types (classes, arrays, or primitive types) referred to by this file, whether defined in the file or not. This list must be sorted by string_id index, and it must not contain any duplicate entries.
proto_ids proto_id_item[] method prototype identifiers list. These are identifiers for all prototypes referred to by this file. This list must be sorted in return-type (by type_id index) major order, and then by argument list (lexicographic ordering, individual arguments ordered by type_id index). The list must not contain any duplicate entries.
field_ids field_id_item[] field identifiers list. These are identifiers for all fields referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (by type_id index) is the major order, field name (by string_id index) is the intermediate order, and type (by type_id index) is the minor order. The list must not contain any duplicate entries.
method_ids method_id_item[] method identifiers list. These are identifiers for all methods referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (by type_id index) is the major order, method name (by string_id index) is the intermediate order, and method prototype (by proto_id index) is the minor order. The list must not contain any duplicate entries.
class_defs class_def_item[] class definitions list. The classes must be ordered such that a given class's superclass and implemented interfaces appear in the list earlier than the referring class. Furthermore, it is invalid for a definition for the same-named class to appear more than once in the list.
call_site_ids call_site_id_item[] call site identifiers list. These are identifiers for all call sites referred to by this file, whether defined in the file or not. This list must be sorted in ascending order of call_site_off .
method_handles method_handle_item[] method handles list. A list of all method handles referred to by this file, whether defined in the file or not. This list is not sorted and may contain duplicates which will logically correspond to different method handle instances.
داده ها ubyte[] data area, containing all the support data for the tables listed above. Different items have different alignment requirements, and padding bytes are inserted before each item if necessary to achieve proper alignment.
link_data ubyte[] data used in statically linked files. The format of the data in this section is left unspecified by this document. This section is empty in unlinked files, and runtime implementations may use it as they see fit.

قالب کانتینر

Version 41 introduces a new container format for DEX data with the goal to save space. This container format allows several logical DEX files to be combined into a single physical file. The new format is mostly just naive concatenation of files in the previous format, with some differences:

  • The file_size is the size of the logical file, not the physical file. It can be used to iterate over all the logical files in the container.
  • Logical dex files may reference any later data in the container (but not earlier). This allows dex files to share data, such as strings, between them.
  • All offsets are relative to the physical file. No offset is relative to the header. This is ensures that sections with offsets can be shared between logical files.
  • The header adds two new fields to describe the bounds of the container. This is an additional consistency check and makes porting code to the new format easier.
  • The data_size and data_off are now unused. Data can be spread across multiple logical files and does not have to be contiguous.

Bitfield, string, and constant definitions

DEX_FILE_MAGIC

Embedded in header_item

The constant array/string DEX_FILE_MAGIC is the list of bytes that must appear at the beginning of a .dex file in order for it to be recognized as such. The value intentionally contains a newline ( "\n" or 0x0a ) and a null byte ( "\0" or 0x00 ) in order to help in the detection of certain forms of corruption. The value also encodes a format version number as three decimal digits, which is expected to increase monotonically over time as the format evolves.

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

Note: Support for version 040 of the format was added in the Android 10.0 release, which extended the set of allowed characters in SimpleNames .

Note: Support for version 039 of the format was added in the Android 9.0 release, which introduced two new bytecodes, const-method-handle and const-method-type . (These are each described in the Summary of bytecode set table.) In Android 10, version 039 extends the DEX file format to include hidden API information that's only applicable to DEX files on the boot class path.

Note: Support for version 038 of the format was added in the Android 8.0 release. Version 038 added new bytecodes ( invoke-polymorphic and invoke-custom ) and data for method handles.

Note: Support for version 037 of the format was added in the Android 7.0 release. Prior to version 037 most versions of Android have used version 035 of the format. The only difference between versions 035 and 037 is the addition of default methods and the adjustment of the invoke .

Note: At least a couple earlier versions of the format have been used in widely available public software releases. For example, version 009 was used for the M3 releases of the Android platform (November–December 2007), and version 013 was used for the M5 releases of the Android platform (February–March 2008). In several respects, these earlier versions of the format differ significantly from the version described in this document.

ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT

Embedded in header_item

The constant ENDIAN_CONSTANT is used to indicate the endianness of the file in which it is found. Although the standard .dex format is little-endian, implementations may choose to perform byte-swapping. Should an implementation come across a header whose endian_tag is REVERSE_ENDIAN_CONSTANT instead of ENDIAN_CONSTANT , it would know that the file has been byte-swapped from the expected form.

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

NO_INDEX

Embedded in class_def_item and debug_info_item

The constant NO_INDEX is used to indicate that an index value is absent.

Note: This value isn't defined to be 0 , because that is in fact typically a valid index.

The chosen value for NO_INDEX is representable as a single byte in the uleb128p1 encoding.

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

access_flags definitions

Embedded in class_def_item, encoded_field, encoded_method, and InnerClass

Bitfields of these flags are used to indicate the accessibility and overall properties of classes and class members.

نام ارزش For Classes (and InnerClass annotations) For Fields For Methods
ACC_PUBLIC 0x1 public : visible everywhere public : visible everywhere public : visible everywhere
ACC_PRIVATE 0x2 * private : only visible to defining class private : only visible to defining class private : only visible to defining class
ACC_PROTECTED 0x4 * protected : visible to package and subclasses protected : visible to package and subclasses protected : visible to package and subclasses
ACC_STATIC 0x8 * static : is not constructed with an outer this reference static : global to defining class static : does not take a this argument
ACC_FINAL 0x10 final : not subclassable final : immutable after construction final : not overridable
ACC_SYNCHRONIZED 0x20 synchronized : associated lock automatically acquired around call to this method.

Note: This is only valid to set when ACC_NATIVE is also set.

ACC_VOLATILE 0x40 volatile : special access rules to help with thread safety
ACC_BRIDGE 0x40 bridge method, added automatically by compiler as a type-safe bridge
ACC_TRANSIENT 0x80 transient : not to be saved by default serialization
ACC_VARARGS 0x80 last argument should be treated as a "rest" argument by compiler
ACC_NATIVE 0x100 native : implemented in native code
ACC_INTERFACE 0x200 interface : multiply-implementable abstract class
ACC_ABSTRACT 0x400 abstract : not directly instantiable abstract : unimplemented by this class
ACC_STRICT 0x800 strictfp : strict rules for floating-point arithmetic
ACC_SYNTHETIC 0x1000 not directly defined in source code not directly defined in source code not directly defined in source code
ACC_ANNOTATION 0x2000 declared as an annotation class
ACC_ENUM 0x4000 declared as an enumerated type declared as an enumerated value
(استفاده نشده) 0x8000
ACC_CONSTRUCTOR 0x10000 constructor method (class or instance initializer)
ACC_DECLARED_
همگام
0x20000 declared synchronized .

Note: This has no effect on execution (other than in reflection of this flag, per se).

* Only allowed on for InnerClass annotations, and must not ever be on in a class_def_item .

Modified UTF-8 encoding

As a concession to easier legacy support, the .dex format encodes its string data in a de facto standard modified UTF-8 form, hereafter referred to as MUTF-8. This form is identical to standard UTF-8, except:

  • Only the one-, two-, and three-byte encodings are used.
  • Code points in the range U+10000U+10ffff are encoded as a surrogate pair, each of which is represented as a three-byte encoded value.
  • The code point U+0000 is encoded in two-byte form.
  • A plain null byte (value 0 ) indicates the end of a string, as is the standard C language interpretation.

The first two items above can be summarized as: MUTF-8 is an encoding format for UTF-16, instead of being a more direct encoding format for Unicode characters.

The final two items above make it simultaneously possible to include the code point U+0000 in a string and still manipulate it as a C-style null-terminated string.

However, the special encoding of U+0000 means that, unlike normal UTF-8, the result of calling the standard C function strcmp() on a pair of MUTF-8 strings does not always indicate the properly signed result of comparison of unequal strings. When ordering (not just equality) is a concern, the most straightforward way to compare MUTF-8 strings is to decode them character by character, and compare the decoded values. (However, more clever implementations are also possible.)

Please refer to The Unicode Standard for further information about character encoding. MUTF-8 is actually closer to the (relatively less well-known) encoding CESU-8 than to UTF-8 per se.

encoded_value encoding

Embedded in annotation_element and encoded_array_item

An encoded_value is an encoded piece of (nearly) arbitrary hierarchically structured data. The encoding is meant to be both compact and straightforward to parse.

نام قالب توضیحات
(value_arg << 5) | value_type یوبایت byte indicating the type of the immediately subsequent value along with an optional clarifying argument in the high-order three bits. See below for the various value definitions. In most cases, value_arg encodes the length of the immediately-subsequent value in bytes, as (size - 1) , eg, 0 means that the value requires one byte, and 7 means it requires eight bytes; however, there are exceptions as noted below.
ارزش ubyte[] bytes representing the value, variable in length and interpreted differently for different value_type bytes, though always little-endian. See the various value definitions below for details.

Value formats

نام را تایپ کنید value_type value_arg Format value Format توضیحات
VALUE_BYTE 0x00 (none; must be 0 ) ubyte[1] signed one-byte integer value
VALUE_SHORT 0x02 size - 1 (0…1) ubyte[size] signed two-byte integer value, sign-extended
VALUE_CHAR 0x03 size - 1 (0…1) ubyte[size] unsigned two-byte integer value, zero-extended
VALUE_INT 0x04 size - 1 (0…3) ubyte[size] signed four-byte integer value, sign-extended
VALUE_LONG 0x06 size - 1 (0…7) ubyte[size] signed eight-byte integer value, sign-extended
VALUE_FLOAT 0x10 size - 1 (0…3) ubyte[size] four-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 32-bit floating point value
VALUE_DOUBLE 0x11 size - 1 (0…7) ubyte[size] eight-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 64-bit floating point value
VALUE_METHOD_TYPE 0x15 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the proto_ids section and representing a method type value
VALUE_METHOD_HANDLE 0x16 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_handles section and representing a method handle value
VALUE_STRING 0x17 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the string_ids section and representing a string value
VALUE_TYPE 0x18 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the type_ids section and representing a reflective type/class value
VALUE_FIELD 0x19 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing a reflective field value
VALUE_METHOD 0x1a size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_ids section and representing a reflective method value
VALUE_ENUM 0x1b size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing the value of an enumerated type constant
VALUE_ARRAY 0x1c (none; must be 0 ) encoded_array an array of values, in the format specified by " encoded_array format" below. The size of the value is implicit in the encoding.
VALUE_ANNOTATION 0x1d (none; must be 0 ) encoded_annotation a sub-annotation, in the format specified by " encoded_annotation format" below. The size of the value is implicit in the encoding.
VALUE_NULL 0x1e (none; must be 0 ) (هیچ کدام) null reference value
VALUE_BOOLEAN 0x1f boolean (0…1) (هیچ کدام) one-bit value; 0 for false and 1 for true . The bit is represented in the value_arg .

encoded_array format

نام قالب توضیحات
اندازه uleb128 تعداد عناصر در آرایه
ارزش ها encoded_value[size] a series of size encoded_value byte sequences in the format specified by this section, concatenated sequentially.

encoded_annotation format

نام قالب توضیحات
type_idx uleb128 type of the annotation. This must be a class (not array or primitive) type.
اندازه uleb128 number of name-value mappings in this annotation
عناصر annotation_element[size] elements of the annotation, represented directly in-line (not as offsets). Elements must be sorted in increasing order by string_id index.

annotation_element format

نام قالب توضیحات
name_idx uleb128 element name, represented as an index into the string_ids section. The string must conform to the syntax for MemberName , defined above.
ارزش encoded_value element value

String syntax

There are several kinds of item in a .dex file which ultimately refer to a string. The following BNF-style definitions indicate the acceptable syntax for these strings.

SimpleName

A SimpleName is the basis for the syntax of the names of other things. The .dex format allows a fair amount of latitude here (much more than most common source languages). In brief, a simple name consists of any low-ASCII alphabetic character or digit, a few specific low-ASCII symbols, and most non-ASCII code points that are not control, space, or special characters. Starting from version 040 the format additionally allows space characters (Unicode Zs category). Note that surrogate code points (in the range U+d800U+dfff ) are not considered valid name characters, per se, but Unicode supplemental characters are valid (which are represented by the final alternative of the rule for SimpleNameChar ), and they should be represented in a file as pairs of surrogate code points in the MUTF-8 encoding.

SimpleName
SimpleNameChar ( SimpleNameChar )*
SimpleNameChar
'A''Z'
| 'a''z'
| '0''9'
| ' ' since DEX version 040
| '$'
| '-'
| '_'
| U+00a0 since DEX version 040
| U+00a1U+1fff
| U+2000U+200a since DEX version 040
| U+2010U+2027
| U+202f since DEX version 040
| U+2030U+d7ff
| U+e000U+ffef
| U+10000U+10ffff

MemberName

used by field_id_item and method_id_item

A MemberName is the name of a member of a class, members being fields, methods, and inner classes.

MemberName
SimpleName
| '<' SimpleName '>'

FullClassName

A FullClassName is a fully qualified class name, including an optional package specifier followed by a required name.

FullClassName
OptionalPackagePrefix SimpleName
OptionalPackagePrefix
( SimpleName '/' )*

TypeDescriptor

Used by type_id_item

A TypeDescriptor is the representation of any type, including primitives, classes, arrays, and void . See below for the meaning of the various versions.

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

ShortyDescriptor

Used by proto_id_item

A ShortyDescriptor is the short form representation of a method prototype, including return and parameter types, except that there is no distinction between various reference (class or array) types. Instead, all reference types are represented by a single 'L' character.

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

TypeDescriptor semantics

This is the meaning of each of the variants of TypeDescriptor .

نحو معنی
V void only valid for return types
ز boolean
ب byte
اس short
سی char
من int
جی long
اف float
D double
L fully/qualified/Name ; the class fully.qualified.Name
[ descriptor array of descriptor , usable recursively for arrays-of-arrays, though it is invalid to have more than 255 dimensions.

Items and related structures

This section includes definitions for each of the top-level items that may appear in a .dex file.

header_item

Appears in the header section

Alignment: 4 bytes

نام قالب توضیحات
سحر و جادو ubyte[8] = DEX_FILE_MAGIC magic value. See discussion above under " DEX_FILE_MAGIC " for more details.
چک جمع uint adler32 checksum of the rest of the file (everything but magic and this field); used to detect file corruption
امضا ubyte[20] SHA-1 signature (hash) of the rest of the file (everything but magic , checksum , and this field); used to uniquely identify files
فایل_اندازه uint

size of the entire file (including the header), in bytes (v40 or earlier)

distance in bytes from the start of this header to the next header or to the end of the whole file (the container). (نسخه 41 یا بالاتر)

header_size uint

size of the header (this entire section), in bytes. This allows for at least a limited amount of backwards/forwards compatibility without invalidating the format.

must be 0x70 (112) bytes (v40 or earlier)

must be 0x78 (120) bytes (v41 or later)

endian_tag uint = ENDIAN_CONSTANT endianness tag. See discussion above under " ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT " for more details.
link_size uint size of the link section, or 0 if this file isn't statically linked
link_off uint offset from the start of the file to the link section, or 0 if link_size == 0 . The offset, if non-zero, should be to an offset into the link_data section. The format of the data pointed at is left unspecified by this document; this header field (and the previous) are left as hooks for use by runtime implementations.
map_off uint offset from the start of the file to the map item. The offset, which must be non-zero, should be to an offset into the data section, and the data should be in the format specified by " map_list " below.
string_ids_size uint count of strings in the string identifiers list
string_ids_off uint offset from the start of the file to the string identifiers list, or 0 if string_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the string_ids section.
type_ids_size uint count of elements in the type identifiers list, at most 65535
type_ids_off uint offset from the start of the file to the type identifiers list, or 0 if type_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the type_ids section.
proto_ids_size uint count of elements in the prototype identifiers list, at most 65535
proto_ids_off uint offset from the start of the file to the prototype identifiers list, or 0 if proto_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the proto_ids section.
field_ids_size uint count of elements in the field identifiers list
field_ids_off uint offset from the start of the file to the field identifiers list, or 0 if field_ids_size == 0 . The offset, if non-zero, should be to the start of the field_ids section.
method_ids_size uint count of elements in the method identifiers list
method_ids_off uint offset from the start of the file to the method identifiers list, or 0 if method_ids_size == 0 . The offset, if non-zero, should be to the start of the method_ids section.
class_defs_size uint count of elements in the class definitions list
class_defs_off uint offset from the start of the file to the class definitions list, or 0 if class_defs_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the class_defs section.
data_size uint

Size of data section in bytes. Must be an even multiple of sizeof(uint). (نسخه 40 یا قبل از آن)

Unused (v41 or later)

data_off uint

offset from the start of the file to the start of the data section (v40 or earlier)

Unused (v41 or later)

ظرف_اندازه uint

this field does not exist. It can be assumed to be equal to file_size . (نسخه 40 یا قبل از آن)

size of the entire file (including other dex headers and their data). (نسخه 41 یا بالاتر)

header_offset uint

this field does not exist. It can be assumed to be equal to 0 . (نسخه 40 یا قبل از آن)

offset from the start of the file to the start of this header. (نسخه 41 یا بالاتر)

map_list

Appears in the data section

Referenced from header_item

Alignment: 4 bytes

This is a list of the entire contents of a file, in order. It contains some redundancy with respect to the header_item but is intended to be an easy form to use to iterate over an entire file. A given type must appear at most once in a map, but there is no restriction on what order types may appear in, other than the restrictions implied by the rest of the format (eg, a header section must appear first, followed by a string_ids section, etc.). Additionally, the map entries must be ordered by initial offset and must not overlap.

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست map_item[size] elements of the list

map_item format

نام قالب توضیحات
نوع کوتاه type of the items; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
اندازه uint count of the number of items to be found at the indicated offset
جبران uint offset from the start of the file to the items in question

Type codes

Item Type ثابت ارزش Item Size In Bytes
header_item TYPE_HEADER_ITEM 0x0000 0x70
string_id_item TYPE_STRING_ID_ITEM 0x0001 0x04
type_id_item TYPE_TYPE_ID_ITEM 0x0002 0x04
proto_id_item TYPE_PROTO_ID_ITEM 0x0003 0x0c
field_id_item TYPE_FIELD_ID_ITEM 0x0004 0x08
method_id_item TYPE_METHOD_ID_ITEM 0x0005 0x08
class_def_item TYPE_CLASS_DEF_ITEM 0x0006 0x20
call_site_id_item TYPE_CALL_SITE_ID_ITEM 0x0007 0x04
method_handle_item TYPE_METHOD_HANDLE_ITEM 0x0008 0x08
map_list TYPE_MAP_LIST 0x1000 4 + (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 implicit; must parse
code_item TYPE_CODE_ITEM 0x2001 implicit; must parse
string_data_item TYPE_STRING_DATA_ITEM 0x2002 implicit; must parse
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 implicit; must parse
annotation_item TYPE_ANNOTATION_ITEM 0x2004 implicit; must parse
encoded_array_item TYPE_ENCODED_ARRAY_ITEM 0x2005 implicit; must parse
annotations_directory_item TYPE_ANNOTATIONS_DIRECTORY_ITEM 0x2006 implicit; must parse
hiddenapi_class_data_item TYPE_HIDDENAPI_CLASS_DATA_ITEM 0xF000 implicit; must parse

string_id_item

Appears in the string_ids section

Alignment: 4 bytes

نام قالب توضیحات
string_data_off uint offset from the start of the file to the string data for this item. The offset should be to a location in the data section, and the data should be in the format specified by " string_data_item " below. There is no alignment requirement for the offset.

string_data_item

Appears in the data section

Alignment: none (byte-aligned)

نام قالب توضیحات
utf16_size uleb128 size of this string, in UTF-16 code units (which is the "string length" in many systems). That is, this is the decoded length of the string. (The encoded length is implied by the position of the 0 byte.)
داده ها ubyte[] a series of MUTF-8 code units (aka octets, aka bytes) followed by a byte of value 0 . See "MUTF-8 (Modified UTF-8) Encoding" above for details and discussion about the data format.

Note: It is acceptable to have a string which includes (the encoded form of) UTF-16 surrogate code units (that is, U+d800U+dfff ) either in isolation or out-of-order with respect to the usual encoding of Unicode into UTF-16. It is up to higher-level uses of strings to reject such invalid encodings, if appropriate.

type_id_item

Appears in the type_ids section

Alignment: 4 bytes

نام قالب توضیحات
descriptor_idx uint index into the string_ids list for the descriptor string of this type. The string must conform to the syntax for TypeDescriptor , defined above.

proto_id_item

Appears in the proto_ids section

Alignment: 4 bytes

نام قالب توضیحات
shorty_idx uint index into the string_ids list for the short-form descriptor string of this prototype. The string must conform to the syntax for ShortyDescriptor , defined above, and must correspond to the return type and parameters of this item.
return_type_idx uint index into the type_ids list for the return type of this prototype
parameters_off uint offset from the start of the file to the list of parameter types for this prototype, or 0 if this prototype has no parameters. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by "type_list" below. Additionally, there should be no reference to the type void in the list.

field_id_item

Appears in the field_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this field. This must be a class type, and not an array or primitive type.
type_idx کوتاه index into the type_ids list for the type of this field
name_idx uint index into the string_ids list for the name of this field. The string must conform to the syntax for MemberName , defined above.

method_id_item

Appears in the method_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this method. This must be a class or array type, and not a primitive type.
proto_idx کوتاه index into the proto_ids list for the prototype of this method
name_idx uint index into the string_ids list for the name of this method. The string must conform to the syntax for MemberName , defined above.

class_def_item

Appears in the class_defs section

Alignment: 4 bytes

نام قالب توضیحات
class_idx uint index into the type_ids list for this class. This must be a class type, and not an array or primitive type.
access_flags uint access flags for the class ( public , final , etc.). See " access_flags Definitions" for details.
superclass_idx uint index into the type_ids list for the superclass, or the constant value NO_INDEX if this class has no superclass (ie, it is a root class such as Object ). If present, this must be a class type, and not an array or primitive type.
interfaces_off uint offset from the start of the file to the list of interfaces, or 0 if there are none. This offset should be in the data section, and the data there should be in the format specified by " type_list " below. Each of the elements of the list must be a class type (not an array or primitive type), and there must not be any duplicates.
source_file_idx uint index into the string_ids list for the name of the file containing the original source for (at least most of) this class, or the special value NO_INDEX to represent a lack of this information. The debug_info_item of any given method may override this source file, but the expectation is that most classes will only come from one source file.
annotations_off uint offset from the start of the file to the annotations structure for this class, or 0 if there are no annotations on this class. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by " annotations_directory_item " below, with all items referring to this class as the definer.
class_data_off uint offset from the start of the file to the associated class data for this item, or 0 if there is no class data for this class. (This may be the case, for example, if this class is a marker interface.) The offset, if non-zero, should be in the data section, and the data there should be in the format specified by " class_data_item " below, with all items referring to this class as the definer.
static_values_off uint offset from the start of the file to the list of initial values for static fields, or 0 if there are none (and all static fields are to be initialized with 0 or null ). This offset should be in the data section, and the data there should be in the format specified by " encoded_array_item " below. The size of the array must be no larger than the number of static fields declared by this class, and the elements correspond to the static fields in the same order as declared in the corresponding field_list . The type of each array element must match the declared type of its corresponding field. If there are fewer elements in the array than there are static fields, then the leftover fields are initialized with a type-appropriate 0 or null .

call_site_id_item

Appears in the call_site_ids section

Alignment: 4 bytes

نام قالب توضیحات
call_site_off uint offset from the start of the file to call site definition. The offset should be in the data section, and the data there should be in the format specified by "call_site_item" below.

call_site_item

Appears in the data section

Alignment: none (byte aligned)

The call_site_item is an encoded_array_item whose elements correspond to the arguments provided to a bootstrap linker method. The first three arguments are:

  1. A method handle representing the bootstrap linker method (VALUE_METHOD_HANDLE).
  2. A method name that the bootstrap linker should resolve (VALUE_STRING).
  3. 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:

  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 کوتاه type of the method handle; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
field_or_method_id کوتاه Field or method id depending on whether the method handle type is an accessor or a method invoker
استفاده نشده کوتاه (استفاده نشده)

Method handle type codes

ثابت ارزش توضیحات
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 and method_id instances 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

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست type_item[size] elements of the list

type_item format

نام قالب توضیحات
type_idx کوتاه index into the type_ids list

code_item

Referenced from encoded_method

Appears in the data section

Alignment: 4 bytes

نام قالب توضیحات
registers_size کوتاه the number of registers used by this code
ins_size کوتاه the number of words of incoming arguments to the method that this code is for
outs_size کوتاه the number of words of outgoing argument space required by this code for method invocation
tries_size کوتاه the number of try_item s for this instance. If non-zero, then these appear as the tries array just after the insns in this instance.
debug_info_off 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 instances and not on the larger internal structures.
بالشتک 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.
تلاش می کند 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.
کنترل کننده ها 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 کوتاه number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 .
handler_off کوتاه offset in bytes from the start of the associated encoded_catch_hander_list to the encoded_catch_handler for this entry. This must be an offset to the start of an encoded_catch_handler .

encoded_catch_handler_list format

نام قالب توضیحات
اندازه uleb128 size of this list, in entries
فهرست encoded_catch_handler[handlers_size] actual list of handler lists, represented directly (not as offsets), and concatenated sequentially

encoded_catch_handler format

نام قالب توضیحات
اندازه sleb128 number of catch types in this list. If non-positive, then this is the negative of the number of catch types, and the catches are followed by a catch-all handler. For example: A size of 0 means that there is a catch-all but no explicitly typed catches. A size of 2 means that there are two explicitly typed catches and no catch-all. And a size of -1 means that there is one typed catch along with a catch-all.
کنترل کننده ها 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
آدرس 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:

نام ارزش قالب استدلال ها توضیحات
DBG_END_SEQUENCE 0x00 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 and method_id instances 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

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست 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

نام قالب توضیحات
اندازه uint size of the set, in entries
ورودی ها annotation_off_item[size] عناصر مجموعه 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)

نام قالب توضیحات
دید یوبایت intended visibility of this annotation (see below)
حاشیه نویسی 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 :

نام ارزش توضیحات
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)

نام قالب توضیحات
ارزش 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 .

نام قالب توضیحات
اندازه uint total size of the section
جبران می کند 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 .
پرچم ها 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:

نام ارزش توضیحات
لیست سفید 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 .
لیست سیاه 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.

نام قالب توضیحات
ارزش حاشیه نویسی 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.

نام قالب توضیحات
ارزش کلاس 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.

نام قالب توضیحات
ارزش روش 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.

نام قالب توضیحات
نام رشته the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null .
accessFlags بین المللی the originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine)

dalvik.annotation.MemberClasses

Appears on classes

A MemberClasses annotation is attached to each class which declares member classes. (A member class is a direct inner class that has a name.)

نام قالب توضیحات
ارزش 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.

نام قالب توضیحات
نام ها رشته[] The names of formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. A value in the array must be null if the formal parameter with that index has no name.
If parameter name strings are empty or contain '.', ';', '[' or '/' then a java.lang.reflect.MalformedParametersException will be thrown at runtime.
accessFlags بین المللی[] The access flags of the formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters.
The value is a bit mask with the following values:
  • 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.

نام قالب توضیحات
ارزش رشته[] 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.

نام قالب توضیحات
ارزش Class[] the array of exception types thrown
،

This document describes the layout and contents of .dex files, which are used to hold a set of class definitions and their associated adjunct data.

Guide to types

نام توضیحات
بایت 8-bit signed int
یوبایت 8-bit unsigned int
کوتاه 16-bit signed int, little-endian
کوتاه 16-bit unsigned int, little-endian
بین المللی 32-bit signed int, little-endian
uint 32-bit unsigned int, little-endian
طولانی 64-bit signed int, little-endian
طولانی 64-bit unsigned int, little-endian
sleb128 signed LEB128, variable-length (see below)
uleb128 unsigned LEB128, variable-length (see below)
uleb128p1 unsigned LEB128 plus 1 , variable-length (see below)

LEB128

LEB128 (" L ittle- E ndian B ase 128 ") is a variable-length encoding for arbitrary signed or unsigned integer quantities. The format was borrowed from the DWARF3 specification. In a .dex file, LEB128 is only ever used to encode 32-bit quantities.

Each LEB128 encoded value consists of one to five bytes, which together represent a single 32-bit value. Each byte has its most significant bit set except for the final byte in the sequence, which has its most significant bit clear. The remaining seven bits of each byte are payload, with the least significant seven bits of the quantity in the first byte, the next seven in the second byte and so on. In the case of a signed LEB128 ( sleb128 ), the most significant payload bit of the final byte in the sequence is sign-extended to produce the final value. In the unsigned case ( uleb128 ), any bits not explicitly represented are interpreted as 0 .

Bitwise diagram of a two-byte LEB128 value
بایت اول Second byte
1 bit 6 bit 5 bit 4 بیت 3 بیت 2 بیت 1 بیت 0 0 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7

The variant uleb128p1 is used to represent a signed value, where the representation is of the value plus one encoded as a uleb128 . This makes the encoding of -1 (alternatively thought of as the unsigned value 0xffffffff ) — but no other negative number — a single byte, and is useful in exactly those cases where the represented number must either be non-negative or -1 (or 0xffffffff ), and where no other negative values are allowed (or where large unsigned values are unlikely to be needed).

Here are some examples of the formats:

Encoded Sequence As sleb128 As uleb128 As uleb128p1
00 0 0 -1
01 1 1 0
7f -1 127 126
80 7f -128 16256 16255

طرح بندی فایل

نام قالب توضیحات
هدر header_item هدر
string_ids string_id_item[] string identifiers list. These are identifiers for all the strings used by this file, either for internal naming (eg, type descriptors) or as constant objects referred to by code. This list must be sorted by string contents, using UTF-16 code point values (not in a locale-sensitive manner), and it must not contain any duplicate entries.
type_ids type_id_item[] type identifiers list. These are identifiers for all types (classes, arrays, or primitive types) referred to by this file, whether defined in the file or not. This list must be sorted by string_id index, and it must not contain any duplicate entries.
proto_ids proto_id_item[] method prototype identifiers list. These are identifiers for all prototypes referred to by this file. This list must be sorted in return-type (by type_id index) major order, and then by argument list (lexicographic ordering, individual arguments ordered by type_id index). The list must not contain any duplicate entries.
field_ids field_id_item[] field identifiers list. These are identifiers for all fields referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (by type_id index) is the major order, field name (by string_id index) is the intermediate order, and type (by type_id index) is the minor order. The list must not contain any duplicate entries.
method_ids method_id_item[] method identifiers list. These are identifiers for all methods referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (by type_id index) is the major order, method name (by string_id index) is the intermediate order, and method prototype (by proto_id index) is the minor order. The list must not contain any duplicate entries.
class_defs class_def_item[] class definitions list. The classes must be ordered such that a given class's superclass and implemented interfaces appear in the list earlier than the referring class. Furthermore, it is invalid for a definition for the same-named class to appear more than once in the list.
call_site_ids call_site_id_item[] call site identifiers list. These are identifiers for all call sites referred to by this file, whether defined in the file or not. This list must be sorted in ascending order of call_site_off .
method_handles method_handle_item[] method handles list. A list of all method handles referred to by this file, whether defined in the file or not. This list is not sorted and may contain duplicates which will logically correspond to different method handle instances.
داده ها ubyte[] data area, containing all the support data for the tables listed above. Different items have different alignment requirements, and padding bytes are inserted before each item if necessary to achieve proper alignment.
link_data ubyte[] data used in statically linked files. The format of the data in this section is left unspecified by this document. This section is empty in unlinked files, and runtime implementations may use it as they see fit.

قالب کانتینر

Version 41 introduces a new container format for DEX data with the goal to save space. This container format allows several logical DEX files to be combined into a single physical file. The new format is mostly just naive concatenation of files in the previous format, with some differences:

  • The file_size is the size of the logical file, not the physical file. It can be used to iterate over all the logical files in the container.
  • Logical dex files may reference any later data in the container (but not earlier). This allows dex files to share data, such as strings, between them.
  • All offsets are relative to the physical file. No offset is relative to the header. This is ensures that sections with offsets can be shared between logical files.
  • The header adds two new fields to describe the bounds of the container. This is an additional consistency check and makes porting code to the new format easier.
  • The data_size and data_off are now unused. Data can be spread across multiple logical files and does not have to be contiguous.

Bitfield, string, and constant definitions

DEX_FILE_MAGIC

Embedded in header_item

The constant array/string DEX_FILE_MAGIC is the list of bytes that must appear at the beginning of a .dex file in order for it to be recognized as such. The value intentionally contains a newline ( "\n" or 0x0a ) and a null byte ( "\0" or 0x00 ) in order to help in the detection of certain forms of corruption. The value also encodes a format version number as three decimal digits, which is expected to increase monotonically over time as the format evolves.

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

Note: Support for version 040 of the format was added in the Android 10.0 release, which extended the set of allowed characters in SimpleNames .

Note: Support for version 039 of the format was added in the Android 9.0 release, which introduced two new bytecodes, const-method-handle and const-method-type . (These are each described in the Summary of bytecode set table.) In Android 10, version 039 extends the DEX file format to include hidden API information that's only applicable to DEX files on the boot class path.

Note: Support for version 038 of the format was added in the Android 8.0 release. Version 038 added new bytecodes ( invoke-polymorphic and invoke-custom ) and data for method handles.

Note: Support for version 037 of the format was added in the Android 7.0 release. Prior to version 037 most versions of Android have used version 035 of the format. The only difference between versions 035 and 037 is the addition of default methods and the adjustment of the invoke .

Note: At least a couple earlier versions of the format have been used in widely available public software releases. For example, version 009 was used for the M3 releases of the Android platform (November–December 2007), and version 013 was used for the M5 releases of the Android platform (February–March 2008). In several respects, these earlier versions of the format differ significantly from the version described in this document.

ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT

Embedded in header_item

The constant ENDIAN_CONSTANT is used to indicate the endianness of the file in which it is found. Although the standard .dex format is little-endian, implementations may choose to perform byte-swapping. Should an implementation come across a header whose endian_tag is REVERSE_ENDIAN_CONSTANT instead of ENDIAN_CONSTANT , it would know that the file has been byte-swapped from the expected form.

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

NO_INDEX

Embedded in class_def_item and debug_info_item

The constant NO_INDEX is used to indicate that an index value is absent.

Note: This value isn't defined to be 0 , because that is in fact typically a valid index.

The chosen value for NO_INDEX is representable as a single byte in the uleb128p1 encoding.

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

access_flags definitions

Embedded in class_def_item, encoded_field, encoded_method, and InnerClass

Bitfields of these flags are used to indicate the accessibility and overall properties of classes and class members.

نام ارزش For Classes (and InnerClass annotations) For Fields For Methods
ACC_PUBLIC 0x1 public : visible everywhere public : visible everywhere public : visible everywhere
ACC_PRIVATE 0x2 * private : only visible to defining class private : only visible to defining class private : only visible to defining class
ACC_PROTECTED 0x4 * protected : visible to package and subclasses protected : visible to package and subclasses protected : visible to package and subclasses
ACC_STATIC 0x8 * static : is not constructed with an outer this reference static : global to defining class static : does not take a this argument
ACC_FINAL 0x10 final : not subclassable final : immutable after construction final : not overridable
ACC_SYNCHRONIZED 0x20 synchronized : associated lock automatically acquired around call to this method.

Note: This is only valid to set when ACC_NATIVE is also set.

ACC_VOLATILE 0x40 volatile : special access rules to help with thread safety
ACC_BRIDGE 0x40 bridge method, added automatically by compiler as a type-safe bridge
ACC_TRANSIENT 0x80 transient : not to be saved by default serialization
ACC_VARARGS 0x80 last argument should be treated as a "rest" argument by compiler
ACC_NATIVE 0x100 native : implemented in native code
ACC_INTERFACE 0x200 interface : multiply-implementable abstract class
ACC_ABSTRACT 0x400 abstract : not directly instantiable abstract : unimplemented by this class
ACC_STRICT 0x800 strictfp : strict rules for floating-point arithmetic
ACC_SYNTHETIC 0x1000 not directly defined in source code not directly defined in source code not directly defined in source code
ACC_ANNOTATION 0x2000 declared as an annotation class
ACC_ENUM 0x4000 declared as an enumerated type declared as an enumerated value
(استفاده نشده) 0x8000
ACC_CONSTRUCTOR 0x10000 constructor method (class or instance initializer)
ACC_DECLARED_
همگام
0x20000 declared synchronized .

Note: This has no effect on execution (other than in reflection of this flag, per se).

* Only allowed on for InnerClass annotations, and must not ever be on in a class_def_item .

Modified UTF-8 encoding

As a concession to easier legacy support, the .dex format encodes its string data in a de facto standard modified UTF-8 form, hereafter referred to as MUTF-8. This form is identical to standard UTF-8, except:

  • Only the one-, two-, and three-byte encodings are used.
  • Code points in the range U+10000U+10ffff are encoded as a surrogate pair, each of which is represented as a three-byte encoded value.
  • The code point U+0000 is encoded in two-byte form.
  • A plain null byte (value 0 ) indicates the end of a string, as is the standard C language interpretation.

The first two items above can be summarized as: MUTF-8 is an encoding format for UTF-16, instead of being a more direct encoding format for Unicode characters.

The final two items above make it simultaneously possible to include the code point U+0000 in a string and still manipulate it as a C-style null-terminated string.

However, the special encoding of U+0000 means that, unlike normal UTF-8, the result of calling the standard C function strcmp() on a pair of MUTF-8 strings does not always indicate the properly signed result of comparison of unequal strings. When ordering (not just equality) is a concern, the most straightforward way to compare MUTF-8 strings is to decode them character by character, and compare the decoded values. (However, more clever implementations are also possible.)

Please refer to The Unicode Standard for further information about character encoding. MUTF-8 is actually closer to the (relatively less well-known) encoding CESU-8 than to UTF-8 per se.

encoded_value encoding

Embedded in annotation_element and encoded_array_item

An encoded_value is an encoded piece of (nearly) arbitrary hierarchically structured data. The encoding is meant to be both compact and straightforward to parse.

نام قالب توضیحات
(value_arg << 5) | value_type یوبایت byte indicating the type of the immediately subsequent value along with an optional clarifying argument in the high-order three bits. See below for the various value definitions. In most cases, value_arg encodes the length of the immediately-subsequent value in bytes, as (size - 1) , eg, 0 means that the value requires one byte, and 7 means it requires eight bytes; however, there are exceptions as noted below.
ارزش ubyte[] bytes representing the value, variable in length and interpreted differently for different value_type bytes, though always little-endian. See the various value definitions below for details.

Value formats

نام را تایپ کنید value_type value_arg Format value Format توضیحات
VALUE_BYTE 0x00 (none; must be 0 ) ubyte[1] signed one-byte integer value
VALUE_SHORT 0x02 size - 1 (0…1) ubyte[size] signed two-byte integer value, sign-extended
VALUE_CHAR 0x03 size - 1 (0…1) ubyte[size] unsigned two-byte integer value, zero-extended
VALUE_INT 0x04 size - 1 (0…3) ubyte[size] signed four-byte integer value, sign-extended
VALUE_LONG 0x06 size - 1 (0…7) ubyte[size] signed eight-byte integer value, sign-extended
VALUE_FLOAT 0x10 size - 1 (0…3) ubyte[size] four-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 32-bit floating point value
VALUE_DOUBLE 0x11 size - 1 (0…7) ubyte[size] eight-byte bit pattern, zero-extended to the right , and interpreted as an IEEE754 64-bit floating point value
VALUE_METHOD_TYPE 0x15 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the proto_ids section and representing a method type value
VALUE_METHOD_HANDLE 0x16 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_handles section and representing a method handle value
VALUE_STRING 0x17 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the string_ids section and representing a string value
VALUE_TYPE 0x18 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the type_ids section and representing a reflective type/class value
VALUE_FIELD 0x19 size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing a reflective field value
VALUE_METHOD 0x1a size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the method_ids section and representing a reflective method value
VALUE_ENUM 0x1b size - 1 (0…3) ubyte[size] unsigned (zero-extended) four-byte integer value, interpreted as an index into the field_ids section and representing the value of an enumerated type constant
VALUE_ARRAY 0x1c (none; must be 0 ) encoded_array an array of values, in the format specified by " encoded_array format" below. The size of the value is implicit in the encoding.
VALUE_ANNOTATION 0x1d (none; must be 0 ) encoded_annotation a sub-annotation, in the format specified by " encoded_annotation format" below. The size of the value is implicit in the encoding.
VALUE_NULL 0x1e (none; must be 0 ) (هیچ کدام) null reference value
VALUE_BOOLEAN 0x1f boolean (0…1) (هیچ کدام) one-bit value; 0 for false and 1 for true . The bit is represented in the value_arg .

encoded_array format

نام قالب توضیحات
اندازه uleb128 تعداد عناصر در آرایه
ارزش ها encoded_value[size] a series of size encoded_value byte sequences in the format specified by this section, concatenated sequentially.

encoded_annotation format

نام قالب توضیحات
type_idx uleb128 type of the annotation. This must be a class (not array or primitive) type.
اندازه uleb128 number of name-value mappings in this annotation
عناصر annotation_element[size] elements of the annotation, represented directly in-line (not as offsets). Elements must be sorted in increasing order by string_id index.

annotation_element format

نام قالب توضیحات
name_idx uleb128 element name, represented as an index into the string_ids section. The string must conform to the syntax for MemberName , defined above.
ارزش encoded_value element value

String syntax

There are several kinds of item in a .dex file which ultimately refer to a string. The following BNF-style definitions indicate the acceptable syntax for these strings.

SimpleName

A SimpleName is the basis for the syntax of the names of other things. The .dex format allows a fair amount of latitude here (much more than most common source languages). In brief, a simple name consists of any low-ASCII alphabetic character or digit, a few specific low-ASCII symbols, and most non-ASCII code points that are not control, space, or special characters. Starting from version 040 the format additionally allows space characters (Unicode Zs category). Note that surrogate code points (in the range U+d800U+dfff ) are not considered valid name characters, per se, but Unicode supplemental characters are valid (which are represented by the final alternative of the rule for SimpleNameChar ), and they should be represented in a file as pairs of surrogate code points in the MUTF-8 encoding.

SimpleName
SimpleNameChar ( SimpleNameChar )*
SimpleNameChar
'A''Z'
| 'a''z'
| '0''9'
| ' ' since DEX version 040
| '$'
| '-'
| '_'
| U+00a0 since DEX version 040
| U+00a1U+1fff
| U+2000U+200a since DEX version 040
| U+2010U+2027
| U+202f since DEX version 040
| U+2030U+d7ff
| U+e000U+ffef
| U+10000U+10ffff

MemberName

used by field_id_item and method_id_item

A MemberName is the name of a member of a class, members being fields, methods, and inner classes.

MemberName
SimpleName
| '<' SimpleName '>'

FullClassName

A FullClassName is a fully qualified class name, including an optional package specifier followed by a required name.

FullClassName
OptionalPackagePrefix SimpleName
OptionalPackagePrefix
( SimpleName '/' )*

TypeDescriptor

Used by type_id_item

A TypeDescriptor is the representation of any type, including primitives, classes, arrays, and void . See below for the meaning of the various versions.

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

ShortyDescriptor

Used by proto_id_item

A ShortyDescriptor is the short form representation of a method prototype, including return and parameter types, except that there is no distinction between various reference (class or array) types. Instead, all reference types are represented by a single 'L' character.

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

TypeDescriptor semantics

This is the meaning of each of the variants of TypeDescriptor .

نحو معنی
V void only valid for return types
ز boolean
ب byte
اس short
سی char
من int
جی long
اف float
D double
L fully/qualified/Name ; the class fully.qualified.Name
[ descriptor array of descriptor , usable recursively for arrays-of-arrays, though it is invalid to have more than 255 dimensions.

Items and related structures

This section includes definitions for each of the top-level items that may appear in a .dex file.

header_item

Appears in the header section

Alignment: 4 bytes

نام قالب توضیحات
سحر و جادو ubyte[8] = DEX_FILE_MAGIC magic value. See discussion above under " DEX_FILE_MAGIC " for more details.
چک جمع uint adler32 checksum of the rest of the file (everything but magic and this field); used to detect file corruption
امضا ubyte[20] SHA-1 signature (hash) of the rest of the file (everything but magic , checksum , and this field); used to uniquely identify files
فایل_اندازه uint

size of the entire file (including the header), in bytes (v40 or earlier)

distance in bytes from the start of this header to the next header or to the end of the whole file (the container). (نسخه 41 یا بالاتر)

header_size uint

size of the header (this entire section), in bytes. This allows for at least a limited amount of backwards/forwards compatibility without invalidating the format.

must be 0x70 (112) bytes (v40 or earlier)

must be 0x78 (120) bytes (v41 or later)

endian_tag uint = ENDIAN_CONSTANT endianness tag. See discussion above under " ENDIAN_CONSTANT and REVERSE_ENDIAN_CONSTANT " for more details.
link_size uint size of the link section, or 0 if this file isn't statically linked
link_off uint offset from the start of the file to the link section, or 0 if link_size == 0 . The offset, if non-zero, should be to an offset into the link_data section. The format of the data pointed at is left unspecified by this document; this header field (and the previous) are left as hooks for use by runtime implementations.
map_off uint offset from the start of the file to the map item. The offset, which must be non-zero, should be to an offset into the data section, and the data should be in the format specified by " map_list " below.
string_ids_size uint count of strings in the string identifiers list
string_ids_off uint offset from the start of the file to the string identifiers list, or 0 if string_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the string_ids section.
type_ids_size uint count of elements in the type identifiers list, at most 65535
type_ids_off uint offset from the start of the file to the type identifiers list, or 0 if type_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the type_ids section.
proto_ids_size uint count of elements in the prototype identifiers list, at most 65535
proto_ids_off uint offset from the start of the file to the prototype identifiers list, or 0 if proto_ids_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the proto_ids section.
field_ids_size uint count of elements in the field identifiers list
field_ids_off uint offset from the start of the file to the field identifiers list, or 0 if field_ids_size == 0 . The offset, if non-zero, should be to the start of the field_ids section.
method_ids_size uint count of elements in the method identifiers list
method_ids_off uint offset from the start of the file to the method identifiers list, or 0 if method_ids_size == 0 . The offset, if non-zero, should be to the start of the method_ids section.
class_defs_size uint count of elements in the class definitions list
class_defs_off uint offset from the start of the file to the class definitions list, or 0 if class_defs_size == 0 (admittedly a strange edge case). The offset, if non-zero, should be to the start of the class_defs section.
data_size uint

Size of data section in bytes. Must be an even multiple of sizeof(uint). (نسخه 40 یا قبل از آن)

Unused (v41 or later)

data_off uint

offset from the start of the file to the start of the data section (v40 or earlier)

Unused (v41 or later)

ظرف_اندازه uint

this field does not exist. It can be assumed to be equal to file_size . (نسخه 40 یا قبل از آن)

size of the entire file (including other dex headers and their data). (نسخه 41 یا بالاتر)

header_offset uint

this field does not exist. It can be assumed to be equal to 0 . (نسخه 40 یا قبل از آن)

offset from the start of the file to the start of this header. (نسخه 41 یا بالاتر)

map_list

Appears in the data section

Referenced from header_item

Alignment: 4 bytes

This is a list of the entire contents of a file, in order. It contains some redundancy with respect to the header_item but is intended to be an easy form to use to iterate over an entire file. A given type must appear at most once in a map, but there is no restriction on what order types may appear in, other than the restrictions implied by the rest of the format (eg, a header section must appear first, followed by a string_ids section, etc.). Additionally, the map entries must be ordered by initial offset and must not overlap.

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست map_item[size] elements of the list

map_item format

نام قالب توضیحات
نوع کوتاه type of the items; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
اندازه uint count of the number of items to be found at the indicated offset
جبران uint offset from the start of the file to the items in question

Type codes

نوع مورد ثابت ارزش Item Size In Bytes
header_item TYPE_HEADER_ITEM 0x0000 0x70
string_id_item TYPE_STRING_ID_ITEM 0x0001 0x04
type_id_item TYPE_TYPE_ID_ITEM 0x0002 0x04
proto_id_item TYPE_PROTO_ID_ITEM 0x0003 0x0c
field_id_item TYPE_FIELD_ID_ITEM 0x0004 0x08
method_id_item TYPE_METHOD_ID_ITEM 0x0005 0x08
class_def_item TYPE_CLASS_DEF_ITEM 0x0006 0x20
call_site_id_item TYPE_CALL_SITE_ID_ITEM 0x0007 0x04
method_handle_item TYPE_METHOD_HANDLE_ITEM 0x0008 0x08
map_list TYPE_MAP_LIST 0x1000 4 + (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 implicit; must parse
code_item TYPE_CODE_ITEM 0x2001 implicit; must parse
string_data_item TYPE_STRING_DATA_ITEM 0x2002 implicit; must parse
debug_info_item TYPE_DEBUG_INFO_ITEM 0x2003 implicit; must parse
annotation_item TYPE_ANNOTATION_ITEM 0x2004 implicit; must parse
encoded_array_item TYPE_ENCODED_ARRAY_ITEM 0x2005 implicit; must parse
annotations_directory_item TYPE_ANNOTATIONS_DIRECTORY_ITEM 0x2006 implicit; must parse
hiddenapi_class_data_item TYPE_HIDDENAPI_CLASS_DATA_ITEM 0xF000 implicit; must parse

string_id_item

Appears in the string_ids section

Alignment: 4 bytes

نام قالب توضیحات
string_data_off uint offset from the start of the file to the string data for this item. The offset should be to a location in the data section, and the data should be in the format specified by " string_data_item " below. There is no alignment requirement for the offset.

string_data_item

Appears in the data section

Alignment: none (byte-aligned)

نام قالب توضیحات
utf16_size uleb128 size of this string, in UTF-16 code units (which is the "string length" in many systems). That is, this is the decoded length of the string. (The encoded length is implied by the position of the 0 byte.)
داده ها ubyte[] a series of MUTF-8 code units (aka octets, aka bytes) followed by a byte of value 0 . See "MUTF-8 (Modified UTF-8) Encoding" above for details and discussion about the data format.

Note: It is acceptable to have a string which includes (the encoded form of) UTF-16 surrogate code units (that is, U+d800U+dfff ) either in isolation or out-of-order with respect to the usual encoding of Unicode into UTF-16. It is up to higher-level uses of strings to reject such invalid encodings, if appropriate.

type_id_item

Appears in the type_ids section

Alignment: 4 bytes

نام قالب توضیحات
descriptor_idx uint index into the string_ids list for the descriptor string of this type. The string must conform to the syntax for TypeDescriptor , defined above.

proto_id_item

Appears in the proto_ids section

Alignment: 4 bytes

نام قالب توضیحات
shorty_idx uint index into the string_ids list for the short-form descriptor string of this prototype. The string must conform to the syntax for ShortyDescriptor , defined above, and must correspond to the return type and parameters of this item.
return_type_idx uint index into the type_ids list for the return type of this prototype
parameters_off uint offset from the start of the file to the list of parameter types for this prototype, or 0 if this prototype has no parameters. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by "type_list" below. Additionally, there should be no reference to the type void in the list.

field_id_item

Appears in the field_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this field. This must be a class type, and not an array or primitive type.
type_idx کوتاه index into the type_ids list for the type of this field
name_idx uint index into the string_ids list for the name of this field. The string must conform to the syntax for MemberName , defined above.

method_id_item

Appears in the method_ids section

Alignment: 4 bytes

نام قالب توضیحات
class_idx کوتاه index into the type_ids list for the definer of this method. This must be a class or array type, and not a primitive type.
proto_idx کوتاه index into the proto_ids list for the prototype of this method
name_idx unint index into the string_ids list for the name of this method. The string must conform to the syntax for MemberName , defined above.

class_def_item

Appears in the class_defs section

Alignment: 4 bytes

نام قالب توضیحات
class_idx uint index into the type_ids list for this class. This must be a class type, and not an array or primitive type.
access_flags uint access flags for the class ( public , final , etc.). See " access_flags Definitions" for details.
superclass_idx uint index into the type_ids list for the superclass, or the constant value NO_INDEX if this class has no superclass (ie, it is a root class such as Object ). If present, this must be a class type, and not an array or primitive type.
interfaces_off uint offset from the start of the file to the list of interfaces, or 0 if there are none. This offset should be in the data section, and the data there should be in the format specified by " type_list " below. Each of the elements of the list must be a class type (not an array or primitive type), and there must not be any duplicates.
source_file_idx uint index into the string_ids list for the name of the file containing the original source for (at least most of) this class, or the special value NO_INDEX to represent a lack of this information. The debug_info_item of any given method may override this source file, but the expectation is that most classes will only come from one source file.
annotations_off uint offset from the start of the file to the annotations structure for this class, or 0 if there are no annotations on this class. This offset, if non-zero, should be in the data section, and the data there should be in the format specified by " annotations_directory_item " below, with all items referring to this class as the definer.
class_data_off uint offset from the start of the file to the associated class data for this item, or 0 if there is no class data for this class. (This may be the case, for example, if this class is a marker interface.) The offset, if non-zero, should be in the data section, and the data there should be in the format specified by " class_data_item " below, with all items referring to this class as the definer.
static_values_off uint offset from the start of the file to the list of initial values for static fields, or 0 if there are none (and all static fields are to be initialized with 0 or null ). This offset should be in the data section, and the data there should be in the format specified by " encoded_array_item " below. The size of the array must be no larger than the number of static fields declared by this class, and the elements correspond to the static fields in the same order as declared in the corresponding field_list . The type of each array element must match the declared type of its corresponding field. If there are fewer elements in the array than there are static fields, then the leftover fields are initialized with a type-appropriate 0 or null .

call_site_id_item

Appears in the call_site_ids section

Alignment: 4 bytes

نام قالب توضیحات
call_site_off uint offset from the start of the file to call site definition. The offset should be in the data section, and the data there should be in the format specified by "call_site_item" below.

call_site_item

Appears in the data section

Alignment: none (byte aligned)

The call_site_item is an encoded_array_item whose elements correspond to the arguments provided to a bootstrap linker method. The first three arguments are:

  1. A method handle representing the bootstrap linker method (VALUE_METHOD_HANDLE).
  2. A method name that the bootstrap linker should resolve (VALUE_STRING).
  3. 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:

  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 کوتاه type of the method handle; جدول زیر را ببینید
استفاده نشده کوتاه (استفاده نشده)
field_or_method_id کوتاه Field or method id depending on whether the method handle type is an accessor or a method invoker
استفاده نشده کوتاه (استفاده نشده)

Method handle type codes

ثابت ارزش توضیحات
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 and method_id instances 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

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست type_item[size] elements of the list

type_item format

نام قالب توضیحات
type_idx کوتاه index into the type_ids list

code_item

Referenced from encoded_method

Appears in the data section

Alignment: 4 bytes

نام قالب توضیحات
registers_size کوتاه the number of registers used by this code
ins_size کوتاه the number of words of incoming arguments to the method that this code is for
outs_size کوتاه the number of words of outgoing argument space required by this code for method invocation
tries_size کوتاه the number of try_item s for this instance. If non-zero, then these appear as the tries array just after the insns in this instance.
debug_info_off 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 instances and not on the larger internal structures.
بالشتک 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.
تلاش می کند 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.
کنترل کننده ها 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 کوتاه number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 .
handler_off کوتاه offset in bytes from the start of the associated encoded_catch_hander_list to the encoded_catch_handler for this entry. This must be an offset to the start of an encoded_catch_handler .

encoded_catch_handler_list format

نام قالب توضیحات
اندازه uleb128 size of this list, in entries
فهرست encoded_catch_handler[handlers_size] actual list of handler lists, represented directly (not as offsets), and concatenated sequentially

encoded_catch_handler format

نام قالب توضیحات
اندازه sleb128 number of catch types in this list. If non-positive, then this is the negative of the number of catch types, and the catches are followed by a catch-all handler. For example: A size of 0 means that there is a catch-all but no explicitly typed catches. A size of 2 means that there are two explicitly typed catches and no catch-all. And a size of -1 means that there is one typed catch along with a catch-all.
کنترل کننده ها 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
آدرس 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:

نام ارزش قالب استدلال ها توضیحات
DBG_END_SEQUENCE 0x00 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 (هیچ کدام) 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 unint 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 and method_id instances 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

نام قالب توضیحات
اندازه uint size of the list, in entries
فهرست 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

نام قالب توضیحات
اندازه uint size of the set, in entries
ورودی ها annotation_off_item[size] عناصر مجموعه 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)

نام قالب توضیحات
دید یوبایت intended visibility of this annotation (see below)
حاشیه نویسی 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 :

نام ارزش توضیحات
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)

نام قالب توضیحات
ارزش 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 .

نام قالب توضیحات
اندازه uint total size of the section
جبران می کند 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 .
پرچم ها 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:

نام ارزش توضیحات
لیست سفید 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 .
لیست سیاه 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.

نام قالب توضیحات
ارزش حاشیه نویسی 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.

نام قالب توضیحات
ارزش کلاس 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.

نام قالب توضیحات
ارزش روش 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.

نام قالب توضیحات
نام رشته the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null .
accessFlags بین المللی the originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine)

dalvik.annotation.MemberClasses

Appears on classes

A MemberClasses annotation is attached to each class which declares member classes. (A member class is a direct inner class that has a name.)

نام قالب توضیحات
ارزش 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.

نام قالب توضیحات
نام ها رشته[] The names of formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. A value in the array must be null if the formal parameter with that index has no name.
If parameter name strings are empty or contain '.', ';', '[' or '/' then a java.lang.reflect.MalformedParametersException will be thrown at runtime.
accessFlags بین المللی[] The access flags of the formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters.
The value is a bit mask with the following values:
  • 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.

نام قالب توضیحات
ارزش رشته[] 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.

نام قالب توضیحات
ارزش Class[] the array of exception types thrown