يصف هذا المستند تخطيط ومحتويات ملفات .dex
، والتي تُستخدم للاحتفاظ بمجموعة من تعريفات الفئات والبيانات الملحقة المرتبطة بها.
دليل لأنواع
اسم | وصف |
---|---|
بايت | 8 بت توقيع عدد صحيح |
ubyte | 8 بت عدد صحيح غير موقعة |
قصيرة | 16 بت توقيع int ، صغير endian |
قريب | عدد 16 بت غير موقعة ، قليل النهاية |
int | كثافة العمليات 32 بت ، القليل من endian |
uint | كثافة العمليات 32 بت غير موقعة ، القليل من endian |
طويل | كثافة العمليات 64 بت ، القليل من endian |
أولونغ | كثافة العمليات 64 بت ، القليل من endian |
سليب 128 | توقيع 128 جنيهًا مصريًا ، متغير الطول (انظر أدناه) |
uleb128 | 128 LEB غير موقعة ، متغيرة الطول (انظر أدناه) |
uleb128p1 | 128 جنيهًا مصريًا غير موقعة بالإضافة إلى 1 ، متغير الطول (انظر أدناه) |
جنيه 128
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_id_item [] | قائمة معرفات الحقول. هذه هي معرفات لجميع الحقول التي يشير إليها هذا الملف ، سواء تم تعريفها في الملف أم لا. يجب فرز هذه القائمة ، حيث يكون نوع التعريف (حسب فهرس type_id ) هو الترتيب الرئيسي ، ويكون اسم الحقل (حسب فهرس string_id ) هو الترتيب المتوسط ، والنوع (حسب type_id index) هو الترتيب الثانوي. يجب ألا تحتوي القائمة على أي إدخالات مكررة. |
طريقة_الإرشادات | طريقة_ معرّف_عنصر [] | قائمة معرفات الطريقة. هذه هي معرفات لجميع الطرق التي يشير إليها هذا الملف ، سواء تم تعريفها في الملف أم لا. يجب فرز هذه القائمة ، حيث يكون نوع التعريف (حسب فهرس type_id ) هو الترتيب الرئيسي ، واسم الطريقة (حسب مؤشر string_id ) هو الترتيب المتوسط ، والنموذج الأولي للطريقة (بواسطة فهرس proto_id ) هو الترتيب الثانوي. يجب ألا تحتوي القائمة على أي إدخالات مكررة. |
class_defs | class_def_item [] | قائمة تعريفات الفصل. يجب ترتيب الفئات بحيث تظهر الطبقة الفائقة والواجهات المنفذة لفئة معينة في القائمة قبل فئة الإحالة. علاوة على ذلك ، من غير الصحيح أن يظهر تعريف للفئة التي تحمل نفس الاسم أكثر من مرة في القائمة. |
call_site_ids | call_site_id_item [] | قائمة معرفات موقع الاتصال. هذه هي معرفات لجميع مواقع الاتصال المشار إليها بواسطة هذا الملف ، سواء تم تعريفها في الملف أم لا. يجب فرز هذه القائمة بترتيب تصاعدي من call_site_off . |
طريقة_مقابض | طريقة_معامل_عنصر [] | طريقة مقابض القائمة. قائمة بكل معالجات الطريقة المشار إليها بواسطة هذا الملف ، سواء تم تعريفها في الملف أم لا. لم يتم فرز هذه القائمة وقد تحتوي على تكرارات تتوافق منطقيًا مع مثيلات معالجة طريقة مختلفة. |
بيانات | ubyte [] | منطقة البيانات ، التي تحتوي على جميع بيانات الدعم للجداول المذكورة أعلاه. العناصر المختلفة لها متطلبات محاذاة مختلفة ، ويتم إدخال وحدات البايت المتروكة قبل كل عنصر إذا لزم الأمر لتحقيق المحاذاة المناسبة. |
link_data | ubyte [] | البيانات المستخدمة في الملفات المرتبطة بشكل ثابت. يتم ترك تنسيق البيانات في هذا القسم غير محدد في هذا المستند. هذا القسم فارغ في الملفات غير المرتبطة ، وقد تستخدمه تطبيقات وقت التشغيل بالشكل الذي تراه مناسبًا. |
Bitfield ، سلسلة وتعريفات ثابتة
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
من التنسيق في إصدار Android 9.0 ، والذي قدم اثنين من الرموز البايت الجديدة ، و const-method-handle
و const-method-type
. (تم وصف كل من هذه في ملخص جدول مجموعة الرموز الثنائية .) في Android 10 ، يوسع الإصدار 039
تنسيق ملف DEX ليشمل معلومات API المخفية التي تنطبق فقط على ملفات DEX على مسار فئة التمهيد.
ملاحظة: تمت إضافة دعم الإصدار 038
من التنسيق في إصدار Android 8.0. أضاف الإصدار 038
أكواد بايت جديدة ( invoke-polymorphic
invoke-custom
) وبيانات لمقابض الطريقة.
ملاحظة: تمت إضافة دعم الإصدار 037
من التنسيق في إصدار Android 7.0. قبل الإصدار 037
، استخدمت معظم إصدارات Android الإصدار 035
من التنسيق. الاختلاف الوحيد بين الإصدارين 035
و 037
هو إضافة الطرق الافتراضية وضبط invoke
.
ملاحظة: تم استخدام نسختين أقدمتين على الأقل من التنسيق في إصدارات البرامج العامة المتاحة على نطاق واسع. على سبيل المثال ، تم استخدام الإصدار 009
لإصدارات M3 لمنصة Android (نوفمبر - ديسمبر 2007) ، وتم استخدام الإصدار 013
لإصدارات M5 من نظام Android الأساسي (فبراير - مارس 2008). من نواحٍ عديدة ، تختلف هذه الإصدارات السابقة من التنسيق بشكل كبير عن الإصدار الموضح في هذا المستند.
ENDIAN_CONSTANT و REVERSE_ENDIAN_CONSTANT
مضمن في header_item
يتم استخدام الثابت ENDIAN_CONSTANT
للإشارة إلى نهاية الملف الذي تم العثور عليه فيه. على الرغم من أن تنسيق .dex
القياسي ضئيل للغاية ، إلا أن التطبيقات قد تختار إجراء تبديل البايت. إذا ظهر تنفيذ عبر رأس يكون endian_tag
هو REVERSE_ENDIAN_CONSTANT
بدلاً من ENDIAN_CONSTANT
، فسيعلم أنه تم تبديل الملف بالبايت من النموذج المتوقع.
uint ENDIAN_CONSTANT = 0x12345678; uint REVERSE_ENDIAN_CONSTANT = 0x78563412;
NO_INDEX
مضمن في class_def_item و debug_info_item
يتم استخدام الثابت NO_INDEX
للإشارة إلى عدم وجود قيمة مؤشر.
ملاحظة: لم يتم تعريف هذه القيمة على أنها 0
، لأن هذا في الواقع عادة ما يكون فهرسًا صالحًا.
يمكن تمثيل القيمة المختارة لـ NO_INDEX
واحد في تشفير uleb128p1
.
uint NO_INDEX = 0xffffffff; // == -1 if treated as a signed int
تعريفات access_flags
مضمن في class_def_item و encoded_field و encoded_method و InnerClass
يتم استخدام Bitfields من هذه العلامات للإشارة إلى إمكانية الوصول والخصائص العامة للفئات وأعضاء الفصل.
اسم | قيمة | للفئات (وشروح 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 | طريقة الجسر ، المضافة تلقائيًا بواسطة المترجم كجسر من النوع الآمن | ||
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 ، بدلاً من كونه تنسيق ترميز مباشر أكثر لأحرف Unicode.
يتيح العنصران الأخيران أعلاه إمكانية تضمين نقطة الرمز U+0000
في سلسلة في نفس الوقت ومعالجتها كسلسلة منتهية بقيمة خالية من النمط C.
ومع ذلك ، فإن الترميز الخاص لـ U+0000
يعني أنه ، على عكس UTF-8 العادي ، فإن نتيجة استدعاء دالة C القياسية strcmp()
على زوج من سلاسل MUTF-8 لا تشير دائمًا إلى النتيجة الموقعة بشكل صحيح لمقارنة السلاسل غير المتكافئة . عندما يكون الترتيب (وليس المساواة فقط) مصدر قلق ، فإن الطريقة الأكثر مباشرة لمقارنة سلاسل MUTF-8 هي فك تشفيرها حرفًا بحرف ، ومقارنة القيم التي تم فك تشفيرها. (ومع ذلك ، من الممكن أيضًا استخدام تطبيقات أكثر ذكاءً).
يرجى الرجوع إلى معيار Unicode للحصول على مزيد من المعلومات حول ترميز الأحرف. يعد MUTF-8 أقرب إلى ترميز CESU-8 (الأقل شهرة نسبيًا) منه إلى UTF-8 في حد ذاته.
encoded_value ترميز
مضمن في annotation_element و encoded_array_item
encoded_value
هي قطعة مشفرة من (تقريبًا) بيانات منظمة بشكل هرمي عشوائية. من المفترض أن يكون الترميز مضغوطًا ومباشرًا لتحليله.
اسم | شكل | وصف |
---|---|---|
(القيمة_العربية << 5) | نوع القيمة | ubyte | بايت يشير إلى نوع value اللاحقة مباشرة إلى جانب وسيطة توضيح اختيارية في البتات الثلاثة عالية الترتيب. انظر أدناه للحصول على تعريفات value المختلفة. في معظم الحالات ، value_arg بترميز طول value اللاحقة مباشرة بالبايت ، مثل (size - 1) ، على سبيل المثال ، 0 تعني أن القيمة تتطلب بايتًا واحدًا ، و 7 تعني أنها تتطلب ثمانية بايت ؛ ومع ذلك ، هناك استثناءات كما هو مذكور أدناه. |
القيمة | ubyte [] | بايت تمثل القيمة ، متغير في الطول ويتم تفسيرها بشكل مختلف value_type من نوع value_type مختلفة ، على الرغم من أنها دائمًا صغيرة. راجع تعريفات القيمة المختلفة أدناه للحصول على التفاصيل. |
تنسيقات القيمة
أكتب اسم | value_type | تنسيق value_arg | تنسيق value | وصف |
---|---|---|---|---|
VALUE_BYTE | 0x00 | (بلا ؛ يجب أن يكون 0 ) | ubyte [1] | قيمة عدد صحيح واحد بايت |
VALUE_SHORT | 0x02 | الحجم - 1 (0 ... 1) | ubyte [الحجم] | قيمة عدد صحيح ثنائي البايت موقعة ، موسعة بتوقيع |
VALUE_CHAR | 0x03 | الحجم - 1 (0 ... 1) | ubyte [الحجم] | قيمة عدد صحيح ثنائي البايت بدون إشارة ، صفر ممتد |
VALUE_INT | 0x04 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح بأربعة بايت موقعة ، موسعة بتوقيع |
VALUE_LONG | 0x06 | الحجم - 1 (0 ... 7) | ubyte [الحجم] | قيمة عدد صحيح ثمانية بايت ، علامة موسعة |
VALUE_FLOAT | 0x10 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | نمط بت رباعي البايت ، ممتد صفراً إلى اليمين ، ويتم تفسيره على أنه قيمة فاصلة عائمة 32 بت IEEE754 |
VALUE_DOUBLE | 0x11 | الحجم - 1 (0 ... 7) | ubyte [الحجم] | نمط بت ثمانية بايت ، ممتد صفراً إلى اليمين ، ويتم تفسيره على أنه قيمة فاصلة عائمة 64 بت IEEE754 |
VALUE_METHOD_TYPE | 0x15 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، يتم تفسيرها على أنها فهرس في قسم proto_ids وتمثل قيمة نوع الطريقة |
VALUE_METHOD_HANDLE | 0x16 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، تُفسَّر على أنها فهرس في قسم method_handles الطريقة وتمثل قيمة مقبض الأسلوب |
VALUE_STRING | 0x17 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، تُفسَّر على أنها فهرس في قسم string_ids وتمثل قيمة سلسلة |
VALUE_TYPE | 0x18 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، تُفسَّر على أنها فهرس في قسم type_ids وتمثل قيمة نوع / فئة عاكسة |
VALUE_FIELD | 0x19 | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، يتم تفسيرها على أنها فهرس في قسم field_ids وتمثل قيمة حقل عاكس |
VALUE_METHOD | 0x1a | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، تُفسَّر على أنها فهرس في قسم method_ids وتمثل قيمة طريقة عاكسة |
VALUE_ENUM | 0x1b | الحجم - 1 (0 ... 3) | ubyte [الحجم] | قيمة عدد صحيح رباعي البايت بدون إشارة (ممتدة صفريًا) ، يتم تفسيرها على أنها فهرس في قسم field_ids وتمثل قيمة ثابت من النوع المعدَّد |
VALUE_ARRAY | 0x1c | (بلا ؛ يجب أن يكون 0 ) | encoded_array | مصفوفة من القيم بالتنسيق المحدد بواسطة "تنسيق encoded_array " أدناه. حجم value ضمني في الترميز. |
VALUE_ANNOTATION | 0x1d | (بلا ؛ يجب أن يكون 0 ) | التشفير | شرح فرعي ، بالتنسيق المحدد بواسطة "تنسيق encoded_annotation " أدناه. حجم value ضمني في الترميز. |
VALUE_NULL | 0x1e | (بلا ؛ يجب أن يكون 0 ) | (لا أحد) | قيمة مرجعية null |
VALUE_BOOLEAN | 0x1f | قيمة منطقية (0 ... 1) | (لا أحد) | قيمة بت واحد 0 true و 1 false . يتم تمثيل البتة في value_arg . |
encoded_array
اسم | شكل | وصف |
---|---|---|
بحجم | uleb128 | عدد العناصر في المصفوفة |
القيم | encoded_value [الحجم] | سلسلة من متواليات بايت size encoded_value في النسق المحدد في هذا القسم ، متسلسلة بالتتابع. |
encoded_annotation تنسيق
اسم | شكل | وصف |
---|---|---|
type_idx | uleb128 | نوع التعليق التوضيحي. يجب أن يكون هذا نوع فئة (وليس مصفوفة أو بدائي). |
بحجم | uleb128 | عدد عمليات تعيين الاسم والقيمة في هذا التعليق التوضيحي |
عناصر | anotation_element [الحجم] | عناصر التعليق التوضيحي ، ممثلة مباشرة في الخط (وليس كتعويضات). يجب فرز العناصر بترتيب تصاعدي حسب فهرس string_id . |
anotation_element format
اسم | شكل | وصف |
---|---|---|
name_idx | uleb128 | يتم تمثيل اسم العنصر كفهرس في قسم string_ids . يجب أن تتوافق السلسلة مع بناء جملة MemberName الموضح أعلاه. |
القيمة | encoded_value | قيمة العنصر |
بناء جملة السلسلة
هناك عدة أنواع من العناصر في ملف .dex
والتي تشير في النهاية إلى سلسلة. تشير تعريفات نمط BNF التالية إلى الصيغة المقبولة لهذه السلاسل.
SimpleName
إن SimpleName هو الأساس لبناء جملة أسماء الأشياء الأخرى. يسمح تنسيق .dex
بقدر معقول من خطوط العرض هنا (أكثر بكثير من معظم لغات المصدر الشائعة). باختصار ، يتكون الاسم البسيط من أي حرف أبجدي أو رقم أبجدي منخفض ASCII ، وعدد قليل من رموز ASCII المنخفضة ، ومعظم نقاط الرموز غير ASCII التي ليست تحكم أو مسافة أو أحرف خاصة. بدءًا من الإصدار 040
، يسمح التنسيق بالإضافة إلى ذلك بأحرف المسافات (فئة Unicode Zs
). لاحظ أن نقاط الشفرة البديلة (في النطاق U+d800
+ d800… U+dfff
) لا تعتبر أحرف اسم صالحة ، في حد ذاتها ، ولكن أحرف Unicode التكميلية صالحة (والتي يتم تمثيلها بواسطة البديل النهائي لقاعدة 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
اسم العضو هو اسم عضو في الفصل ، والأعضاء عبارة عن حقول وأساليب وفئات داخلية.
اسم العضو → | |
SimpleName | |
| | '<' SimpleName '>' |
FullClassName
FullClassName هو اسم فئة مؤهل بالكامل ، بما في ذلك محدد حزمة اختياري متبوعًا باسم مطلوب.
FullClassName → | |
OptionalPackagePrefix SimpleName | |
OptionalPackagePrefix → | |
( SimpleName '/' ) * |
النوع
المستخدمة من قبل type_id_item
يعد TypeDescriptor تمثيلًا لأي نوع ، بما في ذلك العناصر الأولية والفئات والمصفوفات void
. انظر أدناه لمعرفة معنى الإصدارات المختلفة.
اكتب واصف → | |
'V' | |
| | نوع الحقل |
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 → | |
'Z' | |
| | 'B' |
| | 'S' |
| | 'C' |
| | 'I' |
| | 'J' |
| | 'F' |
| | 'D' |
| | 'L' |
TypeDescriptor Semantics
هذا هو معنى كل من متغيرات TypeDescriptor .
بناء الجملة | المعنى |
---|---|
الخامس | void . صالحة فقط لأنواع الإرجاع |
ض | boolean |
ب | byte |
س | short |
ج | char |
أنا | int |
ي | long |
F | float |
د | double |
L بالكامل / مؤهل / اسم ؛ | الصنف fully.qualified.Name |
[ واصف | مصفوفة من descriptor ، قابلة للاستخدام بشكل متكرر لمصفوفات المصفوفات ، على الرغم من أنه من غير الصحيح أن تحتوي على أكثر من 255 بُعدًا. |
العناصر والهياكل ذات الصلة
يتضمن هذا القسم تعريفات لكل عنصر من عناصر المستوى الأعلى التي قد تظهر في ملف .dex
.
header_item
يظهر في قسم الرأس
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
سحر | ubyte [8] = DEX_FILE_MAGIC | قيمة سحرية. راجع المناقشة أعلاه ضمن " DEX_FILE_MAGIC " للحصول على مزيد من التفاصيل. |
اختباري | uint | adler32 المجموع الاختباري لبقية الملف (كل شيء ما عدا magic وهذا المجال) ؛ تستخدم لاكتشاف تلف الملف |
التوقيع | يوبيت [20] | توقيع SHA-1 (تجزئة) لبقية الملف (كل شيء ما عدا magic ، checksum ، وهذا الحقل) ؛ تستخدم لتعريف الملفات بشكل فريد |
حجم الملف | uint | حجم الملف بأكمله (بما في ذلك الرأس) بالبايت |
header_size | uint = 0x70 | حجم الرأس (هذا القسم بأكمله) بالبايت. يسمح هذا بكمية محدودة على الأقل من التوافق مع الإصدارات السابقة / إلى الأمام دون إبطال التنسيق. |
endian_tag | uint = ENDIAN_CONSTANT | علامة endianness. راجع المناقشة أعلاه ضمن " ENDIAN_CONSTANT و REVERSE_ENDIAN_CONSTANT " للحصول على مزيد من التفاصيل. |
link_size | uint | حجم قسم الارتباط ، أو 0 إذا لم يكن هذا الملف مرتبطًا بشكل ثابت |
link_off | uint | الإزاحة من بداية الملف إلى قسم الارتباط ، أو 0 إذا كان link_size == 0 . الإزاحة ، إذا كانت غير صفرية ، يجب أن تكون معادلة في قسم link_data . يتم ترك تنسيق البيانات المشار إليها غير محدد في هذه الوثيقة ؛ يتم ترك حقل الرأس هذا (والحقل السابق) كخطافات للاستخدام بواسطة تطبيقات وقت التشغيل. |
map_off | uint | الإزاحة من بداية الملف إلى عنصر الخريطة. يجب أن تكون الإزاحة ، التي يجب أن تكون غير صفرية ، معادلة في قسم data ، ويجب أن تكون البيانات بالتنسيق المحدد بواسطة " map_list " أدناه. |
string_ids_size | uint | عدد السلاسل في قائمة معرفات السلاسل |
string_ids_off | uint | الإزاحة من بداية الملف إلى قائمة معرفات السلسلة ، أو 0 إذا كانت string_ids_size == 0 (من المسلم به أنها حالة حافة غريبة). يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم string_ids . |
type_ids_size | uint | عدد العناصر في قائمة معرفات النوع ، بحد أقصى 65535 |
type_ids_off | uint | الإزاحة من بداية الملف إلى قائمة معرفات النوع ، أو 0 إذا كانت type_ids_size == 0 (من المسلم به أنها حالة حافة غريبة). يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم type_ids . |
proto_ids_size | uint | عدد العناصر في قائمة معرفات النموذج الأولي ، على الأكثر 65535 |
proto_ids_off | uint | الإزاحة من بداية الملف إلى قائمة معرفات النموذج الأولي ، أو 0 إذا كانت proto_ids_size == 0 (من المسلم به أنها حالة حافة غريبة). يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم proto_ids . |
field_ids_size | uint | عدد العناصر في قائمة معرفات الحقول |
field_ids_off | uint | الإزاحة من بداية الملف إلى قائمة معرفات الحقول ، أو 0 إذا كان field_ids_size == 0 . يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم field_ids . |
طريقة_تعريف_حجم | uint | عدد العناصر في قائمة معرفات الطريقة |
طريقة_تعريف_الخارج | uint | الإزاحة من بداية الملف إلى قائمة معرفات الطريقة ، أو 0 إذا كان method_ids_size == 0 . يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم method_ids . |
class_defs_size | uint | عدد العناصر في قائمة تعريفات الفئات |
class_defs_off | uint | الإزاحة من بداية الملف إلى قائمة تعريفات الفئات ، أو 0 إذا كانت class_defs_size == 0 (من المسلم به أنها حالة حافة غريبة). يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في بداية قسم class_defs . |
حجم البيانات | uint | حجم قسم data بالبايت. يجب أن يكون مضاعفًا لـ sizeof (uint). |
data_off | uint | الإزاحة من بداية الملف إلى بداية قسم data . |
map_list
يظهر في قسم البيانات
مشار إليه من header_item
المحاذاة: 4 بايت
هذه قائمة بكامل محتويات الملف ، بالترتيب. يحتوي على بعض التكرار فيما يتعلق بـ header_item
ولكن الغرض منه أن يكون نموذجًا سهل الاستخدام للتكرار على ملف بأكمله. يجب أن يظهر نوع معين مرة واحدة على الأكثر في الخريطة ، ولكن لا توجد قيود على أنواع الطلبات التي قد تظهر فيها ، بخلاف القيود التي تتضمنها بقية التنسيق (على سبيل المثال ، يجب أن يظهر قسم header
أولاً ، متبوعًا بـ string_ids
القسم ، وما إلى ذلك). بالإضافة إلى ذلك ، يجب ترتيب إدخالات الخريطة عن طريق الإزاحة الأولية ويجب ألا تتداخل.
اسم | شكل | وصف |
---|---|---|
بحجم | uint | حجم القائمة في الإدخالات |
قائمة | map_item [الحجم] | عناصر القائمة |
تنسيق map_item
اسم | شكل | وصف |
---|---|---|
يكتب | قريب | نوع العناصر انظر الجدول أدناه |
غير مستعمل | قريب | (غير مستعمل) |
بحجم | uint | حساب عدد العناصر التي يمكن العثور عليها في الإزاحة المشار إليها |
عوض | uint | الإزاحة من بداية الملف إلى العناصر المعنية |
اكتب الرموز
نوع العنصر | مستمر | قيمة | حجم العنصر بالبايت |
---|---|---|---|
header_item | TYPE_HEADER_ITEM | 0x0000 | 0x70 |
string_id_item | TYPE_STRING_ID_ITEM | 0x0001 | 0x04 |
type_id_item | TYPE_TYPE_ID_ITEM | 0x0002 | 0x04 |
proto_id_item | TYPE_PROTO_ID_ITEM | 0x0003 | 0x0c |
field_id_item | TYPE_FIELD_ID_ITEM | 0x0004 | 0x08 |
طريقة_ معرّف_عنصر | 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 |
طريقة_معامل_عنصر | 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 | ضمني يجب أن يحلل |
كود_عنصر | TYPE_CODE_ITEM | 0x2001 | ضمني يجب أن يحلل |
string_data_item | TYPE_STRING_DATA_ITEM | 0x2002 | ضمني يجب أن يحلل |
debug_info_item | TYPE_DEBUG_INFO_ITEM | 0x2003 | ضمني يجب أن يحلل |
شرح_البند | TYPE_ANNOTATION_ITEM | 0x2004 | ضمني يجب أن يحلل |
encoded_array_item | TYPE_ENCODED_ARRAY_ITEM | 0x2005 | ضمني يجب أن يحلل |
التعليقات التوضيحية_دليل_البند | TYPE_ANNOTATIONS_DIRECTORY_ITEM | 0x2006 | ضمني يجب أن يحلل |
hiddenapi_class_data_item | TYPE_HIDDENAPI_CLASS_DATA_ITEM | 0xF000 | ضمني يجب أن يحلل |
string_id_item
يظهر في قسم string_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
string_data_off | uint | الإزاحة من بداية الملف إلى بيانات السلسلة لهذا العنصر. يجب أن تكون الإزاحة لموقع في قسم data ، ويجب أن تكون البيانات بالتنسيق المحدد بواسطة " string_data_item " أدناه. لا توجد متطلبات محاذاة للإزاحة. |
string_data_item
يظهر في قسم البيانات
المحاذاة: لا شيء (محاذاة البايت)
اسم | شكل | وصف |
---|---|---|
utf16_size | uleb128 | حجم هذه السلسلة ، بوحدات كود UTF-16 (وهو "طول السلسلة" في العديد من الأنظمة). وهذا يعني أن هذا هو طول السلسلة التي تم فك تشفيرها. (يشير الطول المشفر إلى موضع البايت 0 ). |
بيانات | ubyte [] | سلسلة من وحدات كود MUTF-8 (تُعرف أيضًا باسم ثماني بتات ، وتعرف أيضًا بالبايتات) متبوعة ببايت بقيمة 0 . راجع "ترميز MUTF-8 (UTF-8 المعدل)" أعلاه للحصول على تفاصيل ومناقشة حول تنسيق البيانات. ملاحظة: من المقبول أن يكون لديك سلسلة تتضمن (الصيغة المشفرة) UTF-16 وحدات الشفرة البديلة (أي |
type_id_item
يظهر في قسم type_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
descriptor_idx | uint | index في قائمة string_ids لسلسلة الوصف من هذا النوع. يجب أن تتوافق السلسلة مع بناء جملة TypeDescriptor المحدد أعلاه. |
proto_id_item
يظهر في قسم proto_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
shorty_idx | uint | index في قائمة string_ids لسلسلة واصف النموذج القصير لهذا النموذج الأولي. يجب أن تتوافق السلسلة مع بناء جملة ShortyDescriptor المحدد أعلاه ، ويجب أن تتوافق مع نوع الإرجاع ومعلمات هذا العنصر. |
return_type_idx | uint | index في قائمة type_ids لنوع الإرجاع لهذا النموذج الأولي |
المعلمات_إيقاف | uint | الإزاحة من بداية الملف إلى قائمة أنواع المعلمات لهذا النموذج الأولي ، أو 0 إذا كان هذا النموذج الأولي لا يحتوي على معلمات. يجب أن تكون هذه الإزاحة ، إذا لم تكن صفرية ، في قسم data ، ويجب أن تكون البيانات هناك بالتنسيق المحدد بواسطة "type_list" أدناه. بالإضافة إلى ذلك ، يجب ألا يكون هناك أي إشارة إلى نوع void في القائمة. |
field_id_item
يظهر في قسم field_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
class_idx | قريب | الفهرس في قائمة type_ids لمُعرّف هذا الحقل. يجب أن يكون هذا نوع فئة وليس مصفوفة أو نوعًا أوليًا. |
type_idx | قريب | فهرس في قائمة type_ids لنوع هذا الحقل |
name_idx | uint | الفهرس في قائمة string_ids لاسم هذا الحقل. يجب أن تتوافق السلسلة مع بناء جملة MemberName الموضح أعلاه. |
طريقة_ معرّف_عنصر
يظهر في قسم method_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
class_idx | قريب | فهرس في قائمة type_ids لمحدد هذه الطريقة. يجب أن يكون هذا فئة أو نوع مصفوفة ، وليس نوعًا أوليًا. |
proto_idx | قريب | فهرس في قائمة proto_ids للنموذج الأولي لهذه الطريقة |
name_idx | uint | فهرس في قائمة string_ids لاسم هذه الطريقة. يجب أن تتوافق السلسلة مع بناء جملة MemberName الموضح أعلاه. |
class_def_item
يظهر في قسم class_defs
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
class_idx | uint | index في قائمة type_ids لهذه الفئة. يجب أن يكون هذا نوع فئة وليس مصفوفة أو نوعًا أوليًا. |
access_flags | uint | أعلام الوصول للفصل ( public ، final ، إلخ). راجع "تعريفات access_flags " للحصول على التفاصيل. |
superclass_idx | uint | الفهرس في قائمة type_ids الفائقة ، أو القيمة الثابتة NO_INDEX إذا لم يكن لهذه الفئة فئة فائقة (أي أنها فئة جذر مثل Object ). إذا كان موجودًا ، يجب أن يكون نوع فئة وليس مصفوفة أو نوعًا أوليًا. |
واجهات_من | uint | الإزاحة من بداية الملف إلى قائمة الواجهات ، أو 0 إذا لم يكن هناك أي واجهات. يجب أن تكون هذه الإزاحة في قسم data ، ويجب أن تكون البيانات هناك بالتنسيق المحدد بواسطة " type_list " أدناه. يجب أن يكون كل عنصر من عناصر القائمة من نوع فئة (وليس مصفوفة أو نوعًا أوليًا) ، ويجب ألا يكون هناك أي تكرارات. |
source_file_idx | uint | index في قائمة string_ids لاسم الملف الذي يحتوي على المصدر الأصلي (على الأقل لمعظم) هذه الفئة ، أو القيمة الخاصة NO_INDEX لتمثيل نقص في هذه المعلومات. قد يتجاوز ملف debug_info_item لأي طريقة ملف المصدر هذا ، ولكن التوقع هو أن معظم الفئات ستأتي فقط من ملف مصدر واحد. |
التعليقات التوضيحية | uint | الإزاحة من بداية الملف إلى بنية التعليقات التوضيحية لهذه الفئة ، أو 0 إذا لم تكن هناك تعليقات توضيحية في هذه الفئة. يجب أن تكون هذه الإزاحة ، إذا لم تكن صفرية ، في قسم data ، ويجب أن تكون البيانات هناك بالتنسيق المحدد بواسطة " annotations_directory_item " أدناه ، مع جميع العناصر التي تشير إلى هذه الفئة على أنها التعريف. |
class_data_off | uint | الإزاحة من بداية الملف إلى بيانات الفئة المرتبطة لهذا العنصر ، أو 0 إذا لم تكن هناك بيانات فئة لهذه الفئة. (قد يكون هذا هو الحال ، على سبيل المثال ، إذا كانت هذه الفئة عبارة عن واجهة علامة.) يجب أن تكون الإزاحة ، إذا لم تكن صفرية ، في قسم data ، ويجب أن تكون البيانات بالتنسيق المحدد بواسطة " class_data_item " أدناه ، مع جميع العناصر التي تشير إلى هذه الفئة على أنها المحدد. |
static_values_off. قيمة ثابتة | uint | الإزاحة من بداية الملف إلى قائمة القيم الأولية للحقول static ، أو 0 إذا لم يكن هناك أي منها (ويجب تهيئة جميع الحقول static بـ 0 أو null ). يجب أن يكون هذا الإزاحة في قسم data ، ويجب أن تكون البيانات هناك بالتنسيق المحدد بواسطة " encoded_array_item " أدناه. يجب ألا يكون حجم المصفوفة أكبر من عدد الحقول static المُعلنة بواسطة هذه الفئة ، والعناصر تتوافق مع الحقول static بنفس الترتيب المُعلن عنها في field_list المقابل. يجب أن يتطابق نوع كل عنصر مصفوفة مع النوع المعلن للحقل المقابل له. إذا كان هناك عدد أقل من العناصر في المصفوفة من الحقول static ، فسيتم تهيئة الحقول المتبقية باستخدام القيمة المناسبة للنوع 0 أو القيمة null . |
call_site_id_item
يظهر في قسم call_site_ids
المحاذاة: 4 بايت
اسم | شكل | وصف |
---|---|---|
call_site_off | uint | الإزاحة من بداية الملف لاستدعاء تعريف الموقع. يجب أن تكون الإزاحة في قسم البيانات ، ويجب أن تكون البيانات هناك بالتنسيق المحدد بواسطة "call_site_item" أدناه. |
call_site_item
يظهر في قسم البيانات
المحاذاة: لا شيء (محاذاة بايت)
إن call_site_item عبارة عن 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 | Value | وصف |
---|---|---|
METHOD_HANDLE_TYPE_STATIC_PUT | 0x00 | Method handle is a static field setter (accessor) |
METHOD_HANDLE_TYPE_STATIC_GET | 0x01 | Method handle is a static field getter (accessor) |
METHOD_HANDLE_TYPE_INSTANCE_PUT | 0x02 | Method handle is an instance field setter (accessor) |
METHOD_HANDLE_TYPE_INSTANCE_GET | 0x03 | Method handle is an instance field getter (accessor) |
METHOD_HANDLE_TYPE_INVOKE_STATIC | 0x04 | Method handle is a static method invoker |
METHOD_HANDLE_TYPE_INVOKE_INSTANCE | 0x05 | Method handle is an instance method invoker |
METHOD_HANDLE_TYPE_INVOKE_CONSTRUCTOR | 0x06 | Method handle is a constructor method invoker |
METHOD_HANDLE_TYPE_INVOKE_DIRECT | 0x07 | Method handle is a direct method invoker |
METHOD_HANDLE_TYPE_INVOKE_INTERFACE | 0x08 | Method handle is an interface method invoker |
class_data_item
referenced from class_def_item
appears in the data section
alignment: none (byte-aligned)
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 | Value | 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 | Value | وصف |
---|---|---|
VISIBILITY_BUILD | 0x00 | intended only to be visible at build time (eg, during compilation of other code) |
VISIBILITY_RUNTIME | 0x01 | intended to visible at runtime |
VISIBILITY_SYSTEM | 0x02 | intended to visible at runtime, but only to the underlying system (and not to regular user code) |
encoded_array_item
referenced from class_def_item
appears in the data section
alignment: none (byte-aligned)
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 | Value | وصف |
---|---|---|
whitelist | 0 | Interfaces that can be freely used and are supported as part of the officially documented Android framework Package Index . |
greylist | 1 | Non-SDK interfaces that can be used regardless of the application's target API level . |
blacklist | 2 | Non-SDK interfaces that cannot be used regardless of the application's target API level . Accessing one of these interfaces causes a runtime error . |
greylist‑max‑o | 3 | Non-SDK interfaces that can be used for Android 8.x and below unless they are restricted. |
greylist‑max‑p | 4 | Non-SDK interfaces that can be used for Android 9.x unless they are restricted. |
greylist‑max‑q | 5 | Non-SDK interfaces that can be used for Android 10.x unless they are restricted. |
greylist‑max‑r | 6 | Non-SDK interfaces that can be used for Android 11.x unless they are restricted. |
System annotations
System annotations are used to represent various pieces of reflective information about classes (and methods and fields). This information is generally only accessed indirectly by client (non-system) code.
System annotations are represented in .dex
files as annotations with visibility set to VISIBILITY_SYSTEM
.
dalvik.annotation.AnnotationDefault
appears on methods in annotation interfaces
An AnnotationDefault
annotation is attached to each annotation interface which wishes to indicate default bindings.
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 |