این سند طرح و محتویات فایلهای .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 قبل از هر آیتم درج می شوند. |
پیوند_داده | یوبایت[] | دادههای مورد استفاده در فایلهای مرتبط استاتیک فرمت داده های این بخش توسط این سند مشخص نشده است. این بخش در فایلهای بدون پیوند خالی است و پیادهسازیهای زمان اجرا ممکن است آنطور که صلاح میدانند از آن استفاده کنند. |
بیت فیلد، رشته و تعاریف ثابت
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"
توجه: پشتیبانی از فرمت 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
آن به جای REVERSE_ENDIAN_CONSTANT
ENDIAN_CONSTANT
باشد، متوجه میشود که فایل از فرم مورد انتظار بایت تعویض شده است.
uint ENDIAN_CONSTANT = 0x12345678; uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
در class_def_item و debug_info_item تعبیه شده است
ثابت NO_INDEX
برای نشان دادن عدم وجود مقدار شاخص استفاده می شود.
توجه: این مقدار 0
تعریف نشده است، زیرا در واقع یک شاخص معتبر است.
مقدار انتخاب شده برای NO_INDEX
به صورت یک بایت در کدگذاری uleb128p1
است.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
تعاریف access_flags
در class_def_item، encoded_field، encoded_method و InnerClass تعبیه شده است
فیلدهای بیتی این پرچم ها برای نشان دادن قابلیت دسترسی و ویژگی های کلی کلاس ها و اعضای کلاس استفاده می شوند.
نام | ارزش | برای کلاس ها (و حاشیه نویسی InnerClass ) | برای فیلدها | برای روش ها |
---|---|---|---|---|
ACC_PUBLIC | 0x1 | public : در همه جا قابل مشاهده است | public : در همه جا قابل مشاهده است | public : در همه جا قابل مشاهده است |
ACC_PRIVATE | 0x2 | private : فقط برای تعریف کلاس قابل مشاهده است | private : فقط برای تعریف کلاس قابل مشاهده است | private : فقط برای تعریف کلاس قابل مشاهده است |
ACC_PROTECTED | 0x4 | protected : قابل مشاهده برای بسته و زیر کلاس ها | protected : قابل مشاهده برای بسته و زیر کلاس ها | protected : قابل مشاهده برای بسته و زیر کلاس ها |
ACC_STATIC | 0x8 | static : با یک مرجع خارجی ساخته this است | static : جهانی برای تعریف کلاس | static : this استدلال را نمی پذیرد |
ACC_FINAL | 0x10 | final : قابل طبقه بندی نیست | final : تغییر ناپذیر پس از ساخت | final : غیر قابل رد شدن |
ACC_SYNCHRONIZED | 0x20 | synchronized : قفل مرتبط به طور خودکار حول تماس با این روش به دست می آید. توجه: این فقط زمانی معتبر است که | ||
ACC_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
باشد.
رمزگذاری MUTF-8 (تغییر یافته UTF-8).
به عنوان امتیازی برای پشتیبانی آسان تر قدیمی، فرمت .dex
داده های رشته ای خود را در یک فرم استاندارد تغییر یافته UTF-8 که از این به بعد MUTF-8 نامیده می شود، رمزگذاری می کند. این فرم با استاندارد UTF-8 یکسان است، به جز:
- فقط از کدهای یک، دو و سه بایتی استفاده می شود.
- نقاط کد در محدوده
U+10000
…U+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+d800
… U+dfff
) به خودی خود کاراکترهای نام معتبر در نظر گرفته نمی شوند، اما کاراکترهای تکمیلی یونیکد معتبر هستند (که با جایگزین نهایی قانون برای SimpleNameChar نشان داده می شوند) و آنها باید در یک فایل به عنوان جفت نقاط کد جایگزین در رمزگذاری MUTF-8 نشان داده شود.
SimpleName → | ||
SimpleNameChar ( SimpleNameChar )* | ||
SimpleNameChar → | ||
'A' ... 'Z' | ||
| | 'a' ... 'z' | |
| | '0' … '9' | |
| | ' ' | از نسخه DEX 040 |
| | '$' | |
| | '-' | |
| | '_' | |
| | U+00a0 | از نسخه DEX 040 |
| | U+00a1 … U+1fff | |
| | U+2000 … U+200a | از نسخه DEX 040 |
| | U+2010 … U+2027 | |
| | U+202f | از نسخه DEX 040 |
| | U+2030 … U+d7ff | |
| | U+e000 … U+ffef | |
| | U+10000 … U+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 | اندازه کل فایل (از جمله هدر)، بر حسب بایت |
سربرگ_اندازه | واحد = 0x70 | اندازه هدر (کل این بخش)، بر حسب بایت. این اجازه می دهد تا حداقل مقدار محدودی از سازگاری به عقب و جلو بدون نامعتبر کردن قالب. |
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) باشد. |
داده_خاموش | unint | از ابتدای فایل تا ابتدای بخش data افست شود. |
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 (یعنی |
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 است که عناصر آن با آرگومان های ارائه شده به روش پیوند دهنده راه انداز مطابقت دارد. سه استدلال اول عبارتند از:
- یک دسته روش که نشان دهنده روش پیوند دهنده راه انداز (VALUE_METHOD_HANDLE) است.
- نام روشی که پیوند دهنده بوت استرپ باید آن را حل کند (VALUE_STRING).
- A method type corresponding to the type of the method name to be resolved (VALUE_METHOD_TYPE).
Any additional arguments are constant values passed to the bootstrap linker method. These arguments are passed in order and without any type conversions.
The method handle representing the bootstrap linker method must have return type java.lang.invoke.CallSite
. The first three parameter types are:
-
java.lang.invoke.Lookup
-
java.lang.String
-
java.lang.invoke.MethodType
The parameter types of any additional arguments are determined from their constant values.
method_handle_item
appears in the method_handles section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
method_handle_type | ushort | type of the method handle; see table below |
unused | ushort | (unused) |
field_or_method_id | ushort | Field or method id depending on whether the method handle type is an accessor or a method invoker |
unused | ushort | (unused) |
Method Handle Type Codes
Constant | ارزش | شرح |
---|---|---|
METHOD_HANDLE_TYPE_STATIC_PUT | 0x00 | Method handle is a static field setter (accessor) |
METHOD_HANDLE_TYPE_STATIC_GET | 0x01 | Method handle is a static field getter (accessor) |
METHOD_HANDLE_TYPE_INSTANCE_PUT | 0x02 | Method handle is an instance field setter (accessor) |
METHOD_HANDLE_TYPE_INSTANCE_GET | 0x03 | Method handle is an instance field getter (accessor) |
METHOD_HANDLE_TYPE_INVOKE_STATIC | 0x04 | Method handle is a static method invoker |
METHOD_HANDLE_TYPE_INVOKE_INSTANCE | 0x05 | Method handle is an instance method invoker |
METHOD_HANDLE_TYPE_INVOKE_CONSTRUCTOR | 0x06 | Method handle is a constructor method invoker |
METHOD_HANDLE_TYPE_INVOKE_DIRECT | 0x07 | Method handle is a direct method invoker |
METHOD_HANDLE_TYPE_INVOKE_INTERFACE | 0x08 | Method handle is an interface method invoker |
class_data_item
referenced from class_def_item
appears in the data section
alignment: none (byte-aligned)
Name | Format | شرح |
---|---|---|
static_fields_size | uleb128 | the number of static fields defined in this item |
instance_fields_size | uleb128 | the number of instance fields defined in this item |
direct_methods_size | uleb128 | the number of direct methods defined in this item |
virtual_methods_size | uleb128 | the number of virtual methods defined in this item |
static_fields | encoded_field[static_fields_size] | the defined static fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order. |
instance_fields | encoded_field[instance_fields_size] | the defined instance fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order. |
direct_methods | encoded_method[direct_methods_size] | the defined direct (any of static , private , or constructor) methods, represented as a sequence of encoded elements. The methods must be sorted by method_idx in increasing order. |
virtual_methods | encoded_method[virtual_methods_size] | the defined virtual (none of static , private , or constructor) methods, represented as a sequence of encoded elements. This list should not include inherited methods unless overridden by the class that this item represents. The methods must be sorted by method_idx in increasing order. The method_idx of a virtual method must not be the same as any direct method. |
Note: All elements' field_id
s and method_id
s must refer to the same defining class.
encoded_field format
Name | Format | شرح |
---|---|---|
field_idx_diff | uleb128 | index into the field_ids list for the identity of this field (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly. |
access_flags | uleb128 | access flags for the field ( public , final , etc.). See " access_flags Definitions" for details. |
encoded_method format
Name | Format | شرح |
---|---|---|
method_idx_diff | uleb128 | index into the method_ids list for the identity of this method (includes the name and descriptor), represented as a difference from the index of previous element in the list. The index of the first element in a list is represented directly. |
access_flags | uleb128 | access flags for the method ( public , final , etc.). See " access_flags Definitions" for details. |
code_off | uleb128 | offset from the start of the file to the code structure for this method, or 0 if this method is either abstract or native . The offset should be to a location in the data section. The format of the data is specified by " code_item " below. |
type_list
referenced from class_def_item and proto_id_item
appears in the data section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
size | uint | size of the list, in entries |
list | type_item[size] | elements of the list |
type_item format
Name | Format | شرح |
---|---|---|
type_idx | ushort | index into the type_ids list |
code_item
referenced from encoded_method
appears in the data section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
registers_size | ushort | the number of registers used by this code |
ins_size | ushort | the number of words of incoming arguments to the method that this code is for |
outs_size | ushort | the number of words of outgoing argument space required by this code for method invocation |
tries_size | ushort | the number of try_item s for this instance. If non-zero, then these appear as the tries array just after the insns in this instance. |
debug_info_off | uint | offset from the start of the file to the debug info (line numbers + local variable info) sequence for this code, or 0 if there simply is no information. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " debug_info_item " below. |
insns_size | uint | size of the instructions list, in 16-bit code units |
insns | ushort[insns_size] | actual array of bytecode. The format of code in an insns array is specified by the companion document Dalvik bytecode . Note that though this is defined as an array of ushort , there are some internal structures that prefer four-byte alignment. Also, if this happens to be in an endian-swapped file, then the swapping is only done on individual ushort s and not on the larger internal structures. |
padding | ushort (optional) = 0 | two bytes of padding to make tries four-byte aligned. This element is only present if tries_size is non-zero and insns_size is odd. |
tries | try_item[tries_size] (optional) | array indicating where in the code exceptions are caught and how to handle them. Elements of the array must be non-overlapping in range and in order from low to high address. This element is only present if tries_size is non-zero. |
handlers | encoded_catch_handler_list (optional) | bytes representing a list of lists of catch types and associated handler addresses. Each try_item has a byte-wise offset into this structure. This element is only present if tries_size is non-zero. |
try_item format
Name | Format | شرح |
---|---|---|
start_addr | uint | start address of the block of code covered by this entry. The address is a count of 16-bit code units to the start of the first covered instruction. |
insn_count | ushort | number of 16-bit code units covered by this entry. The last code unit covered (inclusive) is start_addr + insn_count - 1 . |
handler_off | ushort | offset in bytes from the start of the associated encoded_catch_hander_list to the encoded_catch_handler for this entry. This must be an offset to the start of an encoded_catch_handler . |
encoded_catch_handler_list format
Name | Format | شرح |
---|---|---|
size | uleb128 | size of this list, in entries |
list | encoded_catch_handler[handlers_size] | actual list of handler lists, represented directly (not as offsets), and concatenated sequentially |
encoded_catch_handler format
Name | Format | شرح |
---|---|---|
size | sleb128 | number of catch types in this list. If non-positive, then this is the negative of the number of catch types, and the catches are followed by a catch-all handler. For example: A size of 0 means that there is a catch-all but no explicitly typed catches. A size of 2 means that there are two explicitly typed catches and no catch-all. And a size of -1 means that there is one typed catch along with a catch-all. |
handlers | encoded_type_addr_pair[abs(size)] | stream of abs(size) encoded items, one for each caught type, in the order that the types should be tested. |
catch_all_addr | uleb128 (optional) | bytecode address of the catch-all handler. This element is only present if size is non-positive. |
encoded_type_addr_pair format
Name | Format | شرح |
---|---|---|
type_idx | uleb128 | index into the type_ids list for the type of the exception to catch |
addr | uleb128 | bytecode address of the associated exception handler |
debug_info_item
referenced from code_item
appears in the data section
alignment: none (byte-aligned)
Each debug_info_item
defines a DWARF3-inspired byte-coded state machine that, when interpreted, emits the positions table and (potentially) the local variable information for a code_item
. The sequence begins with a variable-length header (the length of which depends on the number of method parameters), is followed by the state machine bytecodes, and ends with an DBG_END_SEQUENCE
byte.
The state machine consists of five registers. The address
register represents the instruction offset in the associated insns_item
in 16-bit code units. The address
register starts at 0
at the beginning of each debug_info
sequence and must only monotonically increase. The line
register represents what source line number should be associated with the next positions table entry emitted by the state machine. It is initialized in the sequence header, and may change in positive or negative directions but must never be less than 1
. The source_file
register represents the source file that the line number entries refer to. It is initialized to the value of source_file_idx
in class_def_item
. The other two variables, prologue_end
and epilogue_begin
, are boolean flags (initialized to false
) that indicate whether the next position emitted should be considered a method prologue or epilogue. The state machine must also track the name and type of the last local variable live in each register for the DBG_RESTART_LOCAL
code.
The header is as follows:
Name | Format | شرح |
---|---|---|
line_start | uleb128 | the initial value for the state machine's line register. Does not represent an actual positions entry. |
parameters_size | uleb128 | the number of parameter names that are encoded. There should be one per method parameter, excluding an instance method's this , if any. |
parameter_names | uleb128p1[parameters_size] | string index of the method parameter name. An encoded value of NO_INDEX indicates that no name is available for the associated parameter. The type descriptor and signature are implied from the method descriptor and signature. |
The byte code values are as follows:
Name | ارزش | Format | Arguments | شرح |
---|---|---|---|---|
DBG_END_SEQUENCE | 0x00 | (none) | terminates a debug info sequence for a code_item | |
DBG_ADVANCE_PC | 0x01 | uleb128 addr_diff | addr_diff : amount to add to address register | advances the address register without emitting a positions entry |
DBG_ADVANCE_LINE | 0x02 | sleb128 line_diff | line_diff : amount to change line register by | advances the line register without emitting a positions entry |
DBG_START_LOCAL | 0x03 | uleb128 register_num uleb128p1 name_idx uleb128p1 type_idx | register_num : register that will contain localname_idx : string index of the nametype_idx : type index of the type | introduces a local variable at the current address. Either name_idx or type_idx may be NO_INDEX to indicate that that value is unknown. |
DBG_START_LOCAL_EXTENDED | 0x04 | uleb128 register_num uleb128p1 name_idx uleb128p1 type_idx uleb128p1 sig_idx | register_num : register that will contain localname_idx : string index of the nametype_idx : type index of the typesig_idx : string index of the type signature | introduces a local with a type signature at the current address. Any of name_idx , type_idx , or sig_idx may be NO_INDEX to indicate that that value is unknown. (If sig_idx is -1 , though, the same data could be represented more efficiently using the opcode DBG_START_LOCAL .) Note: See the discussion under " |
DBG_END_LOCAL | 0x05 | uleb128 register_num | register_num : register that contained local | marks a currently-live local variable as out of scope at the current address |
DBG_RESTART_LOCAL | 0x06 | uleb128 register_num | register_num : register to restart | re-introduces a local variable at the current address. The name and type are the same as the last local that was live in the specified register. |
DBG_SET_PROLOGUE_END | 0x07 | (none) | sets the prologue_end state machine register, indicating that the next position entry that is added should be considered the end of a method prologue (an appropriate place for a method breakpoint). The prologue_end register is cleared by any special ( >= 0x0a ) opcode. | |
DBG_SET_EPILOGUE_BEGIN | 0x08 | (none) | sets the epilogue_begin state machine register, indicating that the next position entry that is added should be considered the beginning of a method epilogue (an appropriate place to suspend execution before method exit). The epilogue_begin register is cleared by any special ( >= 0x0a ) opcode. | |
DBG_SET_FILE | 0x09 | uleb128p1 name_idx | name_idx : string index of source file name; NO_INDEX if unknown | indicates that all subsequent line number entries make reference to this source file name, instead of the default name specified in code_item |
Special Opcodes | 0x0a…0xff | (none) | advances the line and address registers, emits a position entry, and clears prologue_end and epilogue_begin . See below for description. |
Special opcodes
Opcodes with values between 0x0a
and 0xff
(inclusive) move both the line
and address
registers by a small amount and then emit a new position table entry. The formula for the increments are as follows:
DBG_FIRST_SPECIAL = 0x0a // the smallest special opcode DBG_LINE_BASE = -4 // the smallest line number increment DBG_LINE_RANGE = 15 // the number of line increments represented adjusted_opcode = opcode - DBG_FIRST_SPECIAL line += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE) address += (adjusted_opcode / DBG_LINE_RANGE)
annotations_directory_item
referenced from class_def_item
appears in the data section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
class_annotations_off | uint | offset from the start of the file to the annotations made directly on the class, or 0 if the class has no direct annotations. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " annotation_set_item " below. |
fields_size | uint | count of fields annotated by this item |
annotated_methods_size | uint | count of methods annotated by this item |
annotated_parameters_size | uint | count of method parameter lists annotated by this item |
field_annotations | field_annotation[fields_size] (optional) | list of associated field annotations. The elements of the list must be sorted in increasing order, by field_idx . |
method_annotations | method_annotation[methods_size] (optional) | list of associated method annotations. The elements of the list must be sorted in increasing order, by method_idx . |
parameter_annotations | parameter_annotation[parameters_size] (optional) | list of associated method parameter annotations. The elements of the list must be sorted in increasing order, by method_idx . |
Note: All elements' field_id
s and method_id
s must refer to the same defining class.
field_annotation format
Name | Format | شرح |
---|---|---|
field_idx | uint | index into the field_ids list for the identity of the field being annotated |
annotations_off | uint | offset from the start of the file to the list of annotations for the field. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_item " below. |
method_annotation format
Name | Format | شرح |
---|---|---|
method_idx | uint | index into the method_ids list for the identity of the method being annotated |
annotations_off | uint | offset from the start of the file to the list of annotations for the method. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_item " below. |
parameter_annotation format
Name | Format | شرح |
---|---|---|
method_idx | uint | index into the method_ids list for the identity of the method whose parameters are being annotated |
annotations_off | uint | offset from the start of the file to the list of annotations for the method parameters. The offset should be to a location in the data section. The format of the data is specified by " annotation_set_ref_list " below. |
annotation_set_ref_list
referenced from parameter_annotations_item
appears in the data section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
size | uint | size of the list, in entries |
list | annotation_set_ref_item[size] | elements of the list |
annotation_set_ref_item format
Name | Format | شرح |
---|---|---|
annotations_off | uint | offset from the start of the file to the referenced annotation set or 0 if there are no annotations for this element. The offset, if non-zero, should be to a location in the data section. The format of the data is specified by " annotation_set_item " below. |
annotation_set_item
referenced from annotations_directory_item, field_annotations_item, method_annotations_item, and annotation_set_ref_item
appears in the data section
alignment: 4 bytes
Name | Format | شرح |
---|---|---|
size | uint | size of the set, in entries |
entries | annotation_off_item[size] | elements of the set. The elements must be sorted in increasing order, by type_idx . |
annotation_off_item format
Name | Format | شرح |
---|---|---|
annotation_off | uint | offset from the start of the file to an annotation. The offset should be to a location in the data section, and the format of the data at that location is specified by " annotation_item " below. |
annotation_item
referenced from annotation_set_item
appears in the data section
alignment: none (byte-aligned)
Name | Format | شرح |
---|---|---|
visibility | ubyte | intended visibility of this annotation (see below) |
annotation | encoded_annotation | encoded annotation contents, in the format described by " encoded_annotation format" under " encoded_value encoding" above. |
Visibility values
These are the options for the visibility
field in an annotation_item
:
Name | ارزش | شرح |
---|---|---|
VISIBILITY_BUILD | 0x00 | intended only to be visible at build time (eg, during compilation of other code) |
VISIBILITY_RUNTIME | 0x01 | intended to visible at runtime |
VISIBILITY_SYSTEM | 0x02 | intended to visible at runtime, but only to the underlying system (and not to regular user code) |
encoded_array_item
referenced from class_def_item
appears in the data section
alignment: none (byte-aligned)
Name | Format | شرح |
---|---|---|
value | encoded_array | bytes representing the encoded array value, in the format specified by " encoded_array Format" under " encoded_value Encoding" above. |
hiddenapi_class_data_item
This section contains data on restricted interfaces used by each class.
Note: The hidden API feature was introduced in Android 10.0 and is only applicable to the DEX files of classes in the boot class path. The list of flags described below may be extended in the future releases of Android. For more information, see restrictions on non-SDK interfaces .
Name | Format | شرح |
---|---|---|
size | uint | total size of the section |
offsets | uint[] | array of offsets indexed by class_idx . A zero array entry at index class_idx means that either there is no data for this class_idx , or all hidden API flags are zero. Otherwise the array entry is non-zero and contains an offset from the beginning of the section to an array of hidden API flags for this class_idx . |
flags | uleb128[] | concatenated arrays of hidden API flags for each class. Possible flag values are described in the table below. Flags are encoded in the same order as fields and methods are encoded in class data. |
Restriction flag types:
Name | ارزش | شرح |
---|---|---|
whitelist | 0 | Interfaces that can be freely used and are supported as part of the officially documented Android framework Package Index . |
greylist | 1 | Non-SDK interfaces that can be used regardless of the application's target API level . |
blacklist | 2 | Non-SDK interfaces that cannot be used regardless of the application's target API level . Accessing one of these interfaces causes a runtime error . |
greylist‑max‑o | 3 | Non-SDK interfaces that can be used for Android 8.x and below unless they are restricted. |
greylist‑max‑p | 4 | Non-SDK interfaces that can be used for Android 9.x unless they are restricted. |
greylist‑max‑q | 5 | Non-SDK interfaces that can be used for Android 10.x unless they are restricted. |
greylist‑max‑r | 6 | Non-SDK interfaces that can be used for Android 11.x unless they are restricted. |
System annotations
System annotations are used to represent various pieces of reflective information about classes (and methods and fields). This information is generally only accessed indirectly by client (non-system) code.
System annotations are represented in .dex
files as annotations with visibility set to VISIBILITY_SYSTEM
.
dalvik.annotation.AnnotationDefault
appears on methods in annotation interfaces
An AnnotationDefault
annotation is attached to each annotation interface which wishes to indicate default bindings.
Name | Format | شرح |
---|---|---|
value | Annotation | the default bindings for this annotation, represented as an annotation of this type. The annotation need not include all names defined by the annotation; missing names simply do not have defaults. |
dalvik.annotation.EnclosingClass
appears on classes
An EnclosingClass
annotation is attached to each class which is either defined as a member of another class, per se, or is anonymous but not defined within a method body (eg, a synthetic inner class). Every class that has this annotation must also have an InnerClass
annotation. Additionally, a class must not have both an EnclosingClass
and an EnclosingMethod
annotation.
Name | Format | شرح |
---|---|---|
value | Class | the class which most closely lexically scopes this class |
dalvik.annotation.EnclosingMethod
appears on classes
An EnclosingMethod
annotation is attached to each class which is defined inside a method body. Every class that has this annotation must also have an InnerClass
annotation. Additionally, a class must not have both an EnclosingClass
and an EnclosingMethod
annotation.
Name | Format | شرح |
---|---|---|
value | Method | the method which most closely lexically scopes this class |
dalvik.annotation.InnerClass
appears on classes
An InnerClass
annotation is attached to each class which is defined in the lexical scope of another class's definition. Any class which has this annotation must also have either an EnclosingClass
annotation or an EnclosingMethod
annotation.
Name | Format | شرح |
---|---|---|
name | String | the originally declared simple name of this class (not including any package prefix). If this class is anonymous, then the name is null . |
accessFlags | int | the originally declared access flags of the class (which may differ from the effective flags because of a mismatch between the execution models of the source language and target virtual machine) |
dalvik.annotation.MemberClasses
appears on classes
A MemberClasses
annotation is attached to each class which declares member classes. (A member class is a direct inner class that has a name.)
Name | Format | شرح |
---|---|---|
value | Class[] | array of the member classes |
dalvik.annotation.MethodParameters
appears on methods
Note: This annotation was added after Android 7.1. Its presence on earlier Android releases will be ignored.
A MethodParameters
annotation is optional and can be used to provide parameter metadata such as parameter names and modifiers.
The annotation can be omitted from a method or constructor safely when the parameter metadata is not required at runtime. java.lang.reflect.Parameter.isNamePresent()
can be used to check whether metadata is present for a parameter, and the associated reflection methods such as java.lang.reflect.Parameter.getName()
will fall back to default behavior at runtime if the information is not present.
When including parameter metadata, compilers must include information for generated classes such as enums, since the parameter metadata includes whether or not a parameter is synthetic or mandated.
A MethodParameters
annotation describes only individual method parameters. Therefore, compilers may omit the annotation entirely for constructors and methods that have no parameters, for the sake of code-size and runtime efficiency.
The arrays documented below must be the same size as for the method_id_item
dex structure associated with the method, otherwise a java.lang.reflect.MalformedParametersException
will be thrown at runtime.
That is: method_id_item.proto_idx
-> proto_id_item.parameters_off
-> type_list.size
must be the same as names().length
and accessFlags().length
.
Because MethodParameters
describes all formal method parameters, even those not explicitly or implicitly declared in source code, the size of the arrays may differ from the Signature or other metadata information that is based only on explicit parameters declared in source code. MethodParameters
will also not include any information about type annotation receiver parameters that do not exist in the actual method signature.
Name | Format | شرح |
---|---|---|
names | String[] | The names of formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. A value in the array must be null if the formal parameter with that index has no name. If parameter name strings are empty or contain '.', ';', '[' or '/' then a java.lang.reflect.MalformedParametersException will be thrown at runtime. |
accessFlags | int[] | The access flags of the formal parameters for the associated method. The array must not be null but must be empty if there are no formal parameters. The value is a bit mask with the following values:
java.lang.reflect.MalformedParametersException will be thrown at runtime. |
dalvik.annotation.Signature
appears on classes, fields, and methods
A Signature
annotation is attached to each class, field, or method which is defined in terms of a more complicated type than is representable by a type_id_item
. The .dex
format does not define the format for signatures; it is merely meant to be able to represent whatever signatures a source language requires for successful implementation of that language's semantics. As such, signatures are not generally parsed (or verified) by virtual machine implementations. The signatures simply get handed off to higher-level APIs and tools (such as debuggers). Any use of a signature, therefore, should be written so as not to make any assumptions about only receiving valid signatures, explicitly guarding itself against the possibility of coming across a syntactically invalid signature.
Because signature strings tend to have a lot of duplicated content, a Signature
annotation is defined as an array of strings, where duplicated elements naturally refer to the same underlying data, and the signature is taken to be the concatenation of all the strings in the array. There are no rules about how to pull apart a signature into separate strings; that is entirely up to the tools that generate .dex
files.
Name | Format | شرح |
---|---|---|
value | String[] | the signature of this class or member, as an array of strings that is to be concatenated together |
dalvik.annotation.Throws
appears on methods
A Throws
annotation is attached to each method which is declared to throw one or more exception types.
Name | Format | شرح |
---|---|---|
value | Class[] | the array of exception types thrown |