diff --git a/native/src/core/scripting.cpp b/native/src/core/scripting.cpp index e2a5d5a2a..f045efc11 100644 --- a/native/src/core/scripting.cpp +++ b/native/src/core/scripting.cpp @@ -13,9 +13,10 @@ using namespace std; static const char *bbpath() { static string path; - if (path.empty()) { - path = get_magisk_tmp(); - path += "/" BBPATH "/busybox"; + path = get_magisk_tmp(); + path += "/" BBPATH "/busybox"; + if (access(path.data(), X_OK) != 0) { + path = DATABIN "/busybox"; } return path.data(); } @@ -210,7 +211,7 @@ static void abort(FILE *fp, const char *fmt, ...) { } constexpr char install_module_script[] = R"EOF( -exec $(magisk --path)/.magisk/busybox/busybox sh -c ' +exec %s sh -c ' . /data/adb/magisk/util_functions.sh install_module exit 0' @@ -220,7 +221,7 @@ void install_module(const char *file) { if (getuid() != 0) abort(stderr, "Run this command with root"); if (access(DATABIN, F_OK) || - access(DATABIN "/busybox", X_OK) || + access(bbpath(), X_OK) || access(DATABIN "/util_functions.sh", F_OK)) abort(stderr, "Incomplete Magisk install"); if (access(file, F_OK)) @@ -236,7 +237,10 @@ void install_module(const char *file) { xdup2(fd, STDERR_FILENO); close(fd); - const char *argv[] = { "/system/bin/sh", "-c", install_module_script, nullptr }; + char cmds[256]; + ssprintf(cmds, sizeof(cmds), install_module_script, bbpath()); + + const char *argv[] = { "/system/bin/sh", "-c", cmds, nullptr }; execve(argv[0], (char **) argv, environ); abort(stdout, "Failed to execute BusyBox shell"); }