Skip to content

Instantly share code, notes, and snippets.

@AadilGillani
Created October 1, 2021 06:59
Show Gist options
  • Save AadilGillani/369decab4e99fd17a787136b74b184f4 to your computer and use it in GitHub Desktop.
Save AadilGillani/369decab4e99fd17a787136b74b184f4 to your computer and use it in GitHub Desktop.
Deodexation
What is deodexation?
As everyone knows, the executable code in apk files is located in the classes.dex file. This file can be parsed, edited and reassembled. However, in many firmwares the code is moved from the apk file to the * .odex file, the so-called "optimized" dex. But the * .odex file cannot be parsed directly - before that it must be deodexed, that is, brought to the form classes.dex and returned to the apk file. This process is called deodexation.
2. Why deodex the firmware?
It makes sense to deodex the firmware only in one case - if you need to modify the smali code of applications. Deodexed firmware has no other advantages.
3. What tools are used to deodex * .odex files?
There is only one tool for deodexing android 4.x and below: baksmali. Deodexing android 4.x and below is quite reliable, and if there were no errors during deodexing, then with a 99% probability the applications will also work without errors.
For android 5.x another tool is used: oat2dex. Moreover, the reliability of android 5.x deodexing is lame: even in the case of successful deodexing without errors, the firmware or individual applications may not work correctly. The author of baksmali, a "native" deodexing application, notes that in android 5.x it is not possible to completely recover the smali code from the odex file due to "some potential issues related to field ordering", so baksmali does not support android 5.x deodexing. oat2dex uses debug data to solve this problem, but it doesn't always work well. Thus, the likelihood of successfully deodexing the entire firmware is not very high.
Deodexing android 6.x and higher is supported by two tools: baksmali and oat2dex. By default, baksmali is used, but you can enable deodexing via oat2dex in advanced settings [00].
In android 8 and above, support for a new file format - vdex, appeared, and a new tool appeared for its deodexing - vdexExtractor.
Thus, Batch Apktool supports deodexing of any android version: for API level 20 and below, baksmali is used, for API level 21-22 - oat2dex, for API level 23-25 ​​- baksmali (or oat2dex), for API level 26 and above - baksmali (or vdexExtractor).
4. Direct deodexation process
So, you've decided to deodex the firmware. And the first question that you should ask yourself - do you really need to deodex the firmware?) You can
disassemble the application with an apctul and make a translation or modification of the icons / interface without deodexing.
Deodexing is only needed if you need to change the smali code of system applications.
So you've read all of the above and you want to start deodexing. Place in the _system folder all the contents of the / system folder of the firmware, and select the menu item [01].
Ready! Deodexed files ready for uploading to the phone are located in the _system folder.
I recommend returning them back to the phone using a zip archive for recovery , do not forget to write symlinks in the updater-script, they are displayed at the end of the deodexation log.
After flashing the archive, be sure to wipe the dalwick cache.
5. Possible problems and solutions
If you have android 4.4 and below:
If you get errors during deodexing, try removing inline methods from the device. To do this, select item [18 -> 6], the inline.txt file should appear in the root folder of the current project. If its content looks something like this
Lorg / apache / harmony / dalvik / NativeTestTarget; -> emptyInlineMethod () V
Ljava / lang / String; -> charAt (I) C
... and so on
, and there are no error messages in it, then copy it to the BatchApkTool \ bin \ folder with a replacement, and try to deodex the firmware again.
If you have android 5.x, try updating your oat2dex version. Download the latest version of oat2dex from here and copy and replace it to the bin folder of the utility.
If the firmware does not start after deodexing, carefully study the log. There may be warnings that will help you find an application that was deodexed incorrectly and interferes with the system loading.
If you deodexed the system / framework folder in order to make changes to the jar files, then you need to delete all * .oat and * .art files in the framework folder, otherwise the code will be loaded from them. In this case, all other firmware applications must also be deodexed.
Make sure that you have not forgotten to write symlinks in updater-script, they are displayed at the end of the deodexation log (and, if necessary, remove the symlinks from the firmware).
To run some deodexed firmware (for example, MIUI), you need to patch services.jar (more details here or here )
For the firmware to work normally on the latest versions of android, you need to switch SeLinux to Permissive mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment