首页 > 解决方案 > Format of .dex files for Android 2.1 (Eclair), i.e. API level 7

问题描述

I'm writing an assembler for Android/Dalvik .dex files. The official Android docs seem to only describe the newest version of the .dex format (apparently 038 as of May 2019), with a few short notes describing differences back to version 035. A quick glimpse into Android sources seems to suggest, that version 035 of the format corresponds to Android API level 13, meaning Android 3.2.x (Honeycomb). I own a device with Android 2.1 (Eclair), which apparently means API level 7. I would like to be able to learn how to emit correct .dex and .apk files for that device, to hopefully add support for those to my assembler.

Where can I find information that could help me emit correct .dex files for Android 2.1 (Eclair), i.e. API level 7? I don't even know what's the .dex format version string for that API level!

For "bonus points", I would really love to find some good reference explaining the differences in .dex format between all API levels (at least back to API level 7). I would be also interested if there are any substantial differences in the format of the binary .xml and resource files (as emitted by the aapt tool) between Android API levels. I assume that there's a high chance the .apk format itself, as well as the signing algorithm, hopefully didn't change at all, given that it's the same format used to sign Java .jar files (i.e. a regular .zip with a few simple special files in the META-INF/ subdirectory). But the .dex format spec (including bytecodes) is probably the most important part, or at least a good starting point.

标签: androiddalvikdex

解决方案


https://source.android.com/devices/tech/dalvik/dex-format对版本之间的差异有一些快速的介绍。

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

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

虽然,请注意最新版本是 039,文档中似乎没有提及。iirc, 039 添加了invoke-custom/range,const-method-handleconst-method-type说明。

其他信息来源包括查看这些文件的变更日志: https ://android.googlesource.com/platform/docs/source.android.com/+log/refs/heads/master/en/devices/tech/dalvik/ dex-format.html https://android.googlesource.com/platform/docs/source.android.com/+log/refs/heads/master/en/devices/tech/dalvik/dalvik-bytecode.html

在此之前,在文件被移动之前:

https://android.googlesource.com/platform/docs/source.android.com/+log/a3b748b40bab557fb47fe5a48a5bfb642837fb05/src/devices/tech/dalvik/dex-format.jd https://android.googlesource.com/platform/ docs/source.android.com/+log/a3b748b40bab557fb47fe5a48a5bfb642837fb05/src/devices/tech/dalvik/dalvik-bytecode.jd

此外,您应该能够从 smali 源中收集一些信息。它具有适用于每条指令的最小/最大 api 级别。

对于将 min/max 设置为艺术版本的说明,您可以使用此映射映射回 api 级别。


推荐阅读