diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Const.kt b/app/src/main/java/com/topjohnwu/magisk/core/Const.kt index 2acebd989..d75620d30 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Const.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Const.kt @@ -6,7 +6,8 @@ import java.io.File object Const { // Paths - const val MAGISK_PATH = "/sbin/.magisk/modules" + lateinit var MAGISKTMP: String + val MAGISK_PATH get() = "$MAGISKTMP/modules" var MAGISK_DISABLE_FILE = File("xxx") const val TMP_FOLDER_PATH = "/dev/tmp" const val MAGISK_LOG = "/cache/magisk.log" @@ -25,8 +26,8 @@ object Const { object Version { const val MIN_VERSION = "v19.0" const val MIN_VERCODE = 19000 - const val CONNECT_MODE = 20100 - const val PROVIDER_CONNECT = 20102 + const val PROVIDER_CONNECT = 20200 + const val DYNAMIC_PATH = 20400 } object ID { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Module.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Module.kt index a73df7f92..823d4f9fc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Module.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Module.kt @@ -62,7 +62,7 @@ class Module(path: String) : BaseModule() { companion object { - private const val PERSIST = "/sbin/.magisk/mirror/persist/magisk" + private val PERSIST get() = "${Const.MAGISKTMP}/mirror/persist/magisk" @WorkerThread fun loadModules(): List { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt index 1ef1c4704..b031199fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt @@ -18,22 +18,20 @@ class RootInit : Shell.Initializer() { fun init(context: Context, shell: Shell): Boolean { val job = shell.newJob() + if (Info.env.magiskVersionCode >= Const.Version.DYNAMIC_PATH) + job.add("MAGISKTMP=$(magisk --path)/.magisk") + else + job.add("MAGISKTMP=/sbin/.magisk") job.add(context.rawResource(R.raw.manager)) if (shell.isRoot) { job.add(context.rawResource(R.raw.util_functions)) - .add("SHA1=`grep_prop SHA1 /sbin/.magisk/config`") Const.MAGISK_DISABLE_FILE = SuFile("/cache/.disable_magisk") } - - job.add( - "export BOOTMODE=true", - "mount_partitions", - "get_flags", - "run_migrations" - ).exec() + job.add("mm_init").exec() fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean() + Const.MAGISKTMP = ShellUtils.fastCmd(shell, "echo \$MAGISKTMP") Info.keepVerity = getvar("KEEPVERITY") Info.keepEnc = getvar("KEEPFORCEENCRYPT") Info.isSAR = getvar("SYSTEM_ROOT") diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index 7222f6986..dbf63d73e 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -11,12 +11,9 @@ env_check() { fix_env() { cd $MAGISKBIN - PATH=/sbin:/system/bin sh update-binary -x - ./busybox rm -f $MAGISKTMP/busybox/* - cp -af busybox $MAGISKTMP/busybox/busybox - $MAGISKTMP/busybox/busybox --install -s $MAGISKTMP/busybox - rm -f update-binary magisk.apk - chmod -R 755 . + PATH=/system/bin /system/bin/sh update-binary -x + ./busybox rm -f update-binary magisk.apk + ./busybox chmod -R 755 . ./magiskinit -x magisk magisk cd / } @@ -95,8 +92,8 @@ EOF add_hosts_module() { # Do not touch existing hosts module - [ -d /sbin/.magisk/modules/hosts ] && return - cd /sbin/.magisk/modules + [ -d $MAGISKTMP/modules/hosts ] && return + cd $MAGISKTMP/modules mkdir -p hosts/system/etc cat << EOF > hosts/module.prop id=hosts @@ -106,8 +103,7 @@ versionCode=1 author=Magisk Manager description=Magisk Manager built-in systemless hosts module EOF - cp -f /system/etc/hosts hosts/system/etc/hosts - magisk --clone-attr /system/etc/hosts hosts/system/etc/hosts + magisk --clone /system/etc/hosts hosts/system/etc/hosts touch hosts/update cd / } @@ -159,3 +155,17 @@ get_flags() { } run_migrations() { return; } + +grep_prop() { return; } + +############# +# Initialize +############# + +mm_init() { + export BOOTMODE=true + mount_partitions + get_flags + run_migrations + SHA1=$(grep_prop SHA1 $MAGISKTMP/config) +} diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index 9441a3cc5..3c3aa7604 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -34,8 +34,10 @@ grep_prop() { getvar() { local VARNAME=$1 - local VALUE= - VALUE=`grep_prop $VARNAME /sbin/.magisk/config /data/.magisk /cache/.magisk` + local VALUE + local PROPPATH='/data/.magisk /cache/.magisk' + [ -n $MAGISKTMP ] && PROPPATH="$MAGISKTMP/config $PROPPATH" + VALUE=$(grep_prop $VARNAME $PROPPATH) [ ! -z $VALUE ] && eval $VARNAME=\$VALUE } @@ -628,7 +630,8 @@ is_legacy_script() { # Require OUTFD, ZIPFILE to be set install_module() { - local PERSISTDIR=/sbin/.magisk/mirror/persist + local PERSISTDIR + command -v magisk >/dev/null && PERSISTDIR=$(magisk --path)/mirror/persist rm -rf $TMPDIR mkdir -p $TMPDIR @@ -705,7 +708,7 @@ install_module() { fi # Copy over custom sepolicy rules - if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then + if [ -f $MODPATH/sepolicy.rule -a -e "$PERSISTDIR" ]; then ui_print "- Installing custom sepolicy patch" PERSISTMOD=$PERSISTDIR/magisk/$MODID mkdir -p $PERSISTMOD @@ -733,7 +736,6 @@ install_module() { [ -z $BOOTMODE ] && ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true [ -z $BOOTMODE ] && BOOTMODE=false -MAGISKTMP=/sbin/.magisk NVBASE=/data/adb TMPDIR=/dev/tmp