简体   繁体   中英

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), ie 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 (ie 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.

https://source.android.com/devices/tech/dalvik/dex-format has some quick blurbs on the differences between the versions.

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.

Although, note that the newest version is 039, which doesn't seem to be mentioned in the doc. iirc, 039 added the invoke-custom/range , const-method-handle and const-method-type instructions.

Other sources of information include looking at the changelog of those documents: 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

And prior to that, before the files were moved:

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

Also, you should be able to glean some info from the smali source. It has the min/max api levels , where applicable, for every instruction.

For the instructions with the min/max set as an art version, you can use this mapping to map back to an api level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM