diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index b60742eb6..590b7b9e3 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -126,9 +126,11 @@ string find_preinit_device() { } matched = UNKNOWN; bool encrypted = getprop("ro.crypto.state") == "encrypted"; bool mount = getuid() == 0 && getenv("MAGISKTMP"); + bool make_dev = mount && getenv("MAKEDEV"); string preinit_source; string preinit_dir; + dev_t preinit_dev; for (const auto &info: parse_mount_info("self")) { if (info.target.ends_with(PREINITMIRR)) @@ -180,6 +182,7 @@ string find_preinit_device() { if (mount) { preinit_dir = resolve_preinit_dir(info.target.data()); + preinit_dev = info.device; } preinit_source = info.source; } @@ -189,6 +192,10 @@ string find_preinit_device() { mkdirs(preinit_dir.data(), 0700); mkdirs(mirror_dir.data(), 0700); xmount(preinit_dir.data(), mirror_dir.data(), nullptr, MS_BIND, nullptr); + if (make_dev) { + auto dev_path = string(getenv("MAGISKTMP")) + "/" PREINITDEV; + xmknod(dev_path.data(), S_IFBLK | 0600, preinit_dev); + } } return preinit_source.empty() ? "" : basename(preinit_source.data()); } diff --git a/scripts/avd_magisk.sh b/scripts/avd_magisk.sh index 359d9b1dc..c94814e48 100755 --- a/scripts/avd_magisk.sh +++ b/scripts/avd_magisk.sh @@ -67,15 +67,9 @@ if [ -d /dev/avd-magisk ]; then rm -rf /dev/avd-magisk 2>/dev/null fi -# SELinux stuffs -if [ -d /sys/fs/selinux ]; then - if [ -f /vendor/etc/selinux/precompiled_sepolicy ]; then - ./magiskpolicy --load /vendor/etc/selinux/precompiled_sepolicy --live --magisk 2>&1 - elif [ -f /sepolicy ]; then - ./magiskpolicy --load /sepolicy --live --magisk 2>&1 - else - ./magiskpolicy --live --magisk 2>&1 - fi +# Mount /cache if not already mounted +if ! grep -q ' /cache ' /proc/mounts; then + mount -t tmpfs -o 'mode=0755' tmpfs /cache fi MAGISKTMP=/sbin @@ -148,9 +142,27 @@ mkdir $MAGISKTMP/.magisk/block mkdir $MAGISKTMP/.magisk/worker touch $MAGISKTMP/.magisk/config -# Boot up export MAGISKTMP -$MAGISKTMP/magisk --preinit-device +MAKEDEV=1 $MAGISKTMP/magisk --preinit-device 2>&1 + +RULESCMD="" +for r in $MAGISKTMP/.magisk/preinit/*/sepolicy.rule; do + [ -f "$r" ] || continue + RULESCMD="$RULESCMD --apply $r" +done + +# SELinux stuffs +if [ -d /sys/fs/selinux ]; then + if [ -f /vendor/etc/selinux/precompiled_sepolicy ]; then + ./magiskpolicy --load /vendor/etc/selinux/precompiled_sepolicy --live --magisk $RULESCMD 2>&1 + elif [ -f /sepolicy ]; then + ./magiskpolicy --load /sepolicy --live --magisk $RULESCMD 2>&1 + else + ./magiskpolicy --live --magisk $RULESCMD 2>&1 + fi +fi + +# Boot up $MAGISKTMP/magisk --post-fs-data start $MAGISKTMP/magisk --service