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來舉例
-
Install WinRAR
-
"adb pull /system/framework" => Retrieve all the Framework resource files and save in current directory. Note: The resource files may be device-unique.
-
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)
-
Download "apktool" or ("smali" and "baksmali").
-
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\"
-
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.
-
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.
-
"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.
-
"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.
-
Put "classes.dex" in the original Phone.apk
-
Remove the original certificate(under META-INF) in Phone.apk
-
Sign the apk again with "jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore *.apk alias_name"
-
"adb install *.apk"