Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
3d43c3c5
Commit
3d43c3c5
authored
Jul 09, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scripts
parent
b570b363
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
199 additions
and
197 deletions
+199
-197
build.py
build.py
+11
-0
addon.d.sh
scripts/addon.d.sh
+2
-2
boot_patch.sh
scripts/boot_patch.sh
+16
-2
flash_script.sh
scripts/flash_script.sh
+23
-45
magisk_uninstaller.sh
scripts/magisk_uninstaller.sh
+52
-69
uninstaller_loader.sh
scripts/uninstaller_loader.sh
+34
-78
util_functions.sh
scripts/util_functions.sh
+61
-1
No files found.
build.py
View file @
3d43c3c5
...
@@ -219,6 +219,10 @@ def zip_uninstaller(args):
...
@@ -219,6 +219,10 @@ def zip_uninstaller(args):
target
=
'magisk_uninstaller.sh'
target
=
'magisk_uninstaller.sh'
zip_with_msg
(
zipf
,
source
,
target
)
zip_with_msg
(
zipf
,
source
,
target
)
source
=
os
.
path
.
join
(
'scripts'
,
'util_functions.sh'
)
target
=
'util_functions.sh'
zip_with_msg
(
zipf
,
source
,
target
)
source
=
os
.
path
.
join
(
'scripts'
,
'uninstaller_loader.sh'
)
source
=
os
.
path
.
join
(
'scripts'
,
'uninstaller_loader.sh'
)
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'update-binary'
)
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'update-binary'
)
zip_with_msg
(
zipf
,
source
,
target
)
zip_with_msg
(
zipf
,
source
,
target
)
...
@@ -227,6 +231,13 @@ def zip_uninstaller(args):
...
@@ -227,6 +231,13 @@ def zip_uninstaller(args):
print
(
'zip: '
+
target
)
print
(
'zip: '
+
target
)
zipf
.
writestr
(
target
,
'#MAGISK
\n
'
)
zipf
.
writestr
(
target
,
'#MAGISK
\n
'
)
# 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-uninstaller-{}.zip'
.
format
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y
%
m
%
d'
))
output
=
'Magisk-uninstaller-{}.zip'
.
format
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y
%
m
%
d'
))
sign_adjust_zip
(
'tmp_unsigned.zip'
,
output
)
sign_adjust_zip
(
'tmp_unsigned.zip'
,
output
)
...
...
scripts/addon.d.sh
View file @
3d43c3c5
...
@@ -28,7 +28,7 @@ main() {
...
@@ -28,7 +28,7 @@ main() {
mount
-o
ro /vendor 2>/dev/null
mount
-o
ro /vendor 2>/dev/null
mount /data 2>/dev/null
mount /data 2>/dev/null
# Load
all
functions
# Load
utility
functions
.
$MAGISKBIN
/util_functions.sh
.
$MAGISKBIN
/util_functions.sh
[
-f
/system/build.prop
]
||
abort
"! /system could not be mounted!"
[
-f
/system/build.prop
]
||
abort
"! /system could not be mounted!"
...
@@ -57,7 +57,7 @@ main() {
...
@@ -57,7 +57,7 @@ main() {
if
[
-L
"
$BOOTIMAGE
"
]
;
then
if
[
-L
"
$BOOTIMAGE
"
]
;
then
dd
if
=
new-boot.img
of
=
"
$BOOTIMAGE
"
bs
=
4096
dd
if
=
new-boot.img
of
=
"
$BOOTIMAGE
"
bs
=
4096
else
else
cat
new-boot.img /dev/zero |
dd
of
=
"
$BOOTIMAGE
"
bs
=
4096
cat
new-boot.img /dev/zero |
dd
of
=
"
$BOOTIMAGE
"
bs
=
4096
>
/dev/null 2>&1
fi
fi
rm
-f
new-boot.img
rm
-f
new-boot.img
...
...
scripts/boot_patch.sh
View file @
3d43c3c5
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
# Magisk Boot Image Patcher
# Magisk Boot Image Patcher
# by topjohnwu
# by topjohnwu
#
#
# This script should be placed in a directory with
at least
the following files:
# This script should be placed in a directory with the following files:
#
#
# File name type Description
# File name type Description
#
#
...
@@ -14,9 +14,11 @@
...
@@ -14,9 +14,11 @@
# magisk binary The main binary for all Magisk operations.
# magisk binary The main binary for all Magisk operations.
# It is also used to patch the sepolicy in the ramdisk.
# It is also used to patch the sepolicy in the ramdisk.
# magiskboot binary A tool to unpack boot image, decompress ramdisk, extract ramdisk
# magiskboot binary A tool to unpack boot image, decompress ramdisk, extract ramdisk
#
and patch common patches such as forceencrypt, remove dm-verity.
#
, and patch the ramdisk for Magisk support
# init.magisk.rc script A new line will be added to init.rc to import this script.
# init.magisk.rc script A new line will be added to init.rc to import this script.
# All magisk entrypoints are defined here
# All magisk entrypoints are defined here
# chromeos folder This folder should store all the utilities and keys to sign
# (optional) a chromeos device, used in the tablet Pixel C
#
#
# If the script is not running as root, then the input boot image should be a stock image
# 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
# or have a backup included in ramdisk internally, since we cannot access the stock boot
...
@@ -231,4 +233,16 @@ A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
...
@@ -231,4 +233,16 @@ A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
ui_print_wrap
"- Repacking boot image"
ui_print_wrap
"- Repacking boot image"
./magiskboot
--repack
"
$BOOTIMAGE
"
||
abort_wrap
"! Unable to repack boot image!"
./magiskboot
--repack
"
$BOOTIMAGE
"
||
abort_wrap
"! Unable to repack boot image!"
# Sign chromeos boot
if
[
-f
chromeos
]
;
then
echo
>
empty
./chromeos/futility vbutil_kernel
--pack
new-boot.img.signed
\
--keyblock
./chromeos/kernel.keyblock
--signprivate
./chromeos/kernel_data_key.vbprivk
\
--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
fi
./magiskboot
--cleanup
./magiskboot
--cleanup
scripts/flash_script.sh
View file @
3d43c3c5
...
@@ -9,6 +9,10 @@
...
@@ -9,6 +9,10 @@
#
#
##########################################################################################
##########################################################################################
##########################################################################################
# Preparation
##########################################################################################
# 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
2>/dev/null |
grep
zygote |
grep
-v
grep
>
/dev/null
&&
BOOTMODE
=
true
$BOOTMODE
||
ps
-A
2>/dev/null |
grep
zygote |
grep
-v
grep
>
/dev/null
&&
BOOTMODE
=
true
...
@@ -16,7 +20,7 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO
...
@@ -16,7 +20,7 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO
# This path should work in any cases
# This path should work in any cases
TMPDIR
=
/dev/tmp
TMPDIR
=
/dev/tmp
INSTALLER
=
$TMPDIR
/
magisk
INSTALLER
=
$TMPDIR
/
install
COMMONDIR
=
$INSTALLER
/common
COMMONDIR
=
$INSTALLER
/common
CHROMEDIR
=
$INSTALLER
/chromeos
CHROMEDIR
=
$INSTALLER
/chromeos
COREDIR
=
/magisk/.core
COREDIR
=
/magisk/.core
...
@@ -24,45 +28,27 @@ COREDIR=/magisk/.core
...
@@ -24,45 +28,27 @@ COREDIR=/magisk/.core
# Default permissions
# Default permissions
umask
022
umask
022
##########################################################################################
# Flashable update-binary preparation
##########################################################################################
OUTFD
=
$2
OUTFD
=
$2
ZIP
=
$3
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
rm
-rf
$TMPDIR
2>/dev/null
rm
-rf
$TMPDIR
2>/dev/null
mkdir
-p
$INSTALLER
mkdir
-p
$INSTALLER
unzip
-o
"
$ZIP
"
-d
$INSTALLER
unzip
-o
"
$ZIP
"
-d
$INSTALLER
2>/dev/null
##########################################################################################
# Detection
##########################################################################################
if
[
!
-d
"
$COMMONDIR
"
]
;
then
if
[
!
-d
"
$COMMONDIR
"
]
;
then
echo
"! Unable to extract zip file!"
echo
"! Unable to extract zip file!"
exit
1
exit
1
fi
fi
# Load
all
fuctions
# Load
utility
fuctions
.
$COMMONDIR
/util_functions.sh
.
$COMMONDIR
/util_functions.sh
get_outfd
##########################################################################################
# Detection
##########################################################################################
ui_print
"************************"
ui_print
"************************"
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"************************"
ui_print
"************************"
...
@@ -108,6 +94,7 @@ is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
...
@@ -108,6 +94,7 @@ is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
rm
-rf
$MAGISKBIN
2>/dev/null
rm
-rf
$MAGISKBIN
2>/dev/null
mkdir
-p
$MAGISKBIN
mkdir
-p
$MAGISKBIN
cp
-af
$BINDIR
/.
$COMMONDIR
/.
$MAGISKBIN
cp
-af
$BINDIR
/.
$COMMONDIR
/.
$MAGISKBIN
cp
-af
$CHROMEDIR
$MAGISKBIN
chmod
-R
755
$MAGISKBIN
chmod
-R
755
$MAGISKBIN
# addon.d
# addon.d
...
@@ -125,7 +112,7 @@ fi
...
@@ -125,7 +112,7 @@ fi
$BOOTMODE
||
recovery_actions
$BOOTMODE
||
recovery_actions
# Fix SuperSU.....
# Fix SuperSU.....
$BOOTMODE
&&
$
BINDIR
/magisk magiskpolicy
--live
"allow fsck * * *"
$BOOTMODE
&&
$
MAGISKBIN
/magisk magiskpolicy
--live
"allow fsck * * *"
if
(
is_mounted /data
)
;
then
if
(
is_mounted /data
)
;
then
IMG
=
/data/magisk.img
IMG
=
/data/magisk.img
...
@@ -138,12 +125,12 @@ if [ -f $IMG ]; then
...
@@ -138,12 +125,12 @@ if [ -f $IMG ]; then
ui_print
"-
$IMG
detected!"
ui_print
"-
$IMG
detected!"
else
else
ui_print
"- Creating
$IMG
"
ui_print
"- Creating
$IMG
"
$
BINDIR
/magisk
--createimg
$IMG
64M
$
MAGISKBIN
/magisk
--createimg
$IMG
64M
fi
fi
if
!
is_mounted /magisk
;
then
if
!
is_mounted /magisk
;
then
ui_print
"- Mounting
$IMG
to /magisk"
ui_print
"- Mounting
$IMG
to /magisk"
MAGISKLOOP
=
`
$
BINDIR
/magisk
--mountimg
$IMG
/magisk
`
MAGISKLOOP
=
`
$
MAGISKBIN
/magisk
--mountimg
$IMG
/magisk
`
fi
fi
is_mounted /magisk
||
abort
"! Magisk image mount failed..."
is_mounted /magisk
||
abort
"! Magisk image mount failed..."
...
@@ -165,10 +152,10 @@ ui_print "- Found Boot Image: $BOOTIMAGE"
...
@@ -165,10 +152,10 @@ ui_print "- Found Boot Image: $BOOTIMAGE"
# 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
=
`
$
BINDIR
/magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
SHA1
=
`
$
MAGISKBIN
/magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
mv
/data/stock_boot.img
$STOCKDUMP
mv
/data/stock_boot.img
$STOCKDUMP
$
BINDIR
/magiskboot
--compress
$STOCKDUMP
$
MAGISKBIN
/magiskboot
--compress
$STOCKDUMP
fi
fi
SOURCEDMODE
=
true
SOURCEDMODE
=
true
...
@@ -177,20 +164,11 @@ cd $MAGISKBIN
...
@@ -177,20 +164,11 @@ cd $MAGISKBIN
# Source the boot patcher
# Source the boot patcher
.
$COMMONDIR
/boot_patch.sh
"
$BOOTIMAGE
"
.
$COMMONDIR
/boot_patch.sh
"
$BOOTIMAGE
"
# Sign chromeos boot
if
[
-f
stock_boot
*
]
;
then
if
[
-f
chromeos
]
;
then
rm
-f
/data/stock_boot
*
2>/dev/null
echo
>
empty
mv
stock_boot
*
/data
$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
empty
--arch
arm
--bootloader
empty
--flags
0x1
rm
-f
empty new-boot.img
mv
new-boot.img.signed new-boot.img
fi
fi
[
-f
stock_boot
*
]
&&
rm
-f
/data/stock_boot
*
2>/dev/null
ui_print
"- Flashing new boot image"
ui_print
"- Flashing new boot image"
if
[
-L
"
$BOOTIMAGE
"
]
;
then
if
[
-L
"
$BOOTIMAGE
"
]
;
then
dd
if
=
new-boot.img
of
=
"
$BOOTIMAGE
"
bs
=
4096
dd
if
=
new-boot.img
of
=
"
$BOOTIMAGE
"
bs
=
4096
...
@@ -202,7 +180,7 @@ rm -f new-boot.img
...
@@ -202,7 +180,7 @@ rm -f new-boot.img
cd
/
cd
/
if
!
$BOOTMODE
;
then
if
!
$BOOTMODE
;
then
$
BINDIR
/magisk
--umountimg
/magisk
$MAGISKLOOP
$
MAGISKBIN
/magisk
--umountimg
/magisk
$MAGISKLOOP
rmdir
/magisk
rmdir
/magisk
recovery_cleanup
recovery_cleanup
fi
fi
...
...
scripts/magisk_uninstaller.sh
View file @
3d43c3c5
...
@@ -8,120 +8,103 @@
...
@@ -8,120 +8,103 @@
# The Magisk main binary will pick up the script, and uninstall itself, following a reboot
# The Magisk main binary will pick up the script, and uninstall itself, following a reboot
# This script can also be used in flashable zip with the uninstaller_loader.sh
# This script can also be used in flashable zip with the uninstaller_loader.sh
#
#
# This script will try to do restoration in the following order:
# This script will try to do restoration with the following:
# 1. Find and restore the original stock boot image dump (OTA proof)
# 1-1. Find and restore the original stock boot image dump (OTA proof)
# 2. Restore ramdisk from the internal backup (ramdisk fully restored, not OTA friendly)
# 1-2. If 1-1 fails, restore ramdisk from the internal backup
# 3. Remove added files in ramdisk, modified files are remained intact. By doing so, Magisk
# (ramdisk fully restored, not OTA friendly)
# will not be started at boot, but not removed clean enough
# 1-3. If 1-2 fails, it will remove added files in ramdisk, however modified files
#
# are remained modified, because we have no backups. By doing so, Magisk will
# Finally, this uninstaller will remove all Magisk related files
# not be started at boot, but this isn't actually 100% cleaned up
# (The list is LARGE, most likely due to bad decision in early versions
# 2. Remove all Magisk related files
# the latest versions has much less bloat to cleanup)
# (The list is LARGE, most likely due to bad decision in early versions
# the latest versions has much less bloat to cleanup)
#
#
##########################################################################################
##########################################################################################
[
-z
$BOOTMODE
]
&&
BOOTMODE
=
false
MAGISKBIN
=
/data/magisk
CHROMEDIR
=
$MAGISKBIN
/chromeos
[
-d
/system/lib64
]
&&
SYSTEMLIB
=
/system/lib64
||
SYSTEMLIB
=
/system/lib
# Default permissions
umask
022
# Call ui_print_wrap if exists, or else simply use echo
# Call ui_print_wrap if exists, or else simply use echo
# Useful when wrapped in flashable zip
# Useful when wrapped in flashable zip
ui_print_wrap
()
{
ui_print_wrap
()
{
type
ui_print
>
/dev/null 2>&1
&&
ui_print
"
$1
"
||
echo
"
$1
"
type
ui_print
>
/dev/null 2>&1
&&
ui_print
"
$1
"
||
echo
"
$1
"
}
}
grep_prop
()
{
# Call abort if exists, or else show error message and exit
REGEX
=
"s/^
$1
=//p"
# Essential when wrapped in flashable zip
shift
abort_wrap
()
{
FILES
=
$@
type
abort
>
/dev/null 2>&1
if
[
-z
"
$FILES
"
]
;
then
if
[
$?
-ne
0
]
;
then
FILES
=
'/system/build.prop'
ui_print_wrap
"
$1
"
exit
1
else
abort
"
$1
"
fi
fi
cat
$FILES
2>/dev/null |
sed
-n
"
$REGEX
"
|
head
-n
1
}
}
find_boot_image
()
{
if
[
!
-d
$MAGISKBIN
-o
!
-f
$MAGISKBIN
/magiskboot
-o
!
-f
$MAGISKBIN
/util_functions.sh
]
;
then
if
[
-z
"
$BOOTIMAGE
"
]
;
then
ui_print_wrap
"! Cannot find
$MAGISKBIN
"
for
PARTITION
in
kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX
;
do
exit
1
BOOTIMAGE
=
`
readlink
/dev/block/by-name/
$PARTITION
||
readlink
/dev/block/platform/
*
/by-name/
$PARTITION
||
readlink
/dev/block/platform/
*
/
*
/by-name/
$PARTITION
`
fi
if
[
!
-z
"
$BOOTIMAGE
"
]
;
then
break
;
fi
done
[
-z
$BOOTMODE
]
&&
BOOTMODE
=
false
fi
if
[
-z
"
$BOOTIMAGE
"
]
;
then
MAGISKBIN
=
/data/magisk
FSTAB
=
"/etc/recovery.fstab"
CHROMEDIR
=
$MAGISKBIN
/chromeos
[
!
-f
"
$FSTAB
"
]
&&
FSTAB
=
"/etc/recovery.fstab.bak"
[
-f
"
$FSTAB
"
]
&&
BOOTIMAGE
=
`
grep
-E
'\b/boot\b'
"
$FSTAB
"
|
grep
-oE
'/dev/[a-zA-Z0-9_./-]*'
`
fi
}
# Environments
# Default permissions
# Set permissions
umask
022
chmod
-R
755
$CHROMEDIR
/futility
$MAGISKBIN
2>/dev/null
# Load utility functions
.
$MAGISKBIN
/util_functions.sh
# Find the boot image
# Find the boot image
find_boot_image
find_boot_image
if
[
-z
"
$BOOTIMAGE
"
]
;
then
[
-z
$BOOTIMAGE
]
&&
abort
"! Unable to detect boot image"
ui_print_wrap
"! Unable to detect boot image"
exit
1
fi
ui_print_wrap
"- Found Boot Image:
$BOOTIMAGE
"
ui_print_wrap
"- Found Boot Image:
$BOOTIMAGE
"
cd
$MAGISKBIN
cd
$MAGISKBIN
ui_print_wrap
"- Unpacking boot image"
ui_print_wrap
"- Unpacking boot image"
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--unpack
$BOOTIMAGE
./magiskboot
--unpack
"
$BOOTIMAGE
"
if
[
$?
-ne
0
]
;
then
[
$?
-ne
0
]
&&
abort_wrap
"! Unable to unpack boot image"
ui_print_wrap
"! Unable to unpack boot image"
exit
1
fi
# Update our previous backup
s
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
./magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
SHA1
=
`
./magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
mv
/data/stock_boot.img
$STOCKDUMP
mv
/data/stock_boot.img
$STOCKDUMP
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--compress
$STOCKDUMP
./magiskboot
--compress
$STOCKDUMP
fi
fi
# Detect boot image state
# Detect boot image state
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--cpio-test
ramdisk.cpio
./magiskboot
--cpio-test
ramdisk.cpio
case
$?
in
case
$?
in
0
)
0
)
# Stock boot
ui_print_wrap
"- Stock boot image detected!"
ui_print_wrap
"- Stock boot image detected!"
ui_print_wrap
"! Magisk is not installed!"
ui_print_wrap
"! Magisk is not installed!"
exit
exit
;;
;;
1
)
1
)
# Magisk patched
ui_print_wrap
"- Magisk patched image detected!"
ui_print_wrap
"- Magisk patched image detected!"
# Find SHA1 of stock boot image
# Find SHA1 of stock boot image
if
[
-z
$SHA1
]
;
then
if
[
-z
$SHA1
]
;
then
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--cpio-extract
ramdisk.cpio init.magisk.rc init.magisk.rc.old
./magiskboot
--cpio-extract
ramdisk.cpio init.magisk.rc init.magisk.rc.old
SHA1
=
`
grep_prop
"# STOCKSHA1"
init.magisk.rc.old
`
SHA1
=
`
grep_prop
"# STOCKSHA1"
init.magisk.rc.old
`
[
!
-z
$SHA1
]
&&
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
rm
-f
init.magisk.rc.old
rm
-f
init.magisk.rc.old
fi
fi
[
!
-z
$SHA1
]
&&
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
if
[
-f
${
STOCKDUMP
}
.gz
]
;
then
if
[
-f
${
STOCKDUMP
}
.gz
]
;
then
ui_print_wrap
"- Boot image backup found!"
ui_print_wrap
"- Boot image backup found!"
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--decompress
${
STOCKDUMP
}
.gz stock_boot.img
./magiskboot
--decompress
${
STOCKDUMP
}
.gz stock_boot.img
else
else
ui_print_wrap
"! Boot image backup unavailable"
ui_print_wrap
"! Boot image backup unavailable"
ui_print_wrap
"- Restoring ramdisk with backup"
ui_print_wrap
"- Restoring ramdisk with backup"
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--cpio-restore
ramdisk.cpio
./magiskboot
--cpio-restore
ramdisk.cpio
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--repack
$BOOTIMAGE
stock_boot.img
./magiskboot
--repack
$BOOTIMAGE
stock_boot.img
fi
fi
;;
;;
2
)
# Other patched
2
)
# Other patched
ui_print_wrap
"! Boot image patched by other programs!"
ui_print_wrap
"! Boot image patched by other programs!"
ui_print_wrap
"! Cannot uninstall with this uninstaller"
abort_wrap
"! Cannot uninstall with this uninstaller"
exit
1
;;
;;
esac
esac
...
@@ -138,10 +121,10 @@ if [ -f chromeos ]; then
...
@@ -138,10 +121,10 @@ if [ -f chromeos ]; then
fi
fi
ui_print_wrap
"- Flashing stock/reverted image"
ui_print_wrap
"- Flashing stock/reverted image"
if
[
-L
$BOOTIMAGE
]
;
then
if
[
-L
"
$BOOTIMAGE
"
]
;
then
dd
if
=
stock_boot.img
of
=
$BOOTIMAGE
bs
=
4096
dd
if
=
stock_boot.img
of
=
"
$BOOTIMAGE
"
bs
=
4096
else
else
cat
stock_boot.img /dev/zero |
dd
of
=
$BOOTIMAGE
bs
=
4096
cat
stock_boot.img /dev/zero |
dd
of
=
"
$BOOTIMAGE
"
bs
=
4096
>
/dev/null 2>&1
fi
fi
rm
-f
stock_boot.img
rm
-f
stock_boot.img
...
...
scripts/uninstaller_loader.sh
View file @
3d43c3c5
...
@@ -8,100 +8,49 @@
...
@@ -8,100 +8,49 @@
#
#
##########################################################################################
##########################################################################################
INSTALLER
=
/tmp/uninstall
##########################################################################################
# Preparation
##########################################################################################
BOOTMODE
=
false
INSTALLER
=
/tmp/uninstall
# Default permissions
# Default permissions
umask
022
umask
022
##########################################################################################
# Flashable update-binary preparation
##########################################################################################
OUTFD
=
$2
OUTFD
=
$2
ZIP
=
$3
ZIP
=
$3
readlink
/proc/
$$
/fd/
$OUTFD
2>/dev/null |
grep
/tmp
>
/dev/null
rm
-rf
$INSTALLER
2>/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
mkdir
-p
$INSTALLER
cd
$INSTALLER
unzip
-o
"
$ZIP
"
-d
$INSTALLER
2>/dev/null
unzip
-o
"
$ZIP
"
##########################################################################################
if
[
!
-f
$INSTALLER
/util_functions.sh
]
;
then
# Functions
echo
"! Failed: Unable to extract zip file!"
##########################################################################################
exit
1
fi
# Load utility functions
.
$INSTALLER
/util_functions.sh
ui_print
()
{
get_outfd
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
# Main
##########################################################################################
##########################################################################################
ui_print
"*****************************"
ui_print
"************************"
ui_print
" Magisk Uninstaller "
ui_print
" Magisk Uninstaller "
ui_print
"*****************************"
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"
ui_print
"- Mounting /system
, /vendor
, /cache, /data"
mount
-o
ro /system 2>/dev/null
mount
-o
ro /system 2>/dev/null
mount
-o
ro /vendor 2>/dev/null
mount /cache 2>/dev/null
mount /cache 2>/dev/null
mount /data 2>/dev/null
mount /data 2>/dev/null
if
[
!
-f
'/system/build.prop'
]
;
then
[
-f
/system/build.prop
]
||
abort
"! /system could not be mounted!"
ui_print
"! Failed: /system could not be mounted!"
exit
1
fi
API
=
`
grep_prop ro.build.version.sdk
`
api_level_arch_detect
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
"
ui_print
"- Device platform:
$ARCH
"
CHROMEDIR
=
$INSTALLER
/chromeos
CHROMEDIR
=
$INSTALLER
/chromeos
...
@@ -111,12 +60,20 @@ BINDIR=$INSTALLER/$ARCH
...
@@ -111,12 +60,20 @@ BINDIR=$INSTALLER/$ARCH
# Detection all done, start installing
# Detection all done, start installing
##########################################################################################
##########################################################################################
if
(
is_mounted /data
)
;
then
MAGISKBIN
=
/data/magisk
if
is_mounted /data
;
then
# Copy the binaries to /data/magisk, in case they do not exist
# Copy the binaries to /data/magisk, in case they do not exist
rm
-rf
/data/magisk 2>/dev/null
rm
-rf
$MAGISKBIN
2>/dev/null
mkdir
-p
/data/magisk 2>/dev/null
mkdir
-p
$MAGISKBIN
cp
-af
$BINDIR
/.
$CHROMEDIR
/data/magisk
cp
-af
$BINDIR
/.
$MAGISKBIN
cp
-af
$CHROMEDIR
$MAGISKBIN
cp
-af
$INSTALLER
/util_functions.sh
$MAGISKBIN
chmod
-R
755
$MAGISKBIN
# Run the acttual uninstallation
recovery_actions
.
$INSTALLER
/magisk_uninstaller.sh
.
$INSTALLER
/magisk_uninstaller.sh
recovery_cleanup
else
else
ui_print
"! Data unavailable"
ui_print
"! Data unavailable"
ui_print
"! Placing uninstall script to /cache"
ui_print
"! Placing uninstall script to /cache"
...
@@ -128,6 +85,5 @@ else
...
@@ -128,6 +85,5 @@ else
reboot
reboot
fi
fi
umount /system
ui_print
"- Done"
ui_print
"- Done"
exit
0
exit
0
scripts/util_functions.sh
View file @
3d43c3c5
...
@@ -3,10 +3,28 @@
...
@@ -3,10 +3,28 @@
# Magisk General Utility Functions
# Magisk General Utility Functions
# by topjohnwu
# by topjohnwu
#
#
# Used in flash_script.sh
and addon.d.sh
# Used in flash_script.sh
, addon.d.sh, magisk module installers, and uninstaller
#
#
##########################################################################################
##########################################################################################
get_outfd
()
{
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
}
ui_print
()
{
ui_print
()
{
if
$BOOTMODE
;
then
if
$BOOTMODE
;
then
echo
"
$1
"
echo
"
$1
"
...
@@ -130,3 +148,45 @@ abort() {
...
@@ -130,3 +148,45 @@ abort() {
mv
/sbin_tmp /sbin 2>/dev/null
mv
/sbin_tmp /sbin 2>/dev/null
exit
1
exit
1
}
}
set_perm
()
{
chown
$2
:
$3
$1
||
exit
1
chmod
$4
$1
||
exit
1
if
[
!
-z
$5
]
;
then
chcon
$5
$1
2>/dev/null
else
chcon
'u:object_r:system_file:s0'
$1
2>/dev/null
fi
}
set_perm_recursive
()
{
find
$1
-type
d 2>/dev/null |
while
read dir
;
do
set_perm
$dir
$2
$3
$4
$6
done
find
$1
-type
f 2>/dev/null |
while
read
file
;
do
set_perm
$file
$2
$3
$5
$6
done
}
mktouch
()
{
mkdir
-p
${
1
%/*
}
if
[
-z
"
$2
"
]
;
then
touch
$1
else
echo
$2
>
$1
fi
chmod
644
$1
}
request_size_check
()
{
reqSizeM
=
`
du
-s
$1
|
cut
-f1
`
reqSizeM
=
$((
reqSizeM
/
1024
+
1
))
}
image_size_check
()
{
SIZE
=
"
`
$MAGISKBIN
/magisk
--imgsize
$IMG
`
"
curUsedM
=
`
echo
"
$SIZE
"
|
cut
-d
" "
-f1
`
curSizeM
=
`
echo
"
$SIZE
"
|
cut
-d
" "
-f2
`
curFreeM
=
$((
curSizeM
-
curUsedM
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment