diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 2323adba5..42bc6a4d6 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -411,27 +411,25 @@ static void daemon_entry() { poll_loop(); } -string find_magisk_tmp() { - if (access("/debug_ramdisk/" INTLROOT, F_OK) == 0) { - return "/debug_ramdisk"; - } - if (access("/sbin/" INTLROOT, F_OK) == 0) { - return "/sbin"; - } - // Fallback to lookup from mountinfo for manual mount, e.g. avd - for (const auto &mount: parse_mount_info("self")) { - if (mount.source == "magisk" && mount.root == "/") { - return mount.target; +const char *get_magisk_tmp() { + static const char *path = nullptr; + if (path == nullptr) { + if (access("/debug_ramdisk/" INTLROOT, F_OK) == 0) { + path = "/debug_ramdisk"; + } else if (access("/sbin/" INTLROOT, F_OK) == 0) { + path = "/sbin"; + } else { + path = ""; } } - return ""; + return path; } int connect_daemon(int req, bool create) { int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); sockaddr_un addr = {.sun_family = AF_LOCAL}; - string tmp = find_magisk_tmp(); - strcpy(addr.sun_path, (tmp + "/" MAIN_SOCKET).data()); + const char *tmp = get_magisk_tmp(); + ssprintf(addr.sun_path, sizeof(addr.sun_path), "%s/" MAIN_SOCKET, tmp); if (connect(fd, (sockaddr *) &addr, sizeof(addr))) { if (!create || getuid() != AID_ROOT) { LOGE("No daemon is currently running!\n"); @@ -441,7 +439,7 @@ int connect_daemon(int req, bool create) { char buf[64]; xreadlink("/proc/self/exe", buf, sizeof(buf)); - if (tmp.empty() || !str_starts(buf, tmp)) { + if (tmp[0] == '\0' || !str_starts(buf, tmp)) { LOGE("Start daemon on magisk tmpfs\n"); close(fd); return -1; diff --git a/native/src/core/magisk.cpp b/native/src/core/magisk.cpp index 01e568214..1278ba93e 100644 --- a/native/src/core/magisk.cpp +++ b/native/src/core/magisk.cpp @@ -129,9 +129,9 @@ int magisk_main(int argc, char *argv[]) { write_int(fd, do_reboot); return read_int(fd); } else if (argv[1] == "--path"sv) { - string path = find_magisk_tmp(); - if (!path.empty()) { - printf("%s\n", path.data()); + const char *path = get_magisk_tmp(); + if (path[0] != '\0') { + printf("%s\n", path); return 0; } return 1; diff --git a/native/src/include/daemon.hpp b/native/src/include/daemon.hpp index d2292472e..ba3aaff4b 100644 --- a/native/src/include/daemon.hpp +++ b/native/src/include/daemon.hpp @@ -71,7 +71,7 @@ extern int app_process_32; extern int app_process_64; extern std::vector *module_list; -std::string find_magisk_tmp(); +const char *get_magisk_tmp(); int connect_daemon(int req, bool create = false); // Poll control diff --git a/native/src/include/magisk.hpp b/native/src/include/magisk.hpp index 9010aab2c..795a399dd 100644 --- a/native/src/include/magisk.hpp +++ b/native/src/include/magisk.hpp @@ -3,7 +3,6 @@ #include #define JAVA_PACKAGE_NAME "com.topjohnwu.magisk" -#define LOGFILE "/cache/magisk.log" #define SECURE_DIR "/data/adb" #define MODULEROOT SECURE_DIR "/modules" #define MODULEUPGRADE SECURE_DIR "/modules_update" diff --git a/scripts/avd_magisk.sh b/scripts/avd_magisk.sh index c76ec44b2..c93371688 100755 --- a/scripts/avd_magisk.sh +++ b/scripts/avd_magisk.sh @@ -61,9 +61,8 @@ done # Stop zygote (and previous setup if exists) magisk --stop 2>/dev/null stop -if [ -d /dev/avd-magisk ]; then - umount -l /dev/avd-magisk 2>/dev/null - rm -rf /dev/avd-magisk 2>/dev/null +if [ -d /debug_ramdisk ]; then + umount -l /debug_ramdisk 2>/dev/null fi # Make sure boot completed props are not set to 1 @@ -108,11 +107,10 @@ elif [ -e /sbin ]; then rm -rf /dev/sysroot else # Android Q+ without sbin - MAGISKTMP=/dev/avd-magisk - mkdir /dev/avd-magisk + MAGISKTMP=/debug_ramdisk # If a file name 'magisk' is in current directory, mount will fail rm -f magisk - mount -t tmpfs -o 'mode=0755' magisk /dev/avd-magisk + mount -t tmpfs -o 'mode=0755' magisk /debug_ramdisk fi # Magisk stuff @@ -138,7 +136,6 @@ else fi ln -s ./magisk $MAGISKTMP/su ln -s ./magisk $MAGISKTMP/resetprop -ln -s ./magisk $MAGISKTMP/magiskhide ln -s ./magiskpolicy $MAGISKTMP/supolicy mkdir -p $MAGISKTMP/.magisk/mirror