mirror of
https://github.com/topjohnwu/Magisk
synced 2024-11-13 20:54:12 +01:00
parent
30c048723c
commit
670fe8590c
@ -19,6 +19,12 @@ INSTALLER=$TMPDIR/magisk
|
|||||||
|
|
||||||
COREDIR=/magisk/.core
|
COREDIR=/magisk/.core
|
||||||
|
|
||||||
|
# Boot Image Variables
|
||||||
|
CHROMEDIR=$INSTALLER/chromeos
|
||||||
|
NEWBOOT=$TMPDIR/boottmp/new-boot.img
|
||||||
|
UNPACKDIR=$TMPDIR/boottmp/bootunpack
|
||||||
|
RAMDISK=$TMPDIR/boottmp/ramdisk
|
||||||
|
|
||||||
# Default permissions
|
# Default permissions
|
||||||
umask 022
|
umask 022
|
||||||
|
|
||||||
@ -86,7 +92,7 @@ find_boot_image() {
|
|||||||
if [ -z "$BOOTIMAGE" ]; then
|
if [ -z "$BOOTIMAGE" ]; then
|
||||||
FSTAB="/etc/recovery.fstab"
|
FSTAB="/etc/recovery.fstab"
|
||||||
[ ! -f "$FSTAB" ] && FSTAB="/etc/recovery.fstab.bak"
|
[ ! -f "$FSTAB" ] && FSTAB="/etc/recovery.fstab.bak"
|
||||||
[ -f "$FSTAB" ] BOOTIMAGE=`grep -E '\b/boot\b' "$FSTAB" | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
|
[ -f "$FSTAB" ] && BOOTIMAGE=`grep -E '\b/boot\b' "$FSTAB" | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +118,7 @@ mount_image() {
|
|||||||
if (! is_mounted $2); then
|
if (! is_mounted $2); then
|
||||||
LOOPDEVICE=/dev/block/loop$LOOP
|
LOOPDEVICE=/dev/block/loop$LOOP
|
||||||
if [ ! -f "$LOOPDEVICE" ]; then
|
if [ ! -f "$LOOPDEVICE" ]; then
|
||||||
mknod $LOOPDEVICE b 7 $LOOP
|
mknod $LOOPDEVICE b 7 $LOOP 2>/dev/null
|
||||||
fi
|
fi
|
||||||
losetup $LOOPDEVICE $1
|
losetup $LOOPDEVICE $1
|
||||||
if [ "$?" -eq "0" ]; then
|
if [ "$?" -eq "0" ]; then
|
||||||
@ -148,7 +154,7 @@ unpack_boot() {
|
|||||||
mkdir -p $UNPACKDIR
|
mkdir -p $UNPACKDIR
|
||||||
mkdir -p $RAMDISK
|
mkdir -p $RAMDISK
|
||||||
cd $UNPACKDIR
|
cd $UNPACKDIR
|
||||||
$BINDIR/bootimgtools --extract $1
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --extract $1
|
||||||
|
|
||||||
cd $RAMDISK
|
cd $RAMDISK
|
||||||
gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i
|
gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i
|
||||||
@ -158,11 +164,11 @@ repack_boot() {
|
|||||||
cd $RAMDISK
|
cd $RAMDISK
|
||||||
find . | cpio -o -H newc 2>/dev/null | gzip -9 > $UNPACKDIR/ramdisk.gz
|
find . | cpio -o -H newc 2>/dev/null | gzip -9 > $UNPACKDIR/ramdisk.gz
|
||||||
cd $UNPACKDIR
|
cd $UNPACKDIR
|
||||||
$BINDIR/bootimgtools --repack $ORIGBOOT
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --repack $ORIGBOOT
|
||||||
if [ -f chromeos ]; then
|
if [ -f chromeos ]; then
|
||||||
echo " " > config
|
echo " " > config
|
||||||
echo " " > bootloader
|
echo " " > bootloader
|
||||||
$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
|
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
|
||||||
rm -f new-boot.img
|
rm -f new-boot.img
|
||||||
mv new-boot.img.signed new-boot.img
|
mv new-boot.img.signed new-boot.img
|
||||||
fi
|
fi
|
||||||
@ -173,7 +179,7 @@ repack_boot() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
mv new-boot.img $NEWBOOT
|
mv new-boot.img $NEWBOOT
|
||||||
$BINDIR/bootimgtools --hexpatch $NEWBOOT \
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --hexpatch $NEWBOOT \
|
||||||
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
|
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
|
||||||
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
||||||
}
|
}
|
||||||
@ -251,6 +257,9 @@ ui_print "- Device platform: $ARCH"
|
|||||||
BINDIR=$INSTALLER/$ARCH
|
BINDIR=$INSTALLER/$ARCH
|
||||||
chmod -R 755 $CHROMEDIR/futility $BINDIR
|
chmod -R 755 $CHROMEDIR/futility $BINDIR
|
||||||
|
|
||||||
|
SYSTEMLIB=/system/lib
|
||||||
|
($IS64BIT) && SYSTEMLIB=/system/lib64
|
||||||
|
|
||||||
find_boot_image
|
find_boot_image
|
||||||
if [ -z "$BOOTIMAGE" ]; then
|
if [ -z "$BOOTIMAGE" ]; then
|
||||||
ui_print "! Unable to detect boot image"
|
ui_print "! Unable to detect boot image"
|
||||||
@ -277,7 +286,6 @@ if (is_mounted /data); then
|
|||||||
PATH=/data/busybox:$PATH
|
PATH=/data/busybox:$PATH
|
||||||
else
|
else
|
||||||
rm -rf /cache/data_bin 2>/dev/null
|
rm -rf /cache/data_bin 2>/dev/null
|
||||||
mkdir -p /cache/data_bin
|
|
||||||
cp -af $BINDIR /cache/data_bin
|
cp -af $BINDIR /cache/data_bin
|
||||||
cp -af $INSTALLER/common/init.magisk.rc $INSTALLER/common/magic_mask.sh /cache/data_bin
|
cp -af $INSTALLER/common/init.magisk.rc $INSTALLER/common/magic_mask.sh /cache/data_bin
|
||||||
fi
|
fi
|
||||||
@ -322,11 +330,6 @@ ui_print "- Found Boot Image: $BOOTIMAGE"
|
|||||||
rm -rf $TMPDIR/boottmp 2>/dev/null
|
rm -rf $TMPDIR/boottmp 2>/dev/null
|
||||||
mkdir -p $TMPDIR/boottmp
|
mkdir -p $TMPDIR/boottmp
|
||||||
|
|
||||||
CHROMEDIR=$INSTALLER/chromeos
|
|
||||||
NEWBOOT=$TMPDIR/boottmp/new-boot.img
|
|
||||||
UNPACKDIR=$TMPDIR/boottmp/bootunpack
|
|
||||||
RAMDISK=$TMPDIR/boottmp/ramdisk
|
|
||||||
|
|
||||||
ORIGBOOT=$BOOTIMAGE
|
ORIGBOOT=$BOOTIMAGE
|
||||||
|
|
||||||
ui_print "- Unpacking boot image"
|
ui_print "- Unpacking boot image"
|
||||||
@ -407,7 +410,7 @@ if (! $SUPERSU); then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# sepolicy patches
|
# sepolicy patches
|
||||||
$BINDIR/sepolicy-inject --magisk -P sepolicy
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/sepolicy-inject --magisk -P sepolicy
|
||||||
|
|
||||||
# Add new items
|
# Add new items
|
||||||
mkdir -p magisk 2>/dev/null
|
mkdir -p magisk 2>/dev/null
|
||||||
@ -420,7 +423,7 @@ chmod 0750 init.magisk.rc sbin/magic_mask.sh
|
|||||||
ui_print "- Repacking boot image"
|
ui_print "- Repacking boot image"
|
||||||
repack_boot
|
repack_boot
|
||||||
|
|
||||||
BOOTSIZE=`blockdev --getsize64 $BOOTIMAGE`
|
BOOTSIZE=`blockdev --getsize64 $BOOTIMAGE 2>/dev/null`
|
||||||
NEWSIZE=`ls -l $NEWBOOT | awk '{print $5}'`
|
NEWSIZE=`ls -l $NEWBOOT | awk '{print $5}'`
|
||||||
if [ "$NEWSIZE" -gt "$BOOTSIZE" ]; then
|
if [ "$NEWSIZE" -gt "$BOOTSIZE" ]; then
|
||||||
ui_print "! Boot partition space insufficient"
|
ui_print "! Boot partition space insufficient"
|
||||||
|
@ -16,8 +16,9 @@ MOUNTINFO=$TMPDIR/mnt
|
|||||||
# e.g. we rely on the option "-c" for cp (reserve contexts), and -exec for find
|
# e.g. we rely on the option "-c" for cp (reserve contexts), and -exec for find
|
||||||
TOOLPATH=/data/busybox
|
TOOLPATH=/data/busybox
|
||||||
BINPATH=/data/magisk
|
BINPATH=/data/magisk
|
||||||
OLDPATH=$PATH
|
|
||||||
PATH=$TOOLPATH:$OLDPATH
|
export OLDPATH=$PATH
|
||||||
|
export PATH=$TOOLPATH:$OLDPATH
|
||||||
|
|
||||||
# Default permissions
|
# Default permissions
|
||||||
umask 022
|
umask 022
|
||||||
@ -44,7 +45,6 @@ unblock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_scripts() {
|
run_scripts() {
|
||||||
PATH=$OLDPATH
|
|
||||||
BASE=$MOUNTPOINT
|
BASE=$MOUNTPOINT
|
||||||
for MOD in $BASE/* ; do
|
for MOD in $BASE/* ; do
|
||||||
if [ ! -f "$MOD/disable" ]; then
|
if [ ! -f "$MOD/disable" ]; then
|
||||||
@ -56,7 +56,6 @@ run_scripts() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
PATH=$TOOLPATH:$OLDPATH
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loopsetup() {
|
loopsetup() {
|
||||||
@ -124,9 +123,8 @@ travel() {
|
|||||||
|
|
||||||
clone_dummy() {
|
clone_dummy() {
|
||||||
for ITEM in "$1/"* ; do
|
for ITEM in "$1/"* ; do
|
||||||
if [ -d "$DUMMDIR$ITEM" ]; then
|
if [ ! -e "$DUMMDIR$ITEM" ]; then
|
||||||
(clone_dummy "$ITEM")
|
if [ ! -d "$MOUNTINFO$ITEM" ]; then
|
||||||
elif [ ! -e "$DUMMDIR$ITEM" ]; then
|
|
||||||
if [ -d "$ITEM" ]; then
|
if [ -d "$ITEM" ]; then
|
||||||
# Create dummy directory
|
# Create dummy directory
|
||||||
mkdir -p "$DUMMDIR$ITEM"
|
mkdir -p "$DUMMDIR$ITEM"
|
||||||
@ -138,6 +136,13 @@ clone_dummy() {
|
|||||||
mktouch "$DUMMDIR$ITEM"
|
mktouch "$DUMMDIR$ITEM"
|
||||||
fi
|
fi
|
||||||
chcon -f "u:object_r:system_file:s0" "$DUMMDIR$ITEM"
|
chcon -f "u:object_r:system_file:s0" "$DUMMDIR$ITEM"
|
||||||
|
else
|
||||||
|
# Need to clone a skeleton
|
||||||
|
(clone_dummy "$ITEM")
|
||||||
|
fi
|
||||||
|
elif [ -d "$DUMMDIR$ITEM" ]; then
|
||||||
|
# Need to clone a skeleton
|
||||||
|
(clone_dummy "$ITEM")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -270,12 +275,6 @@ case $1 in
|
|||||||
|
|
||||||
log_print "** Magisk post-fs-data mode running..."
|
log_print "** Magisk post-fs-data mode running..."
|
||||||
|
|
||||||
# Live patch sepolicy
|
|
||||||
$BINPATH/sepolicy-inject --live -s su
|
|
||||||
|
|
||||||
# Multirom functions should go here, not available right now
|
|
||||||
MULTIROM=false
|
|
||||||
|
|
||||||
# Cache support
|
# Cache support
|
||||||
if [ -d "/cache/data_bin" ]; then
|
if [ -d "/cache/data_bin" ]; then
|
||||||
rm -rf $BINPATH $TOOLPATH
|
rm -rf $BINPATH $TOOLPATH
|
||||||
@ -294,6 +293,12 @@ case $1 in
|
|||||||
find $TOOLPATH -exec chcon -h "u:object_r:system_file:s0" {} \;
|
find $TOOLPATH -exec chcon -h "u:object_r:system_file:s0" {} \;
|
||||||
chmod -R 755 $BINPATH $TOOLPATH
|
chmod -R 755 $BINPATH $TOOLPATH
|
||||||
|
|
||||||
|
# Live patch sepolicy
|
||||||
|
$BINPATH/sepolicy-inject --live -s su
|
||||||
|
|
||||||
|
# Multirom functions should go here, not available right now
|
||||||
|
MULTIROM=false
|
||||||
|
|
||||||
# Image merging
|
# Image merging
|
||||||
chmod 644 $IMG /cache/magisk.img /data/magisk_merge.img 2>/dev/null
|
chmod 644 $IMG /cache/magisk.img /data/magisk_merge.img 2>/dev/null
|
||||||
merge_image /cache/magisk.img
|
merge_image /cache/magisk.img
|
||||||
|
Loading…
Reference in New Issue
Block a user