mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 20:19:45 +00:00
Massive build script refactor
This commit is contained in:
parent
532c6caddf
commit
e780c76c93
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -10,8 +10,7 @@
|
|||||||
*.cmd text eol=crlf
|
*.cmd text eol=crlf
|
||||||
|
|
||||||
# Denote all files that are truly binary and should not be modified.
|
# Denote all files that are truly binary and should not be modified.
|
||||||
zip_static/chromeos/** binary
|
chromeos/** binary
|
||||||
uninstaller/chromeos/** binary
|
|
||||||
*.jar binary
|
*.jar binary
|
||||||
*.exe binary
|
*.exe binary
|
||||||
*.apk binary
|
*.apk binary
|
||||||
|
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,20 +1,7 @@
|
|||||||
obj/
|
obj/
|
||||||
libs/
|
libs/
|
||||||
*.zip
|
*.zip
|
||||||
|
*.jks
|
||||||
|
|
||||||
# Copied binaries
|
# Copied binaries
|
||||||
zip_static/arm/*
|
|
||||||
zip_static/arm64/*
|
|
||||||
zip_static/x86/*
|
|
||||||
zip_static/x64/*
|
|
||||||
uninstaller/arm/*
|
|
||||||
uninstaller/arm64/*
|
|
||||||
uninstaller/x86/*
|
|
||||||
uninstaller/x64/*
|
|
||||||
ziptools/zipadjust
|
ziptools/zipadjust
|
||||||
|
|
||||||
# Generated scripts
|
|
||||||
uninstaller/common/
|
|
||||||
zip_static/common/*.sh
|
|
||||||
zip_static/common/*.rc
|
|
||||||
zip_static/META-INF/com/google/android/update-binary
|
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,3 +10,6 @@
|
|||||||
[submodule "jni/magiskpolicy"]
|
[submodule "jni/magiskpolicy"]
|
||||||
path = jni/magiskpolicy
|
path = jni/magiskpolicy
|
||||||
url = https://github.com/topjohnwu/magiskpolicy.git
|
url = https://github.com/topjohnwu/magiskpolicy.git
|
||||||
|
[submodule "MagiskManager"]
|
||||||
|
path = MagiskManager
|
||||||
|
url = https://github.com/topjohnwu/MagiskManager.git
|
||||||
|
1
MagiskManager
Submodule
1
MagiskManager
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ff6938280e5e37bba7965b2fc59c76b2c6bc7c65
|
192
build.cmd
192
build.cmd
@ -1,192 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
SETLOCAL ENABLEEXTENSIONS
|
|
||||||
SET me=%~nx0
|
|
||||||
SET parent=%~dp0
|
|
||||||
SET tab=
|
|
||||||
SET OK=
|
|
||||||
SET DEBUG=
|
|
||||||
|
|
||||||
CD %parent%
|
|
||||||
|
|
||||||
call :%~1 "%~2" "%~3"
|
|
||||||
IF NOT DEFINED OK CALL :usage
|
|
||||||
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
:usage
|
|
||||||
ECHO %me% all ^<version name^> ^<version code^>
|
|
||||||
ECHO %tab%Build binaries, zip, and sign Magisk
|
|
||||||
ECHO %tab%This is equlivant to first ^<build^>, then ^<zip^>
|
|
||||||
ECHO %me% clean
|
|
||||||
ECHO %tab%Cleanup compiled / generated files
|
|
||||||
ECHO %me% build ^<version name^> ^<version code^>
|
|
||||||
ECHO %tab%Build the binaries with ndk
|
|
||||||
ECHO %me% debug
|
|
||||||
ECHO %tab%Build the binaries with the debug flag on
|
|
||||||
ECHO %tab%Call ^<zip^> afterwards if you want to flash on device
|
|
||||||
ECHO %me% zip ^<version name^>
|
|
||||||
ECHO %tab%Zip and sign Magisk
|
|
||||||
ECHO %me% uninstaller
|
|
||||||
ECHO %tab%Zip and sign the uninstaller
|
|
||||||
EXIT /B 1
|
|
||||||
|
|
||||||
:all
|
|
||||||
SET OK=y
|
|
||||||
CALL :build "%~1" "%~2"
|
|
||||||
CALL :zip "%~1"
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:debug
|
|
||||||
SET OK=y
|
|
||||||
SET DEBUG=-DDEBUG
|
|
||||||
CALL :build "%~1" "%~2"
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:build
|
|
||||||
SET OK=y
|
|
||||||
IF [%~1] == [] (
|
|
||||||
CALL :error "Missing version info"
|
|
||||||
CALL :usage
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
IF [%~2] == [] (
|
|
||||||
CALL :error "Missing version info"
|
|
||||||
CALL :usage
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
SET BUILD=Build
|
|
||||||
IF NOT [%DEBUG%] == [] (
|
|
||||||
SET BUILD=Debug
|
|
||||||
)
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * %BUILD%: VERSION=%~1 CODE=%~2
|
|
||||||
ECHO ************************
|
|
||||||
FOR /F "tokens=* USEBACKQ" %%F IN (`where ndk-build`) DO (
|
|
||||||
IF [%%F] == [] (
|
|
||||||
CALL :error "Please add ndk-build to PATH!"
|
|
||||||
EXIT /B 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
CALL ndk-build APP_CFLAGS="-DMAGISK_VERSION=%~1 -DMAGISK_VER_CODE=%~2 %DEBUG%" -j%NUMBER_OF_PROCESSORS% || CALL :error "Magisk binary tools build failed...."
|
|
||||||
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Copying binaries
|
|
||||||
ECHO ************************
|
|
||||||
CALL :mkcp libs\armeabi-v7a\magisk zip_static\arm
|
|
||||||
CALL :mkcp libs\armeabi-v7a\magiskboot zip_static\arm
|
|
||||||
CALL :mkcp libs\arm64-v8a\magisk zip_static\arm64
|
|
||||||
CALL :mkcp libs\arm64-v8a\magiskboot zip_static\arm64
|
|
||||||
CALL :mkcp libs\x86\magisk zip_static\x86
|
|
||||||
CALL :mkcp libs\x86\magiskboot zip_static\x86
|
|
||||||
CALL :mkcp libs\x86_64\magisk zip_static\x64
|
|
||||||
CALL :mkcp libs\x86_64\magiskboot zip_static\x64
|
|
||||||
CALL :mkcp libs\armeabi-v7a\magiskboot uninstaller\arm
|
|
||||||
CALL :mkcp libs\arm64-v8a\magiskboot uninstaller\arm64
|
|
||||||
CALL :mkcp libs\x86\magiskboot uninstaller\x86
|
|
||||||
CALL :mkcp libs\x86_64\magiskboot uninstaller\x64
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:clean
|
|
||||||
SET OK=y
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Cleaning up
|
|
||||||
ECHO ************************
|
|
||||||
CALL ndk-build clean
|
|
||||||
2>NUL RMDIR /S /Q zip_static\arm
|
|
||||||
2>NUL RMDIR /S /Q zip_static\arm64
|
|
||||||
2>NUL RMDIR /S /Q zip_static\x86
|
|
||||||
2>NUL RMDIR /S /Q zip_static\x64
|
|
||||||
2>NUL DEL zip_static\META-INF\com\google\android\update-binary
|
|
||||||
2>NUL DEL zip_static\common\*.sh
|
|
||||||
2>NUL DEL zip_static\common\*.rc
|
|
||||||
2>NUL RMDIR /S /Q uninstaller\common
|
|
||||||
2>NUL RMDIR /S /Q uninstaller\arm
|
|
||||||
2>NUL RMDIR /S /Q uninstaller\arm64
|
|
||||||
2>NUL RMDIR /S /Q uninstaller\x86
|
|
||||||
2>NUL RMDIR /S /Q uninstaller\x64
|
|
||||||
EXIT /B 0
|
|
||||||
|
|
||||||
:zip
|
|
||||||
SET OK=y
|
|
||||||
IF [%~1] == [] (
|
|
||||||
CALL :error "Missing version info"
|
|
||||||
CALL :usage
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
IF NOT EXIST "zip_static\arm\magiskboot" CALL :error "Missing binaries! Please run '%me% build' before zipping!"
|
|
||||||
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Adding version info
|
|
||||||
ECHO ************************
|
|
||||||
powershell.exe -nologo -noprofile -command "(gc -Raw scripts\flash_script.sh) -replace 'MAGISK_VERSION_STUB', 'Magisk v%~1 Installer' | sc zip_static\META-INF\com\google\android\update-binary"
|
|
||||||
rem powershell.exe -nologo -noprofile -command "(gc -Raw scripts\magic_mask.sh) -replace 'MAGISK_VERSION_STUB', 'setprop magisk.version \"%~1\"' | sc zip_static\common\magic_mask.sh"
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Copying Files
|
|
||||||
ECHO ************************
|
|
||||||
COPY /Y scripts\custom_ramdisk_patch.sh zip_static\common\custom_ramdisk_patch.sh
|
|
||||||
COPY /Y scripts\init.magisk.rc zip_static\common\init.magisk.rc
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Zipping Magisk v%~1
|
|
||||||
ECHO ************************
|
|
||||||
CD zip_static
|
|
||||||
2>NUL DEL "..\Magisk-v%~1.zip"
|
|
||||||
..\ziptools\win_bin\zip "..\Magisk-v%~1.zip" -r .
|
|
||||||
CD ..\
|
|
||||||
CALL :sign_zip "Magisk-v%~1.zip"
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:uninstaller
|
|
||||||
SET OK=y
|
|
||||||
IF NOT EXIST "uninstaller\arm\magiskboot" CALL :error "Missing binaries! Please run '%me% build' before zipping!"
|
|
||||||
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Copying Files
|
|
||||||
ECHO ************************
|
|
||||||
CALL :mkcp scripts\magisk_uninstaller.sh uninstaller\common
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Zipping uninstaller
|
|
||||||
ECHO ************************
|
|
||||||
FOR /F "tokens=* USEBACKQ" %%F IN (`ziptools\win_bin\date "+%%Y%%m%%d"`) DO (set timestamp=%%F)
|
|
||||||
CD uninstaller
|
|
||||||
2>NUL DEL "../Magisk-uninstaller-%timestamp%.zip"
|
|
||||||
..\ziptools\win_bin\zip "../Magisk-uninstaller-%timestamp%.zip" -r .
|
|
||||||
CD ..\
|
|
||||||
CALL :sign_zip "Magisk-uninstaller-%timestamp%.zip"
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:sign_zip
|
|
||||||
IF NOT EXIST "ziptools\win_bin\zipadjust.exe" (
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Compiling ZipAdjust
|
|
||||||
ECHO ************************
|
|
||||||
gcc -o ziptools\win_bin\zipadjust ziptools\src\*.c -lz || CALL :error "ZipAdjust Build failed...."
|
|
||||||
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
SET basename="%~1"
|
|
||||||
SET basename="%basename:.zip=%"
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * First sign %~1
|
|
||||||
ECHO ************************
|
|
||||||
java -jar "ziptools\signapk.jar" "ziptools\test.certificate.x509.pem" "ziptools\test.key.pk8" "%~1" "%basename:"=%-firstsign.zip"
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Adjusting %~1
|
|
||||||
ECHO ************************
|
|
||||||
ziptools\win_bin\zipadjust "%basename:"=%-firstsign.zip" "%basename:"=%-adjusted.zip"
|
|
||||||
ECHO ************************
|
|
||||||
ECHO * Final sign %~1
|
|
||||||
ECHO ************************
|
|
||||||
java -jar "ziptools\minsignapk.jar" "ziptools\test.certificate.x509.pem" "ziptools\test.key.pk8" "%basename:"=%-adjusted.zip" "%basename:"=%-signed.zip"
|
|
||||||
|
|
||||||
MOVE /Y "%basename:"=%-signed.zip" "%~1"
|
|
||||||
DEL "%basename:"=%-adjusted.zip" "%basename:"=%-firstsign.zip"
|
|
||||||
EXIT /B %ERRORLEVEL%
|
|
||||||
|
|
||||||
:mkcp
|
|
||||||
2>NUL MKDIR "%~2"
|
|
||||||
2>NUL COPY /Y "%~1" "%~2"
|
|
||||||
EXIT /B 0
|
|
||||||
|
|
||||||
:error
|
|
||||||
ECHO.
|
|
||||||
ECHO ! %~1
|
|
||||||
ECHO.
|
|
||||||
EXIT /B 1
|
|
265
build.py
Executable file
265
build.py
Executable file
@ -0,0 +1,265 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def error(str):
|
||||||
|
print('\n' + '\033[41m' + str + '\033[0m' + '\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def header(str):
|
||||||
|
print('\n' + '\033[44m' + str + '\033[0m' + '\n')
|
||||||
|
|
||||||
|
# Environment checks
|
||||||
|
if not sys.version_info >= (3, 5):
|
||||||
|
error('Requires Python >= 3.5')
|
||||||
|
|
||||||
|
if 'ANDROID_HOME' not in os.environ:
|
||||||
|
error('Please add Android SDK path to ANDROID_HOME environment variable!')
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(['java', '-version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
except FileNotFoundError:
|
||||||
|
error('Please install Java and make sure \'java\' is available in PATH')
|
||||||
|
|
||||||
|
# If not Windows, we need gcc to compile
|
||||||
|
if os.name != 'nt':
|
||||||
|
try:
|
||||||
|
subprocess.run(['gcc', '-v'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
except FileNotFoundError:
|
||||||
|
error('Please install C compiler and make sure \'gcc\' is available in PATH')
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import multiprocessing
|
||||||
|
import zipfile
|
||||||
|
import datetime
|
||||||
|
import errno
|
||||||
|
|
||||||
|
def silentremove(file):
|
||||||
|
try:
|
||||||
|
os.remove(file)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def zip_with_msg(zipfile, source, target):
|
||||||
|
if not os.path.exists(source):
|
||||||
|
error('{} does not exist! Try build \'binary\' and \'apk\' before zipping!'.format(source))
|
||||||
|
print('zip: ' + source + ' -> ' + target)
|
||||||
|
zipfile.write(source, target)
|
||||||
|
|
||||||
|
def build_all(args):
|
||||||
|
build_binary(args)
|
||||||
|
build_apk(args)
|
||||||
|
zip_main(args)
|
||||||
|
|
||||||
|
def build_binary(args):
|
||||||
|
header('* Building Magisk binaries')
|
||||||
|
|
||||||
|
ndk_build = os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build')
|
||||||
|
debug_flag = '-DDEBUG' if args.debug else ''
|
||||||
|
proc = subprocess.run('{} APP_CFLAGS=\"-DMAGISK_VERSION={} -DMAGISK_VER_CODE={} {}\" -j{}'.format(
|
||||||
|
ndk_build, args.versionString, args.versionCode, debug_flag, multiprocessing.cpu_count()), shell=True)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Build Magisk binary failed!')
|
||||||
|
|
||||||
|
def build_apk(args):
|
||||||
|
header('* Building Magisk Manager')
|
||||||
|
|
||||||
|
os.chdir('MagiskManager')
|
||||||
|
if args.debug:
|
||||||
|
proc = subprocess.run(['gradlew', 'assembleDebug'])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Build Magisk Manager failed!')
|
||||||
|
else:
|
||||||
|
if not os.path.exists(os.path.join('..', 'release_signature.jks')):
|
||||||
|
error('Please generate a java keystore and place it in \'release_signature.jks\'')
|
||||||
|
|
||||||
|
proc = subprocess.run(['gradlew', 'assembleRelease'])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Build Magisk Manager failed!')
|
||||||
|
|
||||||
|
unsigned = os.path.join('app', 'build', 'outputs', 'apk', 'app-release-unsigned.apk')
|
||||||
|
aligned = os.path.join('app', 'build', 'outputs', 'apk', 'app-release-aligned.apk')
|
||||||
|
release = os.path.join('app', 'build', 'outputs', 'apk', 'app-release.apk')
|
||||||
|
|
||||||
|
# Find the latest build tools
|
||||||
|
build_tool = sorted(os.listdir(os.path.join(os.environ['ANDROID_HOME'], 'build-tools')))[-1]
|
||||||
|
|
||||||
|
silentremove(aligned)
|
||||||
|
silentremove(release)
|
||||||
|
|
||||||
|
proc = subprocess.run([
|
||||||
|
os.path.join(os.environ['ANDROID_HOME'], 'build-tools', build_tool, 'zipalign'),
|
||||||
|
'-v', '-p', '4', unsigned, aligned])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Zipalign Magisk Manager failed!')
|
||||||
|
|
||||||
|
proc = subprocess.run([
|
||||||
|
os.path.join(os.environ['ANDROID_HOME'], 'build-tools', build_tool, 'apksigner'),
|
||||||
|
'sign', '--ks', os.path.join('..', 'release_signature.jks'), '--out',
|
||||||
|
release, aligned])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Release sign Magisk Manager failed!')
|
||||||
|
|
||||||
|
silentremove(unsigned)
|
||||||
|
silentremove(aligned)
|
||||||
|
|
||||||
|
# Return to upper directory
|
||||||
|
os.chdir('..')
|
||||||
|
|
||||||
|
def sign_adjust_zip(unsigned, output):
|
||||||
|
header('* Signing / Adjusting Zip')
|
||||||
|
|
||||||
|
# Unsigned->signed
|
||||||
|
proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'signapk.jar'),
|
||||||
|
os.path.join('ziptools', 'test.certificate.x509.pem'),
|
||||||
|
os.path.join('ziptools', 'test.key.pk8'), unsigned, 'tmp_signed.zip'])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('First sign flashable zip failed!')
|
||||||
|
|
||||||
|
if os.name != 'nt' and not os.path.exists(os.path.join('ziptools', 'zipadjust')):
|
||||||
|
# Compile zipadjust
|
||||||
|
proc = subprocess.run('gcc -o ziptools/zipadjust ziptools/src/*.c -lz', shell=True)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Build zipadjust failed!')
|
||||||
|
|
||||||
|
# Adjust zip
|
||||||
|
proc = subprocess.run([os.path.join('ziptools', 'zipadjust'), 'tmp_signed.zip', 'tmp_adjusted.zip'])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Adjust flashable zip failed!')
|
||||||
|
|
||||||
|
# Adjusted -> output
|
||||||
|
proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'minsignapk.jar'),
|
||||||
|
os.path.join('ziptools', 'test.certificate.x509.pem'),
|
||||||
|
os.path.join('ziptools', 'test.key.pk8'), 'tmp_adjusted.zip', output])
|
||||||
|
if proc.returncode != 0:
|
||||||
|
error('Second sign flashable zip failed!')
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
silentremove(unsigned)
|
||||||
|
silentremove('tmp_signed.zip')
|
||||||
|
silentremove('tmp_adjusted.zip')
|
||||||
|
|
||||||
|
def zip_main(args):
|
||||||
|
header('* Packing Flashable Zip')
|
||||||
|
|
||||||
|
with zipfile.ZipFile('tmp_unsigned.zip', 'w', compression=zipfile.ZIP_DEFLATED) as zipf:
|
||||||
|
# Compiled Binaries
|
||||||
|
for lib_dir, zip_dir in [('arm64-v8a', 'arm64'), ('armeabi-v7a', 'arm'), ('x86', 'x86'), ('x86_64', 'x64')]:
|
||||||
|
for binary in ['magisk', 'magiskboot']:
|
||||||
|
source = os.path.join('libs', lib_dir, binary)
|
||||||
|
target = os.path.join(zip_dir, binary)
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
|
||||||
|
# APK
|
||||||
|
source = os.path.join('MagiskManager', 'app', 'build', 'outputs', 'apk', 'app-debug.apk' if args.debug else 'app-release.apk')
|
||||||
|
target = os.path.join('common', 'magisk.apk')
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
|
||||||
|
# Scripts
|
||||||
|
source = os.path.join('scripts', 'flash_script.sh')
|
||||||
|
with open(source, 'r') as flash_script:
|
||||||
|
# Add version info into flash script
|
||||||
|
update_binary = flash_script.read().replace(
|
||||||
|
'MAGISK_VERSION_STUB', 'Magisk v{} Installer'.format(args.versionString))
|
||||||
|
target = os.path.join('META-INF', 'com', 'google', 'android', 'update-binary')
|
||||||
|
print('zip: ' + source + ' -> ' + target)
|
||||||
|
zipf.writestr(target, update_binary)
|
||||||
|
target = os.path.join('META-INF', 'com', 'google', 'android', 'updater-script')
|
||||||
|
print('zip: ' + target)
|
||||||
|
zipf.writestr(target, '#MAGISK\n')
|
||||||
|
source = os.path.join('scripts', 'init.magisk.rc')
|
||||||
|
target = os.path.join('common', 'init.magisk.rc')
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
source = os.path.join('scripts', 'boot_patch.sh')
|
||||||
|
target = os.path.join('common', 'boot_patch.sh')
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
|
||||||
|
# Prebuilts
|
||||||
|
for chromeos in ['futility', 'kernel_data_key.vbprivk', 'kernel.keyblock']:
|
||||||
|
source = os.path.join('chromeos', chromeos)
|
||||||
|
zip_with_msg(zipf, source, source)
|
||||||
|
|
||||||
|
# End of zipping
|
||||||
|
|
||||||
|
output = 'Magisk-v{}.zip'.format(args.versionString)
|
||||||
|
sign_adjust_zip('tmp_unsigned.zip', output)
|
||||||
|
|
||||||
|
def zip_uninstaller(args):
|
||||||
|
header('* Packing Uninstaller Zip')
|
||||||
|
|
||||||
|
with zipfile.ZipFile('tmp_unsigned.zip', 'w', compression=zipfile.ZIP_DEFLATED) as zipf:
|
||||||
|
# Compiled Binaries
|
||||||
|
for lib_dir, zip_dir in [('arm64-v8a', 'arm64'), ('armeabi-v7a', 'arm'), ('x86', 'x86'), ('x86_64', 'x64')]:
|
||||||
|
source = os.path.join('libs', lib_dir, 'magiskboot')
|
||||||
|
target = os.path.join(zip_dir, 'magiskboot')
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
|
||||||
|
source = os.path.join('scripts', 'magisk_uninstaller.sh')
|
||||||
|
target = os.path.join('META-INF', 'com', 'google', 'android', 'update-binary')
|
||||||
|
zip_with_msg(zipf, source, target)
|
||||||
|
|
||||||
|
target = os.path.join('META-INF', 'com', 'google', 'android', 'updater-script')
|
||||||
|
print('zip: ' + target)
|
||||||
|
zipf.writestr(target, '#MAGISK\n')
|
||||||
|
|
||||||
|
output = 'Magisk-uninstaller-{}.zip'.format(datetime.datetime.now().strftime('%Y%m%d'))
|
||||||
|
sign_adjust_zip('tmp_unsigned.zip', output)
|
||||||
|
|
||||||
|
def cleanup(args):
|
||||||
|
if len(args.target) == 0:
|
||||||
|
args.target = ['binary', 'apk', 'zip']
|
||||||
|
|
||||||
|
if 'binary' in args.target:
|
||||||
|
header('* Cleaning Magisk binaries')
|
||||||
|
subprocess.run([os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build'), 'clean'])
|
||||||
|
|
||||||
|
if 'apk' in args.target:
|
||||||
|
header('* Cleaning Magisk Manager')
|
||||||
|
os.chdir('MagiskManager')
|
||||||
|
subprocess.run(['gradlew', 'clean'])
|
||||||
|
os.chdir('..')
|
||||||
|
|
||||||
|
if 'zip' in args.target:
|
||||||
|
header('* Cleaning created zip files')
|
||||||
|
for f in os.listdir('.'):
|
||||||
|
if '.zip' in f:
|
||||||
|
print('rm {}'.format(f))
|
||||||
|
silentremove(f)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Magisk build script')
|
||||||
|
parser.add_argument('--debug', action='store_true', help='compile Magisk in debug mode')
|
||||||
|
subparsers = parser.add_subparsers(title='actions')
|
||||||
|
|
||||||
|
all_parser = subparsers.add_parser('all', help='build everything and create flashable zip')
|
||||||
|
all_parser.add_argument('versionString')
|
||||||
|
all_parser.add_argument('versionCode', type=int)
|
||||||
|
all_parser.set_defaults(func=build_all)
|
||||||
|
|
||||||
|
binary_parser = subparsers.add_parser('binary', help='build Magisk binaries')
|
||||||
|
binary_parser.add_argument('versionString')
|
||||||
|
binary_parser.add_argument('versionCode', type=int)
|
||||||
|
binary_parser.set_defaults(func=build_binary)
|
||||||
|
|
||||||
|
apk_parser = subparsers.add_parser('apk', help='build Magisk Manager APK')
|
||||||
|
apk_parser.set_defaults(func=build_apk)
|
||||||
|
|
||||||
|
zip_parser = subparsers.add_parser('zip', help='zip and sign Magisk into a flashable zip')
|
||||||
|
zip_parser.add_argument('versionString')
|
||||||
|
zip_parser.set_defaults(func=zip_main)
|
||||||
|
|
||||||
|
uninstaller_parser = subparsers.add_parser('uninstaller', help='create flashable uninstaller')
|
||||||
|
uninstaller_parser.set_defaults(func=zip_uninstaller)
|
||||||
|
|
||||||
|
clean_parser = subparsers.add_parser('clean', help='clean [target...] Targets: binary apk zip (default: all)')
|
||||||
|
clean_parser.add_argument('target', nargs='*')
|
||||||
|
clean_parser.set_defaults(func=cleanup)
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
args.func(args)
|
174
build.sh
174
build.sh
@ -1,174 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "$ME all <version name> <version code>"
|
|
||||||
echo -e "\tBuild binaries, zip, and sign Magisk"
|
|
||||||
echo -e "\tThis is equlivant to first <build>, then <zip>"
|
|
||||||
echo "$ME clean"
|
|
||||||
echo -e "\tCleanup compiled / generated files"
|
|
||||||
echo "$ME build <verison name> <version code>"
|
|
||||||
echo -e "\tBuild the binaries with ndk"
|
|
||||||
echo "$ME debug <verison name> <version code>"
|
|
||||||
echo -e "\tBuild the binaries with the debug flag on\n\tCall <zip> afterwards if you want to flash on device"
|
|
||||||
echo "$ME zip <version name>"
|
|
||||||
echo -e "\tZip and sign Magisk"
|
|
||||||
echo "$ME uninstaller"
|
|
||||||
echo -e "\tZip and sign the uninstaller"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
echo "************************"
|
|
||||||
echo "* Cleaning up"
|
|
||||||
echo "************************"
|
|
||||||
ndk-build clean 2>/dev/null
|
|
||||||
rm -rfv zip_static/arm
|
|
||||||
rm -rfv zip_static/arm64
|
|
||||||
rm -rfv zip_static/x86
|
|
||||||
rm -rfv zip_static/x64
|
|
||||||
rm -rfv zip_static/META-INF/com/google/android/update-binary
|
|
||||||
rm -rfv zip_static/common/*.sh
|
|
||||||
rm -rfv zip_static/common/*.rc
|
|
||||||
rm -rfv uninstaller/common
|
|
||||||
rm -rfv uninstaller/arm
|
|
||||||
rm -rfv uninstaller/arm64
|
|
||||||
rm -rfv uninstaller/x86
|
|
||||||
rm -rfv uninstaller/x64
|
|
||||||
}
|
|
||||||
|
|
||||||
mkcp() {
|
|
||||||
[ ! -d "$2" ] && mkdir -p "$2"
|
|
||||||
cp -afv $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
echo -e "\n! $1\n"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
build_bin() {
|
|
||||||
[ -z "$1" -o -z "$2" ] && echo -e "! Missing version info\n" && usage
|
|
||||||
BUILD="Build"
|
|
||||||
[ -z "$DEBUG" ] || BUILD="Debug"
|
|
||||||
echo "************************"
|
|
||||||
echo "* $BUILD: VERSION=$1 CODE=$2"
|
|
||||||
echo "************************"
|
|
||||||
[ -z `which ndk-build` ] && error "Please add ndk-build to PATH!"
|
|
||||||
ndk-build APP_CFLAGS="-DMAGISK_VERSION=$1 -DMAGISK_VER_CODE=$2 $DEBUG" -j${CPUNUM} || error "Magisk binary tools build failed...."
|
|
||||||
echo "************************"
|
|
||||||
echo "* Copying binaries"
|
|
||||||
echo "************************"
|
|
||||||
mkcp libs/armeabi-v7a/magisk zip_static/arm
|
|
||||||
mkcp libs/armeabi-v7a/magiskboot zip_static/arm
|
|
||||||
mkcp libs/arm64-v8a/magisk zip_static/arm64
|
|
||||||
mkcp libs/arm64-v8a/magiskboot zip_static/arm64
|
|
||||||
mkcp libs/x86/magisk zip_static/x86
|
|
||||||
mkcp libs/x86/magiskboot zip_static/x86
|
|
||||||
mkcp libs/x86_64/magisk zip_static/x64
|
|
||||||
mkcp libs/x86_64/magiskboot zip_static/x64
|
|
||||||
mkcp libs/armeabi-v7a/magiskboot uninstaller/arm
|
|
||||||
mkcp libs/arm64-v8a/magiskboot uninstaller/arm64
|
|
||||||
mkcp libs/x86/magiskboot uninstaller/x86
|
|
||||||
mkcp libs/x86_64/magiskboot uninstaller/x64
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_package() {
|
|
||||||
[ -z "$1" ] && echo -e "! Missing version info\n" && usage
|
|
||||||
[ ! -f "zip_static/arm/magiskboot" ] && error "Missing binaries!! Please run '$ME build' before zipping"
|
|
||||||
echo "************************"
|
|
||||||
echo "* Adding version info"
|
|
||||||
echo "************************"
|
|
||||||
sed "s/MAGISK_VERSION_STUB/Magisk v$1 Installer/g" scripts/flash_script.sh > zip_static/META-INF/com/google/android/update-binary
|
|
||||||
# sed "s/MAGISK_VERSION_STUB/setprop magisk.version \"$1\"/g" scripts/magic_mask.sh > zip_static/common/magic_mask.sh
|
|
||||||
echo "************************"
|
|
||||||
echo "* Copying files"
|
|
||||||
echo "************************"
|
|
||||||
cp -afv scripts/custom_ramdisk_patch.sh zip_static/common/custom_ramdisk_patch.sh
|
|
||||||
cp -afv scripts/init.magisk.rc zip_static/common/init.magisk.rc
|
|
||||||
echo "************************"
|
|
||||||
echo "* Zipping Magisk v$1"
|
|
||||||
echo "************************"
|
|
||||||
cd zip_static
|
|
||||||
find . -type f -exec chmod 644 {} \;
|
|
||||||
find . -type d -exec chmod 755 {} \;
|
|
||||||
rm -rf "../Magisk-v$1.zip"
|
|
||||||
zip "../Magisk-v$1.zip" -r .
|
|
||||||
cd ../
|
|
||||||
sign_zip "Magisk-v$1.zip"
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_uninstaller() {
|
|
||||||
[ ! -f "uninstaller/arm/magiskboot" ] && error "Missing binaries!! Please run '$0 build' before zipping"
|
|
||||||
echo "************************"
|
|
||||||
echo "* Copying files"
|
|
||||||
echo "************************"
|
|
||||||
mkcp scripts/magisk_uninstaller.sh uninstaller/common
|
|
||||||
echo "************************"
|
|
||||||
echo "* Zipping uninstaller"
|
|
||||||
echo "************************"
|
|
||||||
cd uninstaller
|
|
||||||
find . -type f -exec chmod 644 {} \;
|
|
||||||
find . -type d -exec chmod 755 {} \;
|
|
||||||
TIMESTAMP=`date "+%Y%m%d"`
|
|
||||||
rm -rf "../Magisk-uninstaller-$TIMESTAMP.zip"
|
|
||||||
zip "../Magisk-uninstaller-$TIMESTAMP.zip" -r .
|
|
||||||
cd ../
|
|
||||||
sign_zip "Magisk-uninstaller-$TIMESTAMP.zip"
|
|
||||||
}
|
|
||||||
|
|
||||||
sign_zip() {
|
|
||||||
if [ ! -f "ziptools/zipadjust" ]; then
|
|
||||||
echo "************************"
|
|
||||||
echo "* Compiling ZipAdjust"
|
|
||||||
echo "************************"
|
|
||||||
gcc -o ziptools/zipadjust ziptools/src/*.c -lz || error "ZipAdjust Build failed...."
|
|
||||||
chmod 755 ziptools/zipadjust
|
|
||||||
fi
|
|
||||||
echo "************************"
|
|
||||||
echo "* First sign $1"
|
|
||||||
echo "************************"
|
|
||||||
java -jar "ziptools/signapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "$1" "${1%.*}-firstsign.zip"
|
|
||||||
echo "************************"
|
|
||||||
echo "* Adjusting $1"
|
|
||||||
echo "************************"
|
|
||||||
ziptools/zipadjust "${1%.*}-firstsign.zip" "${1%.*}-adjusted.zip"
|
|
||||||
echo "************************"
|
|
||||||
echo "* Final sign $1"
|
|
||||||
echo "************************"
|
|
||||||
java -jar "ziptools/minsignapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "${1%.*}-adjusted.zip" "${1%.*}-signed.zip"
|
|
||||||
|
|
||||||
mv "${1%.*}-signed.zip" "$1"
|
|
||||||
rm "${1%.*}-adjusted.zip" "${1%.*}-firstsign.zip"
|
|
||||||
}
|
|
||||||
|
|
||||||
DIR="$(cd "$(dirname "$0")"; pwd)"
|
|
||||||
DEBUG=
|
|
||||||
CPUNUM=`getconf _NPROCESSORS_ONLN`
|
|
||||||
ME=$0
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
"all" )
|
|
||||||
build_bin $2 $3
|
|
||||||
zip_package $2
|
|
||||||
;;
|
|
||||||
"clean" )
|
|
||||||
cleanup
|
|
||||||
;;
|
|
||||||
"build" )
|
|
||||||
build_bin $2 $3
|
|
||||||
;;
|
|
||||||
"debug" )
|
|
||||||
DEBUG="-DDEBUG"
|
|
||||||
build_bin $2 $3
|
|
||||||
;;
|
|
||||||
"zip" )
|
|
||||||
[ -z "$2" ] && echo -e "! Missing version info\n" && usage
|
|
||||||
zip_package $2
|
|
||||||
;;
|
|
||||||
"uninstaller" )
|
|
||||||
zip_uninstaller
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
|
220
scripts/boot_patch.sh
Normal file
220
scripts/boot_patch.sh
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
#!/system/bin/sh
|
||||||
|
##########################################################################################
|
||||||
|
#
|
||||||
|
# Magisk Boot Image Patcher
|
||||||
|
# by topjohnwu
|
||||||
|
#
|
||||||
|
# This script should be placed in a directory with at least the following files:
|
||||||
|
#
|
||||||
|
# File name type Description
|
||||||
|
#
|
||||||
|
# boot_patch.sh script A script to patch boot. Expect path to boot image as parameter.
|
||||||
|
# (this file) The script will use binaries and files in its same directory
|
||||||
|
# to complete the patching process
|
||||||
|
# magisk binary The main binary for all Magisk operations.
|
||||||
|
# It is also used to patch the sepolicy in the ramdisk.
|
||||||
|
# magiskboot binary A tool to unpack boot image, decompress ramdisk, extract ramdisk
|
||||||
|
# and patch common patches such as forceencrypt, remove dm-verity.
|
||||||
|
# init.magisk.rc script A new line will be added to init.rc to import this script.
|
||||||
|
# All magisk entrypoints are defined here
|
||||||
|
#
|
||||||
|
# If the script is not running as root, then the input boot image should be a stock image
|
||||||
|
# or have a backup included in ramdisk internally, since we cannot access the stock boot
|
||||||
|
# image placed under /data we've created when previously installing
|
||||||
|
#
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
CWD=`pwd`
|
||||||
|
cd `dirname $1`
|
||||||
|
BOOTIMAGE="`pwd`/`basename $1`"
|
||||||
|
cd "$CWD"
|
||||||
|
|
||||||
|
if [ -z $BOOTIMAGE ]; then
|
||||||
|
ui_print_wrap "This script requires a boot image as a parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Presets
|
||||||
|
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
||||||
|
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
||||||
|
|
||||||
|
# Detect whether running as root
|
||||||
|
[ `id -u` -eq 0 ] && ROOT=true || ROOT=false
|
||||||
|
|
||||||
|
# Call ui_print_wrap if exists, or else simply use echo
|
||||||
|
# Useful when wrapped in flashable zip
|
||||||
|
ui_print_wrap() {
|
||||||
|
type ui_print >/dev/null 2>&1 && ui_print "$1" || echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
grep_prop() {
|
||||||
|
REGEX="s/^$1=//p"
|
||||||
|
shift
|
||||||
|
FILES=$@
|
||||||
|
if [ -z "$FILES" ]; then
|
||||||
|
FILES='/system/build.prop'
|
||||||
|
fi
|
||||||
|
cat $FILES 2>/dev/null | sed -n "$REGEX" | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# --cpio-add <incpio> <mode> <entry> <infile>
|
||||||
|
cpio_add() {
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-add ramdisk.cpio $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
|
# --cpio-extract <incpio> <entry> <outfile>
|
||||||
|
cpio_extract() {
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-extract ramdisk.cpio $1 $2
|
||||||
|
}
|
||||||
|
|
||||||
|
# --cpio-mkdir <incpio> <mode> <entry>
|
||||||
|
cpio_mkdir() {
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-mkdir ramdisk.cpio $1 $2
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Prework
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
# Switch to the location of the script file
|
||||||
|
[ -z $SOURCEDMODE ] && cd "`dirname "${BASH_SOURCE:-$0}"`"
|
||||||
|
chmod +x ./*
|
||||||
|
|
||||||
|
# Detect ARCH
|
||||||
|
[ -d /system/lib64 ] && SYSTEMLIB=/system/lib64 || SYSTEMLIB=/system/lib
|
||||||
|
|
||||||
|
ui_print_wrap "- Unpacking boot image"
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --unpack $BOOTIMAGE
|
||||||
|
|
||||||
|
case $? in
|
||||||
|
1 )
|
||||||
|
ui_print_wrap "! Unable to unpack boot image"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
2 )
|
||||||
|
ui_print_wrap "! Sony ELF32 format detected"
|
||||||
|
ui_print_wrap "! Please use BootBridge from @AdrianDC to flash Magisk"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
3 )
|
||||||
|
ui_print_wrap "! Sony ELF64 format detected"
|
||||||
|
ui_print_wrap "! Stock kernel cannot be patched, please use a custom kernel"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Ramdisk restores
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
||||||
|
ui_print_wrap "- Checking ramdisk status"
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-test ramdisk.cpio
|
||||||
|
case $? in
|
||||||
|
0 ) # Stock boot
|
||||||
|
ui_print_wrap "- Stock boot image detected!"
|
||||||
|
ui_print_wrap "- Backing up stock boot image"
|
||||||
|
SHA1=`LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --sha1 $BOOTIMAGE | tail -n 1`
|
||||||
|
STOCKDUMP=stock_boot_${SHA1}.img
|
||||||
|
dd if=$BOOTIMAGE of=$STOCKDUMP
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --compress $STOCKDUMP
|
||||||
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
|
;;
|
||||||
|
1 ) # Magisk patched
|
||||||
|
ui_print_wrap "- Magisk patched image detected!"
|
||||||
|
# Find SHA1 of stock boot image
|
||||||
|
if [ -z $SHA1 ]; then
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc.old
|
||||||
|
SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc.old`
|
||||||
|
rm -f init.magisk.rc.old
|
||||||
|
fi
|
||||||
|
|
||||||
|
OK=false
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-restore ramdisk.cpio
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
ui_print_wrap "- Ramdisk restored from internal backup"
|
||||||
|
OK=true
|
||||||
|
else
|
||||||
|
# Restore failed
|
||||||
|
ui_print_wrap "! Cannot restore from internal backup"
|
||||||
|
# If we are root and SHA1 known, we try to find the stock backup
|
||||||
|
if $ROOT && [ ! -z $SHA1 ]; then
|
||||||
|
STOCKDUMP=/data/stock_boot_${SHA1}.img
|
||||||
|
if [ -f ${STOCKDUMP}.gz ]; then
|
||||||
|
ui_print_wrap "- Stock boot image backup found"
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --unpack stock_boot.img
|
||||||
|
rm -f stock_boot.img
|
||||||
|
OK=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if ! $OK; then
|
||||||
|
ui_print_wrap "! Ramdisk restoration incomplete"
|
||||||
|
ui_print_wrap "! Will still try to continue installation"
|
||||||
|
fi
|
||||||
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
|
;;
|
||||||
|
2 ) # Other patched
|
||||||
|
ui_print_wrap "! Other patched boot detected!"
|
||||||
|
ui_print_wrap "! Please restore stock boot image"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Ramdisk patches
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
ui_print_wrap "- Patching ramdisk"
|
||||||
|
|
||||||
|
# The common patches
|
||||||
|
$KEEPVERITY || LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-patch-dmverity ramdisk.cpio
|
||||||
|
$KEEPFORCEENCRYPT || LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-patch-forceencrypt ramdisk.cpio
|
||||||
|
|
||||||
|
# Add magisk entrypoint
|
||||||
|
cpio_extract init.rc init.rc
|
||||||
|
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
||||||
|
sed -i "/selinux.reload_policy/d" init.rc
|
||||||
|
cpio_add 750 init.rc init.rc
|
||||||
|
rm -f init.rc
|
||||||
|
|
||||||
|
# sepolicy patches
|
||||||
|
cpio_extract sepolicy sepolicy
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magisk magiskpolicy --load sepolicy --save sepolicy --minimal
|
||||||
|
cpio_add 644 sepolicy sepolicy
|
||||||
|
rm -f sepolicy
|
||||||
|
|
||||||
|
# Add new items
|
||||||
|
if [ ! -z $SHA1 ]; then
|
||||||
|
cp init.magisk.rc init.magisk.rc.bak
|
||||||
|
echo "# STOCKSHA1=$SHA1" >> init.magisk.rc
|
||||||
|
fi
|
||||||
|
cpio_add 750 init.magisk.rc init.magisk.rc
|
||||||
|
[ -f init.magisk.rc.bak ] && mv init.magisk.rc.bak init.magisk.rc
|
||||||
|
cpio_add 755 sbin/magisk magisk
|
||||||
|
|
||||||
|
# Create ramdisk backups
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig
|
||||||
|
|
||||||
|
rm -f ramdisk.cpio.orig
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Repack and flash
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
# Hexpatches
|
||||||
|
|
||||||
|
# Remove Samsung RKP in stock kernel
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --hexpatch kernel \
|
||||||
|
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
|
||||||
|
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
||||||
|
|
||||||
|
ui_print_wrap "- Repacking boot image"
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --repack $BOOTIMAGE
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
ui_print_wrap "! Unable to repack boot image!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
LD_LIBRARY_PATH=$SYSTEMLIB ./magiskboot --cleanup
|
@ -1,56 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
RAMDISK=$1
|
|
||||||
|
|
||||||
TMPDIR=/dev/tmp
|
|
||||||
MAGISKBIN=/data/magisk
|
|
||||||
[ ! -e $MAGISKBIN ] && MAGISKBIN=/cache/data_bin
|
|
||||||
[ ! -e $MAGISKBIN ] && exit 1
|
|
||||||
SYSTEMLIB=/system/lib
|
|
||||||
[ -d /system/lib64 ] && SYSTEMLIB=/system/lib64
|
|
||||||
|
|
||||||
mkdir -p $TMPDIR 2>/dev/null
|
|
||||||
cd $TMPDIR
|
|
||||||
|
|
||||||
cpio_add() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-add $RAMDISK $RAMDISK $1 $2 $3
|
|
||||||
}
|
|
||||||
|
|
||||||
cpio_extract() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-extract $RAMDISK $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
cpio_mkdir() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-mkdir $RAMDISK $RAMDISK $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
# Recursive
|
|
||||||
cpio_rm() {
|
|
||||||
if [ "$1" = "-r" ]; then
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-ls $RAMDISK | grep "^$2/" | while read i ; do
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rm $RAMDISK $RAMDISK $i
|
|
||||||
done
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rmdir $RAMDISK $RAMDISK $2
|
|
||||||
else
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rm $RAMDISK $RAMDISK $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Cleanup SuperSU backups
|
|
||||||
cpio_rm -r .subackup
|
|
||||||
|
|
||||||
# Add magisk entrypoint
|
|
||||||
cpio_extract init.rc init.rc
|
|
||||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
|
||||||
sed -i "/selinux.reload_policy/d" init.rc
|
|
||||||
cpio_add 750 init.rc init.rc
|
|
||||||
|
|
||||||
# sepolicy patches
|
|
||||||
cpio_extract sepolicy sepolicy
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magisk magiskpolicy --load sepolicy --save sepolicy --minimal
|
|
||||||
cpio_add 644 sepolicy sepolicy
|
|
||||||
|
|
||||||
# Add new items
|
|
||||||
cpio_add 750 init.magisk.rc $MAGISKBIN/init.magisk.rc
|
|
||||||
cpio_add 755 sbin/magisk $MAGISKBIN/magisk
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
|||||||
#!/sbin/sh
|
#!/sbin/sh
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
#
|
#
|
||||||
# Magisk Boot Image Patcher
|
# Magisk Flash Script
|
||||||
# by topjohnwu
|
# by topjohnwu
|
||||||
#
|
#
|
||||||
# This zip will patch your boot image with Magisk support
|
# This script will detect, construct the environment for Magisk
|
||||||
|
# It will then call boot_patch.sh to patch the boot image
|
||||||
#
|
#
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
MAGISK=true
|
|
||||||
|
|
||||||
# Detect whether in boot mode
|
# Detect whether in boot mode
|
||||||
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
|
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
|
||||||
|
$BOOTMODE || ps -A | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
|
||||||
|
|
||||||
# This path should work in any cases
|
# This path should work in any cases
|
||||||
TMPDIR=/dev/tmp
|
TMPDIR=/dev/tmp
|
||||||
@ -171,21 +171,6 @@ remove_system_su() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# --cpio-add <incpio> <mode> <entry> <infile>
|
|
||||||
cpio_add() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-add ramdisk.cpio $1 $2 $3
|
|
||||||
}
|
|
||||||
|
|
||||||
# --cpio-extract <incpio> <entry> <outfile>
|
|
||||||
cpio_extract() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-extract ramdisk.cpio $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
# --cpio-mkdir <incpio> <mode> <entry>
|
|
||||||
cpio_mkdir() {
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-mkdir ramdisk.cpio $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Detection
|
# Detection
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
@ -214,9 +199,6 @@ getvar KEEPVERITY
|
|||||||
getvar KEEPFORCEENCRYPT
|
getvar KEEPFORCEENCRYPT
|
||||||
getvar BOOTIMAGE
|
getvar BOOTIMAGE
|
||||||
|
|
||||||
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
|
||||||
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
|
||||||
|
|
||||||
# Check if system root is installed and remove
|
# Check if system root is installed and remove
|
||||||
remove_system_su
|
remove_system_su
|
||||||
|
|
||||||
@ -262,10 +244,10 @@ is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
|||||||
# Copy required files
|
# Copy required files
|
||||||
rm -rf $MAGISKBIN 2>/dev/null
|
rm -rf $MAGISKBIN 2>/dev/null
|
||||||
mkdir -p $MAGISKBIN
|
mkdir -p $MAGISKBIN
|
||||||
cp -af $BINDIR/. $COMMONDIR/magisk.apk $COMMONDIR/init.magisk.rc $COMMONDIR/custom_ramdisk_patch.sh $MAGISKBIN
|
cp -af $BINDIR/. $COMMONDIR/. $MAGISKBIN
|
||||||
|
|
||||||
chmod -R 755 $MAGISKBIN
|
chmod -R 755 $MAGISKBIN
|
||||||
chcon -h u:object_r:system_file:s0 $MAGISKBIN $MAGISKBIN/*
|
chcon -hR u:object_r:system_file:s0 $MAGISKBIN
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Magisk Image
|
# Magisk Image
|
||||||
@ -285,7 +267,7 @@ if [ -f $IMG ]; then
|
|||||||
ui_print "- $IMG detected!"
|
ui_print "- $IMG detected!"
|
||||||
else
|
else
|
||||||
ui_print "- Creating $IMG"
|
ui_print "- Creating $IMG"
|
||||||
make_ext4fs -l 32M -a /magisk -S $COMMONDIR/file_contexts_image $IMG
|
$BINDIR/magisk --createimg $IMG 64M
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount_image $IMG /magisk
|
mount_image $IMG /magisk
|
||||||
@ -295,12 +277,15 @@ if (! is_mounted /magisk); then
|
|||||||
fi
|
fi
|
||||||
MAGISKLOOP=$LOOPDEVICE
|
MAGISKLOOP=$LOOPDEVICE
|
||||||
|
|
||||||
# Core folders and scripts
|
# Core folders
|
||||||
mkdir -p $COREDIR/props $COREDIR/magiskhide $COREDIR/post-fs-data.d $COREDIR/service.d 2>/dev/null
|
mkdir -p $COREDIR/props $COREDIR/post-fs-data.d $COREDIR/service.d 2>/dev/null
|
||||||
cp -af $COMMONDIR/magiskhide/. $COREDIR/magiskhide
|
|
||||||
|
|
||||||
chmod -R 755 $COREDIR/bin $COREDIR/magiskhide $COREDIR/post-fs-data.d $COREDIR/service.d
|
chmod -R 755 $COREDIR/post-fs-data.d $COREDIR/service.d
|
||||||
chown -R 0.0 $COREDIR/bin $COREDIR/magiskhide $COREDIR/post-fs-data.d $COREDIR/service.d
|
chown -R 0.0 $COREDIR/post-fs-data.d $COREDIR/service.d
|
||||||
|
|
||||||
|
# Legacy cleanup
|
||||||
|
mv $COREDIR/magiskhide/hidelist $COREDIR/hidelist 2>/dev/null
|
||||||
|
rm -rf $COREDIR/magiskhide $COREDIR/bin
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Unpack boot
|
# Unpack boot
|
||||||
@ -308,33 +293,6 @@ chown -R 0.0 $COREDIR/bin $COREDIR/magiskhide $COREDIR/post-fs-data.d $COREDIR/s
|
|||||||
|
|
||||||
ui_print "- Found Boot Image: $BOOTIMAGE"
|
ui_print "- Found Boot Image: $BOOTIMAGE"
|
||||||
|
|
||||||
rm -rf $BOOTTMP 2>/dev/null
|
|
||||||
mkdir -p $BOOTTMP
|
|
||||||
cd $BOOTTMP
|
|
||||||
|
|
||||||
ui_print "- Unpacking boot image"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --unpack $BOOTIMAGE
|
|
||||||
|
|
||||||
case $? in
|
|
||||||
1 )
|
|
||||||
ui_print "! Unable to unpack boot image"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
2 )
|
|
||||||
ui_print "! Sony ELF32 format detected"
|
|
||||||
ui_print "! Please use BootBridge from @AdrianDC to flash Magisk"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
3 )
|
|
||||||
ui_print "! Sony ELF64 format detected"
|
|
||||||
ui_print "! Stock kernel cannot be patched, please use a custom kernel"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Ramdisk restores
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
# Update our previous backup to new format if exists
|
# Update our previous backup to new format if exists
|
||||||
if [ -f /data/stock_boot.img ]; then
|
if [ -f /data/stock_boot.img ]; then
|
||||||
SHA1=`LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --sha1 /data/stock_boot.img | tail -n 1`
|
SHA1=`LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --sha1 /data/stock_boot.img | tail -n 1`
|
||||||
@ -343,165 +301,36 @@ if [ -f /data/stock_boot.img ]; then
|
|||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --compress $STOCKDUMP
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --compress $STOCKDUMP
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
SOURCEDMODE=true
|
||||||
SUPERSU=false
|
cd $MAGISKBIN
|
||||||
ui_print "- Checking patch status"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-test ramdisk.cpio
|
|
||||||
case $? in
|
|
||||||
0 ) # Stock boot
|
|
||||||
ui_print "- Backing up stock boot image"
|
|
||||||
rm -f /data/stock_boot*
|
|
||||||
SHA1=`LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --sha1 $BOOTIMAGE | tail -n 1`
|
|
||||||
is_mounted /data && STOCKDUMP=/data/stock_boot_${SHA1}.img || STOCKDUMP=/cache/stock_boot_${SHA1}.img
|
|
||||||
dd if=$BOOTIMAGE of=$STOCKDUMP
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --compress $STOCKDUMP
|
|
||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
|
||||||
;;
|
|
||||||
1 ) # Magisk patched
|
|
||||||
# Find SHA1 of stock boot image
|
|
||||||
if [ -z $SHA1 ]; then
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc
|
|
||||||
SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc`
|
|
||||||
[ ! -z $SHA1 ] && STOCKDUMP=/data/stock_boot_${SHA1}.img
|
|
||||||
rm -f init.magisk.rc
|
|
||||||
fi
|
|
||||||
ui_print "- Restoring ramdisk backup"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-restore ramdisk.cpio
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
# Restore failed, try to find original
|
|
||||||
ui_print "! Cannot restore from ramdisk backup"
|
|
||||||
ui_print "- Finding stock boot image backup"
|
|
||||||
if [ -f ${STOCKDUMP}.gz ]; then
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --unpack stock_boot.img
|
|
||||||
rm -f stock_boot.img
|
|
||||||
else
|
|
||||||
ui_print "! Cannot find stock boot image backup"
|
|
||||||
ui_print "! Will still try to complete installation"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
|
||||||
;;
|
|
||||||
2 ) # SuperSU patched
|
|
||||||
SUPERSU=true
|
|
||||||
ui_print "- SuperSU patched boot detected!"
|
|
||||||
ui_print "- Adding ramdisk patch script for SuperSU"
|
|
||||||
cp -af $COMMONDIR/custom_ramdisk_patch.sh /data/custom_ramdisk_patch.sh
|
|
||||||
ui_print "- We are using SuperSU's own tools, mounting su.img"
|
|
||||||
is_mounted /data && SUIMG=/data/su.img || SUIMG=/cache/su.img
|
|
||||||
mount_image $SUIMG /su
|
|
||||||
SUPERSULOOP=$LOOPDEVICE
|
|
||||||
if (is_mounted /su); then
|
|
||||||
ui_print "- Restoring ramdisk backup with sukernel"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-restore ramdisk.cpio ramdisk.cpio.orig
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
ui_print "! Cannot restore from ramdisk"
|
|
||||||
ui_print "- Finding stock boot image backup with sukernel"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --restore ramdisk.cpio stock_boot.img
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --unpack stock_boot.img
|
|
||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
|
||||||
rm stock_boot.img
|
|
||||||
else
|
|
||||||
ui_print "! Cannot find stock boot image backup"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
ui_print "! SuperSU image mount failed..."
|
|
||||||
ui_print "! Magisk scripts are placed correctly"
|
|
||||||
ui_print "! Flash SuperSU immediately to finish installation"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
##########################################################################################
|
# Source the boot patcher
|
||||||
# Boot image patches
|
. $COMMONDIR/boot_patch.sh $BOOTIMAGE
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
# All ramdisk patch commands are stored in a separate script
|
|
||||||
ui_print "- Patching ramdisk"
|
|
||||||
|
|
||||||
if $SUPERSU; then
|
|
||||||
# Use sukernel to patch ramdisk, so we can use its own tools to backup
|
|
||||||
sh $COMMONDIR/custom_ramdisk_patch.sh $BOOTTMP/ramdisk.cpio
|
|
||||||
|
|
||||||
# Create ramdisk backups
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-backup ramdisk.cpio.orig ramdisk.cpio ramdisk.cpio
|
|
||||||
|
|
||||||
else
|
|
||||||
# The common patches
|
|
||||||
$KEEPVERITY || LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-patch-dmverity ramdisk.cpio
|
|
||||||
$KEEPFORCEENCRYPT || LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-patch-forceencrypt ramdisk.cpio
|
|
||||||
|
|
||||||
# Add magisk entrypoint
|
|
||||||
cpio_extract init.rc init.rc
|
|
||||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
|
||||||
sed -i "/selinux.reload_policy/d" init.rc
|
|
||||||
cpio_add 750 init.rc init.rc
|
|
||||||
|
|
||||||
# sepolicy patches
|
|
||||||
cpio_extract sepolicy sepolicy
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magisk magiskpolicy --load sepolicy --save sepolicy --minimal
|
|
||||||
cpio_add 644 sepolicy sepolicy
|
|
||||||
|
|
||||||
# Add new items
|
|
||||||
[ ! -z $SHA1 ] && echo "# STOCKSHA1=$SHA1" >> $COMMONDIR/init.magisk.rc
|
|
||||||
cpio_add 750 init.magisk.rc $COMMONDIR/init.magisk.rc
|
|
||||||
cpio_add 755 sbin/magisk $BINDIR/magisk
|
|
||||||
|
|
||||||
# Create ramdisk backups
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f ramdisk.cpio.orig
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Repack and flash
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
# Hexpatches
|
|
||||||
|
|
||||||
# Remove Samsung RKP in stock kernel
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --hexpatch kernel \
|
|
||||||
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
|
|
||||||
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
|
||||||
|
|
||||||
ui_print "- Repacking boot image"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --repack $BOOTIMAGE
|
|
||||||
|
|
||||||
case $? in
|
|
||||||
1 )
|
|
||||||
ui_print "! Unable to repack boot image!"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
2 )
|
|
||||||
ui_print "! Boot partition space insufficient"
|
|
||||||
ui_print "! Remove ramdisk backups and try again"
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-rm ramdisk.cpio -r .backup
|
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --repack $BOOTIMAGE
|
|
||||||
if [ $? -eq 2 ]; then
|
|
||||||
ui_print "! Boot partition size still too small..."
|
|
||||||
ui_print "! Unable to install Magisk"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Sign chromeos boot
|
# Sign chromeos boot
|
||||||
if [ -f chromeos ]; then
|
if [ -f chromeos ]; then
|
||||||
cp -af $CHROMEDIR/. $MAGISKBIN/chromeos
|
echo > empty
|
||||||
echo > config
|
|
||||||
echo > bootloader
|
LD_LIBRARY_PATH=$SYSTEMLIB $CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed \
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed --keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk --version 1 --vmlinuz new-boot.img --config config --arch arm --bootloader bootloader --flags 0x1
|
--keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk \
|
||||||
rm -f new-boot.img
|
--version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1
|
||||||
|
|
||||||
|
rm -f empty new-boot.img
|
||||||
mv new-boot.img.signed new-boot.img
|
mv new-boot.img.signed new-boot.img
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if is_mounted /data; then
|
||||||
|
rm -f /data/stock_boot*
|
||||||
|
mv stock_boot* /data
|
||||||
|
fi
|
||||||
|
|
||||||
ui_print "- Flashing new boot image"
|
ui_print "- Flashing new boot image"
|
||||||
[ ! -L $BOOTIMAGE ] && dd if=/dev/zero of=$BOOTIMAGE bs=4096 2>/dev/null
|
if [ -L $BOOTIMAGE ]; then
|
||||||
dd if=new-boot.img of=$BOOTIMAGE bs=4096
|
dd if=new-boot.img of=$BOOTIMAGE bs=4096
|
||||||
|
else
|
||||||
|
cat new-boot.img /dev/zero | dd of=$BOOTIMAGE bs=4096
|
||||||
|
fi
|
||||||
|
rm -f new-boot.img
|
||||||
|
|
||||||
cd /
|
cd /
|
||||||
|
|
||||||
@ -510,11 +339,6 @@ if ! $BOOTMODE; then
|
|||||||
umount /magisk
|
umount /magisk
|
||||||
losetup -d $MAGISKLOOP 2>/dev/null
|
losetup -d $MAGISKLOOP 2>/dev/null
|
||||||
rmdir /magisk
|
rmdir /magisk
|
||||||
if $SUPERSU; then
|
|
||||||
umount /su
|
|
||||||
losetup -d $SUPERSULOOP 2>/dev/null
|
|
||||||
rmdir /su
|
|
||||||
fi
|
|
||||||
umount /system
|
umount /system
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1,561 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
LOGFILE=/cache/magisk.log
|
|
||||||
DISABLEFILE=/cache/.disable_magisk
|
|
||||||
UNINSTALLER=/cache/magisk_uninstaller.sh
|
|
||||||
IMG=/data/magisk.img
|
|
||||||
WHITELIST="/system/bin"
|
|
||||||
|
|
||||||
MOUNTPOINT=/magisk
|
|
||||||
COREDIR=$MOUNTPOINT/.core
|
|
||||||
|
|
||||||
TMPDIR=/dev/magisk
|
|
||||||
DUMMDIR=$TMPDIR/dummy
|
|
||||||
MIRRDIR=$TMPDIR/mirror
|
|
||||||
MOUNTINFO=$TMPDIR/mnt
|
|
||||||
|
|
||||||
# Use the included busybox for maximum compatibility and reliable results
|
|
||||||
# e.g. we rely on the option "-c" for cp (reserve contexts), and -exec for find
|
|
||||||
TOOLPATH=/dev/busybox
|
|
||||||
DATABIN=/data/magisk
|
|
||||||
MAGISKBIN=$COREDIR/bin
|
|
||||||
OLDPATH=$PATH
|
|
||||||
export PATH=$TOOLPATH:$OLDPATH
|
|
||||||
|
|
||||||
APPDIR=/data/data/com.topjohnwu.magisk/files
|
|
||||||
|
|
||||||
# Default permissions
|
|
||||||
umask 022
|
|
||||||
|
|
||||||
log_print() {
|
|
||||||
echo "$1"
|
|
||||||
echo "$1" >> $LOGFILE
|
|
||||||
log -p i -t Magisk "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
mktouch() {
|
|
||||||
mkdir -p "${1%/*}" 2>/dev/null
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
touch "$1" 2>/dev/null
|
|
||||||
else
|
|
||||||
echo "$2" > "$1" 2>/dev/null
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
in_list() {
|
|
||||||
for i in $2; do
|
|
||||||
[ "$1" = "$i" ] && return 0
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
unblock() {
|
|
||||||
touch /dev/.magisk.unblock
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
bind_mount() {
|
|
||||||
if [ -e "$1" -a -e "$2" ]; then
|
|
||||||
mount -o bind "$1" "$2" || log_print "Mount Fail: $1 -> $2"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
loopsetup() {
|
|
||||||
LOOPDEVICE=
|
|
||||||
for DEV in `ls /dev/block/loop*`; do
|
|
||||||
if losetup $DEV $1; then
|
|
||||||
LOOPDEVICE=$DEV
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
image_size_check() {
|
|
||||||
e2fsck -yf $1
|
|
||||||
curBlocks=`e2fsck -n $1 2>/dev/null | grep $1 | cut -d, -f3 | cut -d\ -f2`;
|
|
||||||
curUsedM=`echo "$curBlocks" | cut -d/ -f1`
|
|
||||||
curSizeM=`echo "$curBlocks" | cut -d/ -f1`
|
|
||||||
curFreeM=$(((curSizeM - curUsedM) * 4 / 1024))
|
|
||||||
curUsedM=$((curUsedM * 4 / 1024 + 1))
|
|
||||||
curSizeM=$((curSizeM * 4 / 1024))
|
|
||||||
}
|
|
||||||
|
|
||||||
module_scripts() {
|
|
||||||
BASE=$MOUNTPOINT
|
|
||||||
for MOD in $BASE/* ; do
|
|
||||||
if [ ! -f $MOD/disable -a -f $MOD/$1.sh ]; then
|
|
||||||
chmod 755 $MOD/$1.sh
|
|
||||||
chcon u:object_r:system_file:s0 $MOD/$1.sh
|
|
||||||
log_print "$1: $MOD/$1.sh"
|
|
||||||
sh $MOD/$1.sh
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
general_scripts() {
|
|
||||||
for SCRIPT in $COREDIR/${1}.d/* ; do
|
|
||||||
if [ -f "$SCRIPT" ]; then
|
|
||||||
chmod 755 $SCRIPT
|
|
||||||
chcon u:object_r:system_file:s0 $SCRIPT
|
|
||||||
log_print "${1}.d: $SCRIPT"
|
|
||||||
sh $SCRIPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
travel() {
|
|
||||||
cd "$TRAVEL_ROOT/$1"
|
|
||||||
if [ -f .replace ]; then
|
|
||||||
log_print "Replace: /$1"
|
|
||||||
rm -rf "$MOUNTINFO/$1"
|
|
||||||
mktouch "$MOUNTINFO/$1" "$TRAVEL_ROOT"
|
|
||||||
else
|
|
||||||
for ITEM in * ; do
|
|
||||||
# This means it's an empty folder (shouldn't happen, but better to be safe)
|
|
||||||
[ "$ITEM" = "*" ] && return
|
|
||||||
# Ignore /system/vendor since we will handle it differently
|
|
||||||
[ "$1" = "system" -a "$ITEM" = "vendor" ] && continue
|
|
||||||
|
|
||||||
# Target not found or target/file is a symlink
|
|
||||||
if [ ! -e "/$1/$ITEM" -o -L "/$1/$ITEM" -o -L "$ITEM" ]; then
|
|
||||||
# If we are in a higher level, delete the lower levels
|
|
||||||
rm -rf "$MOUNTINFO/dummy/$1" 2>/dev/null
|
|
||||||
# Mount the dummy parent
|
|
||||||
log_print "Replace with dummy: /$1"
|
|
||||||
mktouch "$MOUNTINFO/dummy/$1"
|
|
||||||
|
|
||||||
if [ -L "$ITEM" ]; then
|
|
||||||
# Copy symlinks
|
|
||||||
log_print "Symlink: /$1/$ITEM"
|
|
||||||
mkdir -p "$DUMMDIR/$1" 2>/dev/null
|
|
||||||
cp -afc "$ITEM" "$DUMMDIR/$1/$ITEM"
|
|
||||||
elif [ -d "$ITEM" ]; then
|
|
||||||
# Create new dummy directory and mount it
|
|
||||||
log_print "New directory: /$1/$ITEM"
|
|
||||||
mkdir -p "$DUMMDIR/$1/$ITEM"
|
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
|
||||||
else
|
|
||||||
# Create new dummy file and mount it
|
|
||||||
log_print "New file: /$1/$ITEM"
|
|
||||||
mktouch "$DUMMDIR/$1/$ITEM"
|
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ -d "$ITEM" ]; then
|
|
||||||
# It's an directory, travel deeper
|
|
||||||
(travel "$1/$ITEM")
|
|
||||||
elif [ ! -L "$ITEM" ]; then
|
|
||||||
# Mount this file
|
|
||||||
log_print "Replace: /$1/$ITEM"
|
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
clone_dummy() {
|
|
||||||
LINK=false
|
|
||||||
in_list "$1" "$WHITELIST" && LINK=true
|
|
||||||
|
|
||||||
for ITEM in $MIRRDIR$1/* ; do
|
|
||||||
REAL="${ITEM#$MIRRDIR}"
|
|
||||||
if [ -d "$MOUNTINFO$REAL" ]; then
|
|
||||||
# Need to clone deeper
|
|
||||||
mkdir -p "$DUMMDIR$REAL"
|
|
||||||
(clone_dummy "$REAL")
|
|
||||||
elif [ ! -f "$DUMMDIR$REAL" ]; then
|
|
||||||
# It's not the file to be added/replaced, clone it
|
|
||||||
if [ -L "$ITEM" ]; then
|
|
||||||
# Copy original symlink
|
|
||||||
cp -afc "$ITEM" "$DUMMDIR$REAL"
|
|
||||||
else
|
|
||||||
if $LINK && [ ! -e "$MOUNTINFO$REAL" ]; then
|
|
||||||
ln -sf "$MIRRDIR$REAL" "$DUMMDIR$REAL"
|
|
||||||
else
|
|
||||||
if [ -d "$ITEM" ]; then
|
|
||||||
mkdir -p "$DUMMDIR$REAL"
|
|
||||||
else
|
|
||||||
mktouch "$DUMMDIR$REAL"
|
|
||||||
fi
|
|
||||||
if [ ! -e "$MOUNTINFO$REAL" ]; then
|
|
||||||
log_print "Clone skeleton: $REAL"
|
|
||||||
mktouch "$MOUNTINFO/mirror$REAL"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
merge_image() {
|
|
||||||
if [ -f $1 ]; then
|
|
||||||
log_print "$1 found"
|
|
||||||
if [ -f $IMG ]; then
|
|
||||||
log_print "$IMG found, attempt to merge"
|
|
||||||
|
|
||||||
# Handle large images
|
|
||||||
image_size_check $1
|
|
||||||
mergeUsedM=$curUsedM
|
|
||||||
image_size_check $IMG
|
|
||||||
if [ "$mergeUsedM" -gt "$curFreeM" ]; then
|
|
||||||
NEWDATASIZE=$(((mergeUsedM + curUsedM) / 32 * 32 + 32))
|
|
||||||
log_print "Expanding $IMG to ${NEWDATASIZE}M..."
|
|
||||||
resize2fs $IMG ${NEWDATASIZE}M
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start merging
|
|
||||||
mkdir /cache/data_img
|
|
||||||
mkdir /cache/merge_img
|
|
||||||
|
|
||||||
# setup loop devices
|
|
||||||
loopsetup $IMG
|
|
||||||
LOOPDATA=$LOOPDEVICE
|
|
||||||
log_print "$LOOPDATA $IMG"
|
|
||||||
|
|
||||||
loopsetup $1
|
|
||||||
LOOPMERGE=$LOOPDEVICE
|
|
||||||
log_print "$LOOPMERGE $1"
|
|
||||||
|
|
||||||
if [ ! -z $LOOPDATA -a ! -z $LOOPMERGE ]; then
|
|
||||||
# if loop devices have been setup, mount images
|
|
||||||
OK=false
|
|
||||||
mount -t ext4 -o rw,noatime $LOOPDATA /cache/data_img && \
|
|
||||||
mount -t ext4 -o rw,noatime $LOOPMERGE /cache/merge_img && \
|
|
||||||
OK=true
|
|
||||||
|
|
||||||
if $OK; then
|
|
||||||
# Merge (will reserve selinux contexts)
|
|
||||||
cd /cache/merge_img
|
|
||||||
for MOD in *; do
|
|
||||||
if [ "$MOD" != "lost+found" ]; then
|
|
||||||
log_print "Merging: $MOD"
|
|
||||||
rm -rf /cache/data_img/$MOD
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
cp -afc . /cache/data_img
|
|
||||||
log_print "Merge complete"
|
|
||||||
cd /
|
|
||||||
fi
|
|
||||||
|
|
||||||
umount /cache/data_img
|
|
||||||
umount /cache/merge_img
|
|
||||||
fi
|
|
||||||
|
|
||||||
losetup -d $LOOPDATA
|
|
||||||
losetup -d $LOOPMERGE
|
|
||||||
|
|
||||||
rmdir /cache/data_img
|
|
||||||
rmdir /cache/merge_img
|
|
||||||
else
|
|
||||||
log_print "Moving $1 to $IMG "
|
|
||||||
mv $1 $IMG
|
|
||||||
fi
|
|
||||||
rm -f $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
post-fs )
|
|
||||||
mv $LOGFILE /cache/last_magisk.log
|
|
||||||
touch $LOGFILE
|
|
||||||
chmod 644 $LOGFILE
|
|
||||||
|
|
||||||
# No more cache mods!
|
|
||||||
# Only for multirom!
|
|
||||||
|
|
||||||
log_print "** Magisk post-fs mode running..."
|
|
||||||
|
|
||||||
# Cleanup legacy stuffs...
|
|
||||||
rm -rf /cache/magisk /cache/magisk_merge /cache/magiskhide.log
|
|
||||||
|
|
||||||
[ -f $DISABLEFILE -o -f $UNINSTALLER ] && unblock
|
|
||||||
|
|
||||||
if [ -d /cache/magisk_mount ]; then
|
|
||||||
log_print "* Mounting cache files"
|
|
||||||
find /cache/magisk_mount -type f 2>/dev/null | while read ITEM ; do
|
|
||||||
chmod 644 "$ITEM"
|
|
||||||
chcon u:object_r:system_file:s0 "$ITEM"
|
|
||||||
TARGET="${ITEM#/cache/magisk_mount}"
|
|
||||||
bind_mount "$ITEM" "$TARGET"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
unblock
|
|
||||||
;;
|
|
||||||
|
|
||||||
post-fs-data )
|
|
||||||
# /data not mounted yet
|
|
||||||
! mount | grep " /data " >/dev/null && unblock
|
|
||||||
mount | grep " /data " | grep "tmpfs" >/dev/null && unblock
|
|
||||||
|
|
||||||
# Don't run twice
|
|
||||||
if [ "`getprop magisk.restart_pfsd`" != "1" ]; then
|
|
||||||
|
|
||||||
log_print "** Magisk post-fs-data mode running..."
|
|
||||||
|
|
||||||
# Cache support
|
|
||||||
mv /cache/stock_boot* /data 2>/dev/null
|
|
||||||
if [ -d /cache/data_bin ]; then
|
|
||||||
rm -rf $DATABIN
|
|
||||||
mv /cache/data_bin $DATABIN
|
|
||||||
chmod -R 755 $DATABIN
|
|
||||||
chown -R 0.0 $DATABIN
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up environment
|
|
||||||
mkdir -p $TOOLPATH
|
|
||||||
$DATABIN/busybox --install -s $TOOLPATH
|
|
||||||
ln -sf $DATABIN/busybox $TOOLPATH/busybox
|
|
||||||
# Prevent issues
|
|
||||||
rm -f $TOOLPATH/su $TOOLPATH/sh $TOOLPATH/reboot
|
|
||||||
find $DATABIN $TOOLPATH -exec chcon -h u:object_r:system_file:s0 {} \;
|
|
||||||
|
|
||||||
if [ -f $UNINSTALLER ]; then
|
|
||||||
touch /dev/.magisk.unblock
|
|
||||||
(BOOTMODE=true sh $UNINSTALLER) &
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f $DATABIN/magisk.apk ]; then
|
|
||||||
if ! ls /data/app | grep com.topjohnwu.magisk; then
|
|
||||||
mkdir /data/app/com.topjohnwu.magisk-1
|
|
||||||
cp $DATABIN/magisk.apk /data/app/com.topjohnwu.magisk-1/base.apk
|
|
||||||
chown 1000.1000 /data/app/com.topjohnwu.magisk-1
|
|
||||||
chown 1000.1000 /data/app/com.topjohnwu.magisk-1/base.apk
|
|
||||||
chmod 755 /data/app/com.topjohnwu.magisk-1
|
|
||||||
chmod 644 /data/app/com.topjohnwu.magisk-1/base.apk
|
|
||||||
chcon u:object_r:apk_data_file:s0 /data/app/com.topjohnwu.magisk-1
|
|
||||||
chcon u:object_r:apk_data_file:s0 /data/app/com.topjohnwu.magisk-1/base.apk
|
|
||||||
fi
|
|
||||||
rm -f $DATABIN/magisk.apk 2>/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Image merging
|
|
||||||
chmod 644 $IMG /cache/magisk.img /data/magisk_merge.img 2>/dev/null
|
|
||||||
merge_image /cache/magisk.img
|
|
||||||
merge_image /data/magisk_merge.img
|
|
||||||
|
|
||||||
# Mount magisk.img
|
|
||||||
[ ! -d $MOUNTPOINT ] && mkdir -p $MOUNTPOINT
|
|
||||||
if ! mount | grep $MOUNTPOINT; then
|
|
||||||
loopsetup $IMG
|
|
||||||
[ ! -z $LOOPDEVICE ] && mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
log_print "magisk.img mount failed, nothing to do :("
|
|
||||||
unblock
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove empty directories, legacy paths, symlinks, old temporary images
|
|
||||||
find $MOUNTPOINT -type d -depth ! -path "*core*" -exec rmdir {} \; 2>/dev/null
|
|
||||||
rm -rf $MOUNTPOINT/zzsupersu $MOUNTPOINT/phh $COREDIR/dummy $COREDIR/mirror \
|
|
||||||
$COREDIR/busybox $COREDIR/su /data/magisk/*.img /data/busybox 2>/dev/null
|
|
||||||
|
|
||||||
# Remove modules that are labeled to be removed
|
|
||||||
for MOD in $MOUNTPOINT/* ; do
|
|
||||||
rm -f $MOD/system/placeholder 2>/dev/null
|
|
||||||
if [ -f $MOD/remove ]; then
|
|
||||||
log_print "Remove module: $MOD"
|
|
||||||
rm -rf $MOD
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Unmount, shrink, remount
|
|
||||||
if umount $MOUNTPOINT; then
|
|
||||||
losetup -d $LOOPDEVICE 2>/dev/null
|
|
||||||
image_size_check $IMG
|
|
||||||
NEWDATASIZE=$((curUsedM / 32 * 32 + 32))
|
|
||||||
if [ "$curSizeM" -gt "$NEWDATASIZE" ]; then
|
|
||||||
log_print "Shrinking $IMG to ${NEWDATASIZE}M..."
|
|
||||||
resize2fs $IMG ${NEWDATASIZE}M
|
|
||||||
fi
|
|
||||||
loopsetup $IMG
|
|
||||||
[ ! -z $LOOPDEVICE ] && mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
log_print "magisk.img mount failed, nothing to do :("
|
|
||||||
unblock
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_print "* Running post-fs-data.d"
|
|
||||||
general_scripts post-fs-data
|
|
||||||
|
|
||||||
log_print "* Loading core props"
|
|
||||||
for PROP in $COREDIR/props/* ; do
|
|
||||||
if [ -f $PROP ]; then
|
|
||||||
log_print "Load prop: $PROP"
|
|
||||||
$MAGISKBIN/resetprop --file $PROP
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Exit if disabled
|
|
||||||
[ -f $DISABLEFILE ] && unblock
|
|
||||||
|
|
||||||
######################
|
|
||||||
# Core features done #
|
|
||||||
######################
|
|
||||||
|
|
||||||
# Multirom functions should go here, not available right now
|
|
||||||
MULTIROM=false
|
|
||||||
|
|
||||||
log_print "* Preparing modules"
|
|
||||||
|
|
||||||
# Remove crap folder
|
|
||||||
rm -rf $MOUNTPOINT/lost+found
|
|
||||||
|
|
||||||
# Link vendor if not exist
|
|
||||||
if [ ! -e /vendor ]; then
|
|
||||||
mount -o rw,remount rootfs /
|
|
||||||
ln -sf /system/vendor /vendor
|
|
||||||
mount -o ro,remount rootfs /
|
|
||||||
fi
|
|
||||||
|
|
||||||
for MOD in $MOUNTPOINT/* ; do
|
|
||||||
if [ ! -f $MOD/disable ]; then
|
|
||||||
# Travel through all mods
|
|
||||||
if [ -f $MOD/auto_mount -a -d $MOD/system ]; then
|
|
||||||
log_print "Analyzing module: $MOD"
|
|
||||||
TRAVEL_ROOT=$MOD
|
|
||||||
(travel system)
|
|
||||||
rm -f $MOD/vendor 2>/dev/null
|
|
||||||
if [ -d $MOD/system/vendor ]; then
|
|
||||||
ln -sf $MOD/system/vendor $MOD/vendor
|
|
||||||
(travel vendor)
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# Read in defined system props
|
|
||||||
if [ -f $MOD/system.prop ]; then
|
|
||||||
log_print "* Reading props from $MOD/system.prop"
|
|
||||||
$MAGISKBIN/resetprop --file $MOD/system.prop
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Proper permissions for generated items
|
|
||||||
find $TMPDIR -exec chcon -h u:object_r:system_file:s0 {} \;
|
|
||||||
|
|
||||||
# linker(64), t*box required for bin
|
|
||||||
if [ -f $MOUNTINFO/dummy/system/bin ]; then
|
|
||||||
cp -afc /system/bin/linker* /system/bin/t*box $DUMMDIR/system/bin/
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start doing tasks
|
|
||||||
|
|
||||||
# Stage 1
|
|
||||||
log_print "* Stage 1: Mount system and vendor mirrors"
|
|
||||||
SYSTEMBLOCK=`mount | grep " /system " | awk '{print $1}'`
|
|
||||||
mkdir -p $MIRRDIR/system
|
|
||||||
mount -o ro $SYSTEMBLOCK $MIRRDIR/system
|
|
||||||
if [ `mount | grep -c " /vendor "` -ne 0 ]; then
|
|
||||||
VENDORBLOCK=`mount | grep " /vendor " | awk '{print $1}'`
|
|
||||||
mkdir -p $MIRRDIR/vendor
|
|
||||||
mount -o ro $VENDORBLOCK $MIRRDIR/vendor
|
|
||||||
else
|
|
||||||
ln -sf $MIRRDIR/system/vendor $MIRRDIR/vendor
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Since mirrors always exist, we load libraries and binaries from mirrors
|
|
||||||
export LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib
|
|
||||||
[ -d $MIRRDIR/system/lib64 ] && export LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64
|
|
||||||
|
|
||||||
# Stage 2
|
|
||||||
log_print "* Stage 2: Mount dummy skeletons"
|
|
||||||
# Move /system/vendor to /vendor for consistency
|
|
||||||
mv -f $MOUNTINFO/dummy/system/vendor $MOUNTINFO/dummy/vendor 2>/dev/null
|
|
||||||
mv -f $DUMMDIR/system/vendor $DUMMDIR/vendor 2>/dev/null
|
|
||||||
find $MOUNTINFO/dummy -type f 2>/dev/null | while read ITEM ; do
|
|
||||||
TARGET="${ITEM#$MOUNTINFO/dummy}"
|
|
||||||
ORIG="$DUMMDIR$TARGET"
|
|
||||||
(clone_dummy "$TARGET")
|
|
||||||
bind_mount "$ORIG" "$TARGET"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check if the dummy /system/bin is empty, it shouldn't
|
|
||||||
[ -e $DUMMDIR/system/bin -a ! -e $DUMMDIR/system/bin/sh ] && clone_dummy /system/bin
|
|
||||||
|
|
||||||
# Stage 3
|
|
||||||
log_print "* Stage 3: Mount module items"
|
|
||||||
find $MOUNTINFO/system $MOUNTINFO/vendor -type f 2>/dev/null | while read ITEM ; do
|
|
||||||
TARGET="${ITEM#$MOUNTINFO}"
|
|
||||||
ORIG="`cat "$ITEM"`$TARGET"
|
|
||||||
bind_mount "$ORIG" "$TARGET"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Stage 4
|
|
||||||
log_print "* Stage 4: Execute module scripts"
|
|
||||||
module_scripts post-fs-data
|
|
||||||
|
|
||||||
# Stage 5
|
|
||||||
log_print "* Stage 5: Mount mirrored items back to dummy"
|
|
||||||
find $MOUNTINFO/mirror -type f 2>/dev/null | while read ITEM ; do
|
|
||||||
TARGET="${ITEM#$MOUNTINFO/mirror}"
|
|
||||||
ORIG="$MIRRDIR$TARGET"
|
|
||||||
bind_mount "$ORIG" "$TARGET"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Restart post-fs-data if necessary (multirom)
|
|
||||||
$MULTIROM && setprop magisk.restart_pfsd 1
|
|
||||||
|
|
||||||
fi
|
|
||||||
unblock
|
|
||||||
;;
|
|
||||||
|
|
||||||
mount_busybox )
|
|
||||||
log_print "* Enabling BusyBox"
|
|
||||||
cp -afc /system/xbin/. $TOOLPATH
|
|
||||||
umount /system/xbin 2>/dev/null
|
|
||||||
bind_mount $TOOLPATH /system/xbin
|
|
||||||
;;
|
|
||||||
|
|
||||||
service )
|
|
||||||
# Version info
|
|
||||||
MAGISK_VERSION_STUB
|
|
||||||
log_print "** Magisk late_start service mode running..."
|
|
||||||
|
|
||||||
# Bind hosts for Adblock apps
|
|
||||||
if [ -f $COREDIR/hosts ]; then
|
|
||||||
log_print "* Enabling systemless hosts file support"
|
|
||||||
bind_mount $COREDIR/hosts /system/etc/hosts
|
|
||||||
fi
|
|
||||||
# Expose busybox
|
|
||||||
[ "`getprop persist.magisk.busybox`" = "1" ] && sh /sbin/magic_mask.sh mount_busybox
|
|
||||||
|
|
||||||
# Live patch sepolicy
|
|
||||||
$MAGISKBIN/magiskpolicy --live --magisk
|
|
||||||
|
|
||||||
log_print "* Linking binaries to /sbin"
|
|
||||||
mount -o rw,remount rootfs /
|
|
||||||
chmod 755 /sbin
|
|
||||||
ln -sf $MAGISKBIN/magiskpolicy /sbin/magiskpolicy
|
|
||||||
ln -sf $MAGISKBIN/magiskpolicy /sbin/sepolicy-inject
|
|
||||||
ln -sf $MAGISKBIN/resetprop /sbin/resetprop
|
|
||||||
if [ ! -f /sbin/launch_daemonsu.sh ]; then
|
|
||||||
log_print "* Starting MagiskSU"
|
|
||||||
export PATH=$OLDPATH
|
|
||||||
ln -sf $MAGISKBIN/su /sbin/su
|
|
||||||
ln -sf $MAGISKBIN/magiskpolicy /sbin/supolicy
|
|
||||||
/sbin/su --daemon
|
|
||||||
export PATH=$TOOLPATH:$OLDPATH
|
|
||||||
fi
|
|
||||||
mount -o ro,remount rootfs /
|
|
||||||
|
|
||||||
log_print "* Running service.d"
|
|
||||||
general_scripts service
|
|
||||||
|
|
||||||
# Start MagiskHide
|
|
||||||
if [ "`getprop persist.magisk.hide`" = "1" ]; then
|
|
||||||
log_print "* Starting MagiskHide"
|
|
||||||
sh $COREDIR/magiskhide/enable
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f $DISABLEFILE ]; then
|
|
||||||
# Let MagiskManager know
|
|
||||||
setprop ro.magisk.disable 1
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
module_scripts service
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
@ -13,8 +13,10 @@ SYSTEMLIB=/system/lib
|
|||||||
# Default permissions
|
# Default permissions
|
||||||
umask 022
|
umask 022
|
||||||
|
|
||||||
ui_print_wrapper() {
|
# Call ui_print_wrap if exists, or else simply use echo
|
||||||
type ui_print >/dev/null && ui_print "$1" || echo "$1"
|
# Useful when wrapped in flashable zip
|
||||||
|
ui_print_wrap() {
|
||||||
|
type ui_print >/dev/null 2>&1 && ui_print "$1" || echo "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
grep_prop() {
|
grep_prop() {
|
||||||
@ -48,20 +50,20 @@ chmod -R 755 $CHROMEDIR/futility $MAGISKBIN 2>/dev/null
|
|||||||
# Find the boot image
|
# Find the boot image
|
||||||
find_boot_image
|
find_boot_image
|
||||||
if [ -z "$BOOTIMAGE" ]; then
|
if [ -z "$BOOTIMAGE" ]; then
|
||||||
ui_print_wrapper "! Unable to detect boot image"
|
ui_print_wrap "! Unable to detect boot image"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ui_print_wrapper "- Found Boot Image: $BOOTIMAGE"
|
ui_print_wrap "- Found Boot Image: $BOOTIMAGE"
|
||||||
|
|
||||||
rm -rf $BOOTTMP 2>/dev/null
|
rm -rf $BOOTTMP 2>/dev/null
|
||||||
mkdir -p $BOOTTMP
|
mkdir -p $BOOTTMP
|
||||||
cd $BOOTTMP
|
cd $BOOTTMP
|
||||||
|
|
||||||
ui_print_wrapper "- Unpacking boot image"
|
ui_print_wrap "- Unpacking boot image"
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --unpack $BOOTIMAGE
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --unpack $BOOTIMAGE
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
ui_print_wrapper "! Unable to unpack boot image"
|
ui_print_wrap "! Unable to unpack boot image"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -77,8 +79,8 @@ fi
|
|||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-test ramdisk.cpio
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-test ramdisk.cpio
|
||||||
case $? in
|
case $? in
|
||||||
0 )
|
0 )
|
||||||
ui_print_wrapper "! Magisk is not installed!"
|
ui_print_wrap "! Magisk is not installed!"
|
||||||
ui_print_wrapper "! Nothing to uninstall"
|
ui_print_wrap "! Nothing to uninstall"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
1 )
|
1 )
|
||||||
@ -90,17 +92,17 @@ case $? in
|
|||||||
rm -f init.magisk.rc
|
rm -f init.magisk.rc
|
||||||
fi
|
fi
|
||||||
if [ -f ${STOCKDUMP}.gz ]; then
|
if [ -f ${STOCKDUMP}.gz ]; then
|
||||||
ui_print_wrapper "- Boot image backup found!"
|
ui_print_wrap "- Boot image backup found!"
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
||||||
else
|
else
|
||||||
ui_print_wrapper "! Boot image backup unavailable"
|
ui_print_wrap "! Boot image backup unavailable"
|
||||||
ui_print_wrapper "- Restoring ramdisk with backup"
|
ui_print_wrap "- Restoring ramdisk with backup"
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-restore ramdisk.cpio
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-restore ramdisk.cpio
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --repack $BOOTIMAGE stock_boot.img
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --repack $BOOTIMAGE stock_boot.img
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
2 )
|
2 )
|
||||||
ui_print_wrapper "- SuperSU patched image detected"
|
ui_print_wrap "- SuperSU patched image detected"
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-restore ramdisk.cpio
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-restore ramdisk.cpio
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --repack $BOOTIMAGE stock_boot.img
|
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --repack $BOOTIMAGE stock_boot.img
|
||||||
;;
|
;;
|
||||||
@ -115,11 +117,11 @@ if [ -f chromeos ]; then
|
|||||||
mv stock_boot.img.signed stock_boot.img
|
mv stock_boot.img.signed stock_boot.img
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ui_print_wrapper "- Flashing stock/reverted image"
|
ui_print_wrap "- Flashing stock/reverted image"
|
||||||
[ ! -L "$BOOTIMAGE" ] && dd if=/dev/zero of=$BOOTIMAGE bs=4096 2>/dev/null
|
[ ! -L "$BOOTIMAGE" ] && dd if=/dev/zero of=$BOOTIMAGE bs=4096 2>/dev/null
|
||||||
dd if=stock_boot.img of=$BOOTIMAGE bs=4096
|
dd if=stock_boot.img of=$BOOTIMAGE bs=4096
|
||||||
|
|
||||||
ui_print_wrapper "- Removing Magisk files"
|
ui_print_wrap "- Removing Magisk files"
|
||||||
rm -rf /cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk \
|
rm -rf /cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk \
|
||||||
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh \
|
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh \
|
||||||
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img \
|
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img \
|
||||||
|
@ -1,133 +0,0 @@
|
|||||||
#!/sbin/sh
|
|
||||||
##########################################################################################
|
|
||||||
#
|
|
||||||
# Magisk Uninstaller
|
|
||||||
# by topjohnwu
|
|
||||||
#
|
|
||||||
# This zip will remove all Magisk related files and revert boot image
|
|
||||||
#
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
INSTALLER=/tmp/uninstall
|
|
||||||
|
|
||||||
# Default permissions
|
|
||||||
umask 022
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Flashable update-binary preparation
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
OUTFD=$2
|
|
||||||
ZIP=$3
|
|
||||||
|
|
||||||
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
OUTFD=0
|
|
||||||
|
|
||||||
for FD in `ls /proc/$$/fd`; do
|
|
||||||
readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
ps | grep " 3 $FD " | grep -v grep >/dev/null
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
OUTFD=$FD
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p $INSTALLER
|
|
||||||
cd $INSTALLER
|
|
||||||
unzip -o "$ZIP"
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Functions
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
ui_print() {
|
|
||||||
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
|
|
||||||
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
|
|
||||||
}
|
|
||||||
|
|
||||||
is_mounted() {
|
|
||||||
if [ ! -z "$2" ]; then
|
|
||||||
cat /proc/mounts | grep $1 | grep $2, >/dev/null
|
|
||||||
else
|
|
||||||
cat /proc/mounts | grep $1 >/dev/null
|
|
||||||
fi
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
grep_prop() {
|
|
||||||
REGEX="s/^$1=//p"
|
|
||||||
shift
|
|
||||||
FILES=$@
|
|
||||||
if [ -z "$FILES" ]; then
|
|
||||||
FILES='/system/build.prop'
|
|
||||||
fi
|
|
||||||
cat $FILES 2>/dev/null | sed -n $REGEX | head -n 1
|
|
||||||
}
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Main
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
ui_print "*****************************"
|
|
||||||
ui_print " Magisk Uninstaller "
|
|
||||||
ui_print "*****************************"
|
|
||||||
|
|
||||||
if [ ! -d "$INSTALLER/arm" ]; then
|
|
||||||
ui_print "! Failed: Unable to extract zip file!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ui_print "- Mounting /system(ro), /cache, /data"
|
|
||||||
mount -o ro /system 2>/dev/null
|
|
||||||
mount /cache 2>/dev/null
|
|
||||||
mount /data 2>/dev/null
|
|
||||||
|
|
||||||
if [ ! -f '/system/build.prop' ]; then
|
|
||||||
ui_print "! Failed: /system could not be mounted!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
API=`grep_prop ro.build.version.sdk`
|
|
||||||
ABI=`grep_prop ro.product.cpu.abi | cut -c-3`
|
|
||||||
ABI2=`grep_prop ro.product.cpu.abi2 | cut -c-3`
|
|
||||||
ABILONG=`grep_prop ro.product.cpu.abi`
|
|
||||||
|
|
||||||
ARCH=arm
|
|
||||||
IS64BIT=false
|
|
||||||
if [ "$ABI" = "x86" ]; then ARCH=x86; fi;
|
|
||||||
if [ "$ABI2" = "x86" ]; then ARCH=x86; fi;
|
|
||||||
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; IS64BIT=true; fi;
|
|
||||||
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; IS64BIT=true; fi;
|
|
||||||
|
|
||||||
ui_print "- Device platform: $ARCH"
|
|
||||||
CHROMEDIR=$INSTALLER/chromeos
|
|
||||||
BINDIR=$INSTALLER/$ARCH
|
|
||||||
|
|
||||||
# Copy the binaries to /data/magisk
|
|
||||||
mkdir -p /data/magisk 2>/dev/null
|
|
||||||
cp -af $BINDIR/* $CHROMEDIR /data/magisk
|
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
# Detection all done, start installing
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
if (is_mounted /data); then
|
|
||||||
. $INSTALLER/common/magisk_uninstaller.sh
|
|
||||||
else
|
|
||||||
ui_print "! Data unavailable"
|
|
||||||
ui_print "! Placing uninstall script to /cache"
|
|
||||||
ui_print "! The device might reboot multiple times"
|
|
||||||
cp -af $INSTALLER/common/magisk_uninstaller.sh /cache/magisk_uninstaller.sh
|
|
||||||
umount /system
|
|
||||||
ui_print "- Rebooting....."
|
|
||||||
sleep 5
|
|
||||||
reboot
|
|
||||||
fi
|
|
||||||
|
|
||||||
umount /system
|
|
||||||
ui_print "- Done"
|
|
||||||
exit 0
|
|
@ -1 +0,0 @@
|
|||||||
# this is a dummy file, the magic is in update-binary
|
|
@ -1 +0,0 @@
|
|||||||
#MAGISK
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
/magisk(/.*)? u:object_r:system_file:s0
|
|
Binary file not shown.
@ -1,5 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
PROCESS="$1"
|
|
||||||
|
|
||||||
magiskhide --add "$PROCESS"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
magiskhide --disable
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
magiskhide --enable
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
magiskhide --ls
|
|
@ -1,5 +0,0 @@
|
|||||||
#!/system/bin/sh
|
|
||||||
|
|
||||||
PROCESS="$1"
|
|
||||||
|
|
||||||
magiskhide --rm "$PROCESS"
|
|
@ -162,10 +162,6 @@ static int xdecompress(int fdIn, int fdOut, off_t offsetIn, off_t offsetOut, siz
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
strm.avail_in = read(fdIn, in, CHUNK);
|
strm.avail_in = read(fdIn, in, CHUNK);
|
||||||
if (strm.avail_in < 0) {
|
|
||||||
(void)inflateEnd(&strm);
|
|
||||||
return xerror("Read failed");
|
|
||||||
}
|
|
||||||
if (strm.avail_in == 0) break;
|
if (strm.avail_in == 0) break;
|
||||||
strm.next_in = in;
|
strm.next_in = in;
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user