記反編譯修改services.odex再編譯回去

手機是moto x 2014,系統是6.0,需要wipe掉data分區

  1. 先從手機將framework拷到電腦,實際只需要 boot.oat,services.jar,services.odex 這三個文件:
adb pull /system/framework
  1. 反編譯,得到smali文件,用baksmali工具:
java -jar baksmali-2.2.5.jar de -b framework/arm/boot.oat services.odex

將上面framework/arm/boot.oat替換成實際的boot.oat的路徑。得到out文件夾。

  1. 回編譯,用smali工具:
java -jar smali-2.2.5.jar as out -o classes.dex

得到classes.dex文件。

  1. dex轉odex
    網上搜到的dex轉odex方法是用dexopt工具,但是都是幾年前的了。
    現在用dex2oat工具。
    用二進制編輯器打開,ubuntu的話vim上用xxd就行:
vim services.odex

然後按esc到命令模式,輸入 “:%! xxd”,往下看到地址00001000的地方,後面一串ascii文本,描述了系統編譯時用的參數。
整理得到:

dex2oat \
--runtime-arg -Xms64m \
--runtime-arg -Xmx512m \
--dex-file=services.jar \
--dex-location=/system/framework/services.jar \
--oat-file=services.odex \
--instruction-set=arm \
--instruction-set-variant=krait \
--instruction-set-features=default \
--include-patch-information \
--runtime-arg -Xnorelocate \
--no-generate-debug-info \
--abort-on-hard-verifier-error \
--compile-pic

好,搞清楚了怎麼轉之後就開始了:
a) 先將上面得到的classes.dex文件加到/system/framework/services.jar裏面,這個jar現在應該是沒有dex文件的:

zip services.jar -m classes.dex

b) push到手機:

adb push services.jar /data/local/tmp

c) dex2oat:

adb shell
cd /data/local/tmp
dex2oat \
--runtime-arg -Xms64m \
--runtime-arg -Xmx512m \
--dex-file=services.jar \
--dex-location=/system/framework/services.jar \
--oat-file=services.odex \
--instruction-set=arm \
--instruction-set-variant=krait \
--instruction-set-features=default \
--include-patch-information \
--runtime-arg -Xnorelocate \
--no-generate-debug-info \
--abort-on-hard-verifier-error \
--compile-pic

就得到了services.odex。

  1. 將新的services.odex替換上去:
adb shell
su
mount -o rw,remount /system
cp services.odex /system/framework/oat/arm/services.odex
chmod 644 /system/framework/oat/arm/services.odex
reboot recovery

最後一句是重啓到recovery。

  1. 在recovery中wipe掉data和dalvik-cache和cache,開機,就可以了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章