From f63af0601caa8f9f757ef8830602af84c6f4b5ee Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 31 Aug 2017 03:08:09 +0800 Subject: [PATCH] Support Magisk Manager boot image file patch --- jni/daemon/bootstages.c | 9 ++++----- scripts/boot_patch.sh | 17 +++++++++-------- scripts/update_binary.sh | 10 ++++++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index bfd181ddf..289e30d70 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -553,18 +553,17 @@ void post_fs_data(int client) { char *bin_path = NULL; if (access("/cache/data_bin", F_OK) == 0) bin_path = "/cache/data_bin"; - else if (access("/data/local/tmp/magisk_inject", F_OK) == 0) - bin_path = "/data/local/tmp/magisk_inject"; + else if (access("/data/data/com.topjohnwu.magisk/install", F_OK) == 0) + bin_path = "/data/data/com.topjohnwu.magisk/install"; if (bin_path) { exec_command_sync("rm", "-rf", DATABIN, NULL); exec_command_sync("cp", "-r", bin_path, DATABIN, NULL); exec_command_sync("rm", "-rf", bin_path, NULL); exec_command_sync("chmod", "-R", "755", bin_path, NULL); + // Lazy.... use shell blob to match files + exec_command_sync("sh", "-c", "mv /data/magisk/stock_boot* /data", NULL); } - // Lazy.... use shell blob to match files - exec_command_sync("sh", "-c", "mv /data/magisk/stock_boot* /data", NULL); - // Link busybox mount_mirrors(); link_busybox(); diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 2032111b8..593edb1e5 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -49,12 +49,15 @@ abort_wrap() { # Pure bash dirname implementation dirname_wrap() { - if echo $1 | grep "/" >/dev/null 2>&1; then - RES=${1%/*} - [ -z $RES ] && echo "/" || echo $RES - else - echo "." - fi + case "$1" in + */*) + dir=${1%/*} + [ -z $dir ] && echo "/" || echo $dir + ;; + *) + echo "." + ;; + esac } # Pure bash basename implementation @@ -93,10 +96,8 @@ cpio_mkdir() { [ -z $1 ] && abort_wrap "This script requires a boot image as a parameter" -CWD=`pwd` cd "`dirname_wrap $1`" BOOTIMAGE="`pwd`/`basename_wrap $1`" -cd "$CWD" [ -e "$BOOTIMAGE" ] || abort_wrap "$BOOTIMAGE does not exist!" diff --git a/scripts/update_binary.sh b/scripts/update_binary.sh index 7058768a2..08d79cee2 100644 --- a/scripts/update_binary.sh +++ b/scripts/update_binary.sh @@ -1,6 +1,12 @@ # EX_ARM, EX_X86, BB_ARM, and BB_X86 should be generated in build.py +dirname_wrap() { + case "$1" in + */*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;; + *) echo "." ;; + esac +} [ "$1" = "indep" ] && INDEP=true || INDEP=false -$INDEP && TMPDIR=/data/local/tmp || TMPDIR=/dev/tmp +$INDEP && TMPDIR="`cd "\`dirname_wrap "${BASH_SOURCE:-$0}"\`" && pwd`" || TMPDIR=/dev/tmp INSTALLER=$TMPDIR/install; BBDIR=$TMPDIR/bin EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox $INDEP || rm -rf $TMPDIR 2>/dev/null; @@ -17,7 +23,7 @@ $BBBIN --install -s $TMPDIR/bin export PATH=$BBDIR:$PATH if $INDEP; then shift - exec sh $@ + exec sh "$@" else mkdir -p $INSTALLER unzip -o "$3" -d $INSTALLER