How to retrieve Android "odex" System APK (如何將odex的System APK取出)

  • 4240
  • 0

Android系統上預先安裝好的App(放在「/system/app」下)通常為了效能都會優化成「odex檔案」+「沒有classes.dex在內的APK」
但若想要單獨變成一個可執行的APK,裡面就一定要有classes.dex
因此這篇就是在講如何從已經被原廠優化的odex變成一個完整的apk

Android系統上預先安裝好的App(放在「/system/app」下)通常為了效能都會優化成「odex檔案」+「沒有classes.dex在內的APK」

但若想要單獨變成一個可執行的APK,裡面就一定要有classes.dex,才能在另一台裝置上執行

因此這篇就是在講如何從已經被原廠優化的odex變成一個完整的apk

以Phone App來舉例

 
步驟(Step-by-Step):
  1. Install WinRAR

  2. "adb pull /system/framework"     => Retrieve all the Framework resource files and save in current directory. Note: The resource files may be device-unique.

  3. Use "adb pull /system/app/Phone.odex" to get Phone App's odex file. ("adb shell" -> "ls -al /system/app/" to know System APK file names)

  4. Download "apktool" or ("smali" and "baksmali").

  5. Put "smali-xxx.jar", "baksmali-xxx.jar" and "Phone.odex" to the same folder. Assume I put all the files under "C:\Tools\apktool1.5.2\"

  6. Create a new recursive folder in "C:\Tools\apktool1.5.2\system\framework\". Put all the Framework resource files(including core.jar, framework.jar, etc.) you previously retrieved by "adb pull /system/framework" in it.

  7. Now, under the "C:\Tools\apktool1.5.2\" folder, you have "Phone.odex", "smali-2.0.2.jar", "baksmali-2.0.2.jar" and a "system/framework/" directory with all the Framework resources in it.

  8. "java -jar baksmali-2.0.2.jar -d ./system/framework -x Phone.odex"  => Smali files are now extracted from odex and store in "out" directory.

  9. "java -Xmx512M -jar smali-2.0.2.jar out -o classes.dex"  => A new "classes.dex" file is generated from the Smali files in "out" directory.

  10. Put "classes.dex" in the original Phone.apk

  11. Remove the original certificate(under META-INF) in Phone.apk

  12. Sign the apk again with "jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore *.apk alias_name"

  13. "adb install *.apk"