解決:系統刪除系統自帶應用(以及改官方刷機包)不開機問題。
$ 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 6月
14 20:06 ./
drwxrwxrwx
1 root root
4096 6月
14 20:05
../
-rwxrwxrwx
1 root root
67108864 1月
1 2009 boot.img*
-rwxrwxrwx
1 root root
7503 1月
1 2009 compatibility.zip*
drwxrwxrwx
1 root root
4096 6月
14 20:03 firmware-update/
drwxrwxrwx
1 root root
0 6月
14 20:03 META-INF/
-rwxrwxrwx
1 root root
1862310910 1月
1 2009 system.new.dat.br*
-rwxrwxrwx
1 root root
0 1月
1 2009 system.patch.dat*
-rwxrwxrwx
1 root root
16900 1月
1 2009 system.transfer.list*
-rwxrwxrwx
1 root root
421975174 1月
1 2009 vendor.new.dat.br*
-rwxrwxrwx
1 root root
0 1月
1 2009 vendor.patch.dat*
-rwxrwxrwx
1 root root
4941 1月
1 2009 vendor.transfer.list*
將system.new.dat.br轉為system.new.dat:
$ brotli -d system.new.dat.br
-rwxrwxrwx
1 root root
3293814784 1月
1 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 6月
14 20:17 system.img*
第二步-掛載system.img
(將system鏡像掛載并修改,省得再去打包img鏡像)
因為掛載到目錄需要ROOT權限,所以切換為ROOT用戶:
$
sudo su
創建system目錄,并掛載system.img:
1 目錄結構如下:
total
220
drwxr-xr-x.
21 root root
4096 1月
1 2009 ./
drwxrwxrwx
1 root root
4096 6月
14 20:23
../
drwxr-xr-x.
2 root root
4096 1月
1 2009 acct/
drwxr-xr-x.
2 root root
4096 1月
1 2009 apex/
lrw-r--r--.
1 root root
11 1月
1 2009 bin -
> /system/bin
lrw-r--r--.
1 root root
50 1月
1 2009 bugreports -
> /data/user_de/0/com.android.shell/files/bugreports
drwxrwx---.
2 wxk
2001 4096 1月
1 2009 cache/
lrw-r--r--.
1 root root
19 1月
1 2009 charger -
> /system/bin/charger
dr-xr-xr-x.
2 root root
4096 1月
1 2009 config/
drwxr-xr-x.
2 root root
4096 1月
1 2009 cust/
lrw-r--r--.
1 root root
17 1月
1 2009 d -
> /sys/kernel/debug/
drwxrwx--x.
2 wxk wxk
4096 1月
1 2009 data/
drwxr-xr-x.
2 root root
4096 1月
1 2009 debug_ramdisk/
lrw-------.
1 root root
23 1月
1 2009 default.prop -
> system/etc/prop.default
drwxr-xr-x.
2 root root
4096 1月
1 2009 dev/
lrw-r--r--.
1 root root
11 1月
1 2009 etc -
> /system/etc
lrwxr-x---.
1 root
2000 16 1月
1 2009 init -
> /system/bin/init
-rwxr-x---.
1 root
2000 2215 1月
1 2009 init.environ.rc*
-rwxr-x---.
1 root
2000 0 1月
1 2009 init.exaid.hardware.rc*
-rwxr-x---.
1 root
2000 642 1月
1 2009 init.miui.cust.rc*
-rwxr-x---.
1 root
2000 3740 1月
1 2009 init.miui.early_boot.sh*
-rwxr-x---.
1 root
2000 57 1月
1 2009 init.miui.google_revenue_share.rc*
-rwxr-x---.
1 root
2000 57 1月
1 2009 init.miui.google_revenue_share_v2.rc*
-rwxr-x---.
1 root
2000 342 1月
1 2009 init.miui.nativedebug.rc*
-rwxr-x---.
1 root
2000 545 1月
1 2009 init.miui.post_boot.sh*
-rwxr-x---.
1 root
2000 100 1月
1 2009 init.miui.qadaemon.rc*
-rwxr-x---.
1 root
2000 10896 1月
1 2009 init.miui.rc*
-rwxr-x---.
1 root
2000 38028 1月
1 2009 init.rc*
-rwxr-x---.
1 root
2000 335 1月
1 2009 init.recovery.hardware.rc*
-rwxr-x---.
1 root
2000 3171 1月
1 2009 init.recovery.qcom.rc*
-rwxr-x---.
1 root
2000 7690 1月
1 2009 init.usb.configfs.rc*
-rwxr-x---.
1 root
2000 5649 1月
1 2009 init.usb.rc*
-rwxr-x---.
1 root
2000 611 1月
1 2009 init.zygote32.rc*
-rwxr-x---.
1 root
2000 1029 1月
1 2009 init.zygote64_32.rc*
drwx------.
2 root root
16384 1月
1 2009 lost+found/
drwxr-xr-x.
2 root wxk
4096 1月
1 2009 mnt/
drwxr-xr-x.
2 root root
4096 1月
1 2009 odm/
drwxr-xr-x.
2 root root
4096 1月
1 2009 oem/
drwxr-xr-x.
2 root root
4096 1月
1 2009 proc/
lrw-r--r--.
1 root root
15 1月
1 2009 product -
> /system/product
lrw-r--r--.
1 root root
24 1月
1 2009 product_services -
> /system/product_services
drwxr-xr-x.
3 root root
4096 1月
1 2009 res/
drwxr-x---.
2 root
2000 4096 1月
1 2009 sbin/
lrw-r--r--.
1 root root
21 1月
1 2009 sdcard -
> /storage/self/primary
drwxr-x--x.
2 root
1028 4096 1月
1 2009 storage/
drwxr-xr-x.
2 root root
4096 1月
1 2009 sys/
drwxr-xr-x.
17 root root
4096 1月
1 2009 system/
-rw-r--r--.
1 root root
2712 1月
1 2009 ueventd.rc
drwxr-xr-x.
2 root
2000 4096 1月
1 2009 vendor/
-rw-r--r--.
1 root root
524 1月
1 2009 verity_key
第三步-修改
反編譯:system/system/framework/services.jar
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
...
total
5
drwxrwxrwx
1 root root
0 6月
14 20:30 ./
drwxrwxrwx
1 root root
4096 6月
14 20:29
../
-rwxrwxrwx
1 root root
299 6月
14 20:30 apktool.yml*
drwxrwxrwx
1 root root
0 6月
14 20:30 original/
drwxrwxrwx
1 root root
0 6月
14 20:29 smali/
drwxrwxrwx
1 root root
0 6月
14 20:30 smali_classes2/
修改SecurityManagerService.smali文件:
搜索“method private checkSystemSelfProtection(Z)V”這行代碼,會看到如下這段:
.method private checkSystemSelfProtection
(Z
)V.locals
1.param p1,
"onlyCore" .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覆蓋原來的:
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
...
-rw-r--r--
1 root root
13076817 6月
14 20:39 ./system/system/framework/services.jar
2021年 06月
14日 星期一
20:40:59 CST
第四步-打包
(和解包方向相反,沿著來時的路再走回去)
卸載system:
將system.img轉為system.new.dat:
Convert to sparse Android data image completed, use
340 seconds
將system.new.dat轉為system.new.dat.br:
# brotli -0 sshellystem.new.dat
壓縮為zip包:
total
2573480
drwxrwxrwx
1 root root
4096 6月
14 20:59 ./
drwxrwxrwx
1 root root
4096 6月
14 20:05
../
-rwxrwxrwx
1 root root
67108864 1月
1 2009 boot.img*
-rwxrwxrwx
1 root root
7503 1月
1 2009 compatibility.zip*
drwxrwxrwx
1 root root
4096 6月
14 20:03 firmware-update/
drwxrwxrwx
1 root root
0 6月
14 20:03 META-INF/
-rwxrwxrwx
1 root root
2146116197 6月
14 20:54 system.new.dat.br*
-rwxrwxrwx
1 root root
0 1月
1 2009 system.patch.dat*
-rwxrwxrwx
1 root root
16835 6月
14 20:54 system.transfer.list*
-rwxrwxrwx
1 root root
421975174 1月
1 2009 vendor.new.dat.br*
-rwxrwxrwx
1 root root
0 1月
1 2009 vendor.patch.dat*
-rwxrwxrwx
1 root root
4941 1月
1 2009 vendor.transfer.list*
1 將當前目錄全部內容壓縮到當前目錄下的miui_jeisuo.zip:
-rwxrwxrwx
1 root root
2655638106 6月
14 21:06 miui_jeisuo.zip*
最后的最后,刷機時不要忘了去除AVB校驗和DM校驗:
總結
以上是生活随笔為你收集整理的破解卡米 刷机包(ROM)的解包与打包过程的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。