本文腳本修改自github上的一個腳本。 環境為Mac OS-Arm版 1. 創建一個目錄 mkdir magisk-sh 2. 下載Magisk apk 可以去github上下載,鏈接:https://github.com/topjohnwu/Magisk/releases 本文采用v26.1版本 ...
本文腳本修改自github上的一個腳本。
環境為Mac OS-Arm版
1. 創建一個目錄
mkdir magisk-sh
2. 下載Magisk apk
可以去github上下載,鏈接:https://github.com/topjohnwu/Magisk/releases
本文采用v26.1版本
下載完成之後,可以直接拖入模擬器中安裝
還需要將magisk apk文件放入剛纔創建的目錄中
3. 編寫腳本
腳本尾碼名為.sh
腳本僅供參考,有些地方需要修改
- 修改
APILEVEL
為自己的 - 修改
APK
為自己的,註意要有版本號,沒有要修改一些東西 - 修改
RAMDISK
,如果是從Android Studio中下載的sdk和模擬器的話,只需要修改system-images目錄後面的就行了,其他的自行尋找目錄 - 需要註意修改4,其中
arm64-v8a
是arm版的目錄,不同架構的需要修改成對應的架構,如x86_64
# 修改1
APILEVEL=31
# 修改2
APK="Magisk-v26.1"
TMPDIR="/data/local/tmp/.magisk"
# 修改3
RAMDISK="/Users/toycon/Library/Android/sdk/system-images/android-31/google_apis/arm64-v8a/ramdisk.img"
yellow=`tput setaf 3`
green=`tput setaf 2`
red=`tput setaf 1`
reset=`tput sgr0`
echo "${green}[*] Using APK ${APK}.apk"
echo "[*] Emulator temp dir is ${TMPDIR}"
echo "[*] RAMDISK image to patch is ${RAMDISK}${reset}"
rm -fr "${APK}"
echo "${yellow}[+] Extracting Magisk APK...${reset}"
apktool d -r -s "${APK}.apk"
echo "${yellow}[*] Testing ADB access...${reset}"
adb shell uname -a
if [ $? -eq 0 ]; then
echo "${green}[*] ADB access seems to be working. Proceeding..."
else
echo "${red}[!] ADB access error. Aborted.${reset}"
exit 1
fi
echo "${yellow}[+] Pushing required files from APK to device TEMP folder${reset}"
adb shell "rm -fr ${TMPDIR}"
adb shell "mkdir ${TMPDIR}"
# 修改4
adb push "${APK}/lib/arm64-v8a/libmagiskboot.so" "${TMPDIR}/magiskboot"
adb push "${APK}/lib/arm64-v8a/libmagiskinit.so" "${TMPDIR}/magiskinit"
adb push "${APK}/lib/arm64-v8a/libmagisk64.so" "${TMPDIR}/magisk64"
adb push "${APK}/assets/stub.apk" "${TMPDIR}/stub.apk"
adb shell "chmod +x ${TMPDIR}/magiskboot"
adb shell "chmod +x ${TMPDIR}/magisk64"
echo "${yellow}[+] Prepatching and uploading 2-staged RAMDISK (into single staged version)${reset}"
lz4cat "${RAMDISK}" | bbe -b '/070701000493e6000001ed0000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!/:/07070100/' -e 'D;A 07070100' | adb shell "cat > ${TMPDIR}/ramdisk.cpio"
adb shell "cd ${TMPDIR}; cp -af ramdisk.cpio ramdisk.cpio.orig"
echo "${yellow}[+] RAMDISK is ready to patch!${reset}"
adb shell "echo KEEPVERITY=true > ${TMPDIR}/config"
adb shell "echo KEEPFORCEENCRYPT=true >> ${TMPDIR}/config"
adb shell "echo PREINITDEVICE=\$(${TMPDIR}/magisk64 --preinit-device) >> ${TMPDIR}/config"
adb shell "cd ${TMPDIR}; ./magiskboot compress=xz magisk64 magisk64.xz"
adb shell "cd ${TMPDIR}; ./magiskboot compress=xz stub.apk stub.xz"
echo "${yellow}[+] Patching MAGISK to RAMDISK${reset}"
adb shell "cd ${TMPDIR}; KEEPVERITY=true KEEPFORCEENCRYPT=true ./magiskboot cpio ramdisk.cpio \"add 0750 init magiskinit\" \"mkdir 0750 overlay.d\" \"mkdir 0750 overlay.d/sbin\" \"add 0644 overlay.d/sbin/magisk64.xz magisk64.xz\" \"add 0644 overlay.d/sbin/stub.xz stub.xz\" \"patch\" \"backup ramdisk.cpio.orig\" \"mkdir 000 .backup\" \"add 000 .backup/.magisk config\""
echo "${yellow}[+] Pulling and compressing patched RAMDISK and cleaning up files on device${reset}"
adb shell "cat ${TMPDIR}/ramdisk.cpio" | gzip -c - > ramdisk-patched.img
adb shell "rm -fr ${TMPDIR}"
echo "${green}[*] MAGISK patched RAMDISK image is available: ramdisk-patched.img"
echo "[*] Run emulator with option '-ramdisk ramdisk-patched.img'${reset}"
4. 保存並運行
cd magisk-sh
sh ./magisk-install.sh
5. 運行問題及解決
... : command not found.
缺什麼安裝什麼
比如:我在運行時缺apktool
,bbe
,通過 homebrew 安裝即可
brew install apktool
brew install bbe
若未安裝 homebrew ,可自行上網搜索安裝,或安裝其他缺失的軟體。
6. 將ramdisk.img
複製到模擬器目錄
cp ./ramdisk-patched.img /Users/toycon/Library/Android/sdk/system-images/android-31/google_apis/arm64-v8a/ramdisk.img
重啟模擬器即可,然後就能看到Magisk安裝成功了