日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

破解卡米 刷机包(ROM)的解包与打包过程

發布時間:2023/12/31 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 破解卡米 刷机包(ROM)的解包与打包过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解決:系統刪除系統自帶應用(以及改官方刷機包)不開機問題。
  • 環境:Ubuntu,Python,Java;
$ python3 --version Python 3.8.5$ java --version openjdk 11.0.11 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
  • 工具:

Apktool(https://bitbucket.org/iBotPeaches/apktool/downloads/);
brotli(sudo apt install brotli);
sdat2img(https://github.com/xpirt/sdat2img或者https://github.com/wangkunlin/sdat2img);
rimg2sdat(https://github.com/jazchen/rimg2sdat)。

  • 操作實例:設備:紅米note7;
  • 鏡像(卡刷包):miui_LAVENDER_V12.0.3.0.QFGCNXM_fe51c5198b_10.0.zip
  • 修改位置:/system/framework/services.jar

第一步-解包

  • 解壓刷機包:
  • $ unzip miui_LAVENDER_V12.0.3.0.QFGCNXM_fe51c5198b_10.0.zip
  • 解壓后的目錄結構如下:
  • $ ll miui_LAVENDER_V12.0.3.0.QFGCNXM_fe51c5198b_10.0 total 2296326 drwxrwxrwx 1 root root 4096 614 20:06 ./ drwxrwxrwx 1 root root 4096 614 20:05 ../ -rwxrwxrwx 1 root root 67108864 11 2009 boot.img* -rwxrwxrwx 1 root root 7503 11 2009 compatibility.zip* drwxrwxrwx 1 root root 4096 614 20:03 firmware-update/ drwxrwxrwx 1 root root 0 614 20:03 META-INF/ -rwxrwxrwx 1 root root 1862310910 11 2009 system.new.dat.br* -rwxrwxrwx 1 root root 0 11 2009 system.patch.dat* -rwxrwxrwx 1 root root 16900 11 2009 system.transfer.list* -rwxrwxrwx 1 root root 421975174 11 2009 vendor.new.dat.br* -rwxrwxrwx 1 root root 0 11 2009 vendor.patch.dat* -rwxrwxrwx 1 root root 4941 11 2009 vendor.transfer.list*
  • 將system.new.dat.br轉為system.new.dat:
  • $ brotli -d system.new.dat.br -rwxrwxrwx 1 root root 3293814784 11 2009 system.new.dat*
  • system.new.dat轉為system.img:
  • $ python3 ../sdat2img/sdat2img.py system.transfer.list system.new.dat sdat2img binary - version: 1.2 Android Nougat 7.x / Oreo 8.x detected! Skipping command erase... Copying 555 blocks into position 0... Copying 469 blocks into position 728... Done! Output image: /mnt/hgfs/D/Ubuntu/miui_LAVENDER_V12.0.3.0.QFGCNXM_fe51c5198b_10.0/system.img -rwxrwxrwx 1 root root 3758096384 614 20:17 system.img*

    第二步-掛載system.img

    (將system鏡像掛載并修改,省得再去打包img鏡像)

  • 因為掛載到目錄需要ROOT權限,所以切換為ROOT用戶:
  • $ sudo su
  • 創建system目錄,并掛載system.img:
  • # mkdir system # mount ./system.img ./system
  • 1 目錄結構如下:
  • # ll ./system total 220 drwxr-xr-x. 21 root root 4096 11 2009 ./ drwxrwxrwx 1 root root 4096 614 20:23 ../ drwxr-xr-x. 2 root root 4096 11 2009 acct/ drwxr-xr-x. 2 root root 4096 11 2009 apex/ lrw-r--r--. 1 root root 11 11 2009 bin -> /system/bin lrw-r--r--. 1 root root 50 11 2009 bugreports -> /data/user_de/0/com.android.shell/files/bugreports drwxrwx---. 2 wxk 2001 4096 11 2009 cache/ lrw-r--r--. 1 root root 19 11 2009 charger -> /system/bin/charger dr-xr-xr-x. 2 root root 4096 11 2009 config/ drwxr-xr-x. 2 root root 4096 11 2009 cust/ lrw-r--r--. 1 root root 17 11 2009 d -> /sys/kernel/debug/ drwxrwx--x. 2 wxk wxk 4096 11 2009 data/ drwxr-xr-x. 2 root root 4096 11 2009 debug_ramdisk/ lrw-------. 1 root root 23 11 2009 default.prop -> system/etc/prop.default drwxr-xr-x. 2 root root 4096 11 2009 dev/ lrw-r--r--. 1 root root 11 11 2009 etc -> /system/etc lrwxr-x---. 1 root 2000 16 11 2009 init -> /system/bin/init -rwxr-x---. 1 root 2000 2215 11 2009 init.environ.rc* -rwxr-x---. 1 root 2000 0 11 2009 init.exaid.hardware.rc* -rwxr-x---. 1 root 2000 642 11 2009 init.miui.cust.rc* -rwxr-x---. 1 root 2000 3740 11 2009 init.miui.early_boot.sh* -rwxr-x---. 1 root 2000 57 11 2009 init.miui.google_revenue_share.rc* -rwxr-x---. 1 root 2000 57 11 2009 init.miui.google_revenue_share_v2.rc* -rwxr-x---. 1 root 2000 342 11 2009 init.miui.nativedebug.rc* -rwxr-x---. 1 root 2000 545 11 2009 init.miui.post_boot.sh* -rwxr-x---. 1 root 2000 100 11 2009 init.miui.qadaemon.rc* -rwxr-x---. 1 root 2000 10896 11 2009 init.miui.rc* -rwxr-x---. 1 root 2000 38028 11 2009 init.rc* -rwxr-x---. 1 root 2000 335 11 2009 init.recovery.hardware.rc* -rwxr-x---. 1 root 2000 3171 11 2009 init.recovery.qcom.rc* -rwxr-x---. 1 root 2000 7690 11 2009 init.usb.configfs.rc* -rwxr-x---. 1 root 2000 5649 11 2009 init.usb.rc* -rwxr-x---. 1 root 2000 611 11 2009 init.zygote32.rc* -rwxr-x---. 1 root 2000 1029 11 2009 init.zygote64_32.rc* drwx------. 2 root root 16384 11 2009 lost+found/ drwxr-xr-x. 2 root wxk 4096 11 2009 mnt/ drwxr-xr-x. 2 root root 4096 11 2009 odm/ drwxr-xr-x. 2 root root 4096 11 2009 oem/ drwxr-xr-x. 2 root root 4096 11 2009 proc/ lrw-r--r--. 1 root root 15 11 2009 product -> /system/product lrw-r--r--. 1 root root 24 11 2009 product_services -> /system/product_services drwxr-xr-x. 3 root root 4096 11 2009 res/ drwxr-x---. 2 root 2000 4096 11 2009 sbin/ lrw-r--r--. 1 root root 21 11 2009 sdcard -> /storage/self/primary drwxr-x--x. 2 root 1028 4096 11 2009 storage/ drwxr-xr-x. 2 root root 4096 11 2009 sys/ drwxr-xr-x. 17 root root 4096 11 2009 system/ -rw-r--r--. 1 root root 2712 11 2009 ueventd.rc drwxr-xr-x. 2 root 2000 4096 11 2009 vendor/ -rw-r--r--. 1 root root 524 11 2009 verity_key

    第三步-修改

  • 反編譯:system/system/framework/services.jar
  • # java -jar ../apktool_2.5.0.jar d -r -o ./services/ system/system/framework/services.jar -f I: Using Apktool 2.5.0 on services.jar I: Baksmaling classes.dex... I: Baksmaling classes2.dex... I: Copying assets and libs... I: Copying unknown files... I: Copying original files...# ll ./services/ total 5 drwxrwxrwx 1 root root 0 614 20:30 ./ drwxrwxrwx 1 root root 4096 614 20:29 ../ -rwxrwxrwx 1 root root 299 614 20:30 apktool.yml* drwxrwxrwx 1 root root 0 614 20:30 original/ drwxrwxrwx 1 root root 0 614 20:29 smali/ drwxrwxrwx 1 root root 0 614 20:30 smali_classes2/
  • 修改SecurityManagerService.smali文件:
  • # vi ./services/smali_classes2/com/miui/server/SecurityManagerService.smali

    搜索“method private checkSystemSelfProtection(Z)V”這行代碼,會看到如下這段:

    .method private checkSystemSelfProtection(Z)V.locals 1.param p1, "onlyCore" # Z.line 676new-instance v0, Lcom/miui/server/SecurityManagerService$1;invoke-direct {v0, p0, p1}, Lcom/miui/server/SecurityManagerService$1;-><init>(Lcom/miui/server/SecurityManagerService;Z)V.line 746invoke-virtual {v0}, Lcom/miui/server/SecurityManagerService$1;->start()V.line 747return-void .end method

    改為如下(刪除了.locals 1和return-void之間的內容):

    .method private checkSystemSelfProtection(Z)V.locals 1return-void .end method
  • 編譯生成新的services.jar覆蓋原來的:
  • # java -jar ../apktool_2.5.0.jar b -o ./system/system/framework/services.jar ./services/ -f I: Using Apktool 2.5.0 I: Smaling smali folder into classes.dex... I: Smaling smali_classes2 folder into classes2.dex... W: Could not find resources I: Building apk file... I: Copying unknown files/dir... I: Built apk...# ll ./system/system/framework/services.jar && date -rw-r--r-- 1 root root 13076817 614 20:39 ./system/system/framework/services.jar 2021年 06月 14日 星期一 20:40:59 CST

    第四步-打包

    (和解包方向相反,沿著來時的路再走回去)

  • 卸載system:
  • # umount ./system
  • 將system.img轉為system.new.dat:
  • # python3 ../rimg2sdat/rimg2sdat.py system.imgConvert to sparse Android data image completed, use 340 seconds
  • 將system.new.dat轉為system.new.dat.br:
  • # brotli -0 sshellystem.new.dat
  • 壓縮為zip包:
  • # ll total 2573480 drwxrwxrwx 1 root root 4096 614 20:59 ./ drwxrwxrwx 1 root root 4096 614 20:05 ../ -rwxrwxrwx 1 root root 67108864 11 2009 boot.img* -rwxrwxrwx 1 root root 7503 11 2009 compatibility.zip* drwxrwxrwx 1 root root 4096 614 20:03 firmware-update/ drwxrwxrwx 1 root root 0 614 20:03 META-INF/ -rwxrwxrwx 1 root root 2146116197 614 20:54 system.new.dat.br* -rwxrwxrwx 1 root root 0 11 2009 system.patch.dat* -rwxrwxrwx 1 root root 16835 614 20:54 system.transfer.list* -rwxrwxrwx 1 root root 421975174 11 2009 vendor.new.dat.br* -rwxrwxrwx 1 root root 0 11 2009 vendor.patch.dat* -rwxrwxrwx 1 root root 4941 11 2009 vendor.transfer.list*
  • 1 將當前目錄全部內容壓縮到當前目錄下的miui_jeisuo.zip:
  • # zip -q -r miui_jeisuo.zip *# ll miui_jeisuo.zip -rwxrwxrwx 1 root root 2655638106 614 21:06 miui_jeisuo.zip*

    最后的最后,刷機時不要忘了去除AVB校驗和DM校驗:

    總結

    以上是生活随笔為你收集整理的破解卡米 刷机包(ROM)的解包与打包过程的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。