From f9c7a4c933f6116e41d65856555d9114bdbaa674 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 11 Nov 2020 02:26:07 -0800 Subject: [PATCH] Redirect /data/adb/magisk/busybox Workaround some stupid Samsung kernel restrictions --- native/jni/core/bootstages.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 5fc36eb4e..ee359667c 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -98,6 +98,13 @@ static void mount_mirrors() { link_mirror(system_ext) } +constexpr char bb_script[] = R"EOF( +#!/system/bin/sh +BB=%s +[ -x $BB ] && exec $BB "$@" +exec /data/adb/magisk/busybox.bin "$@" +)EOF"; + static bool magisk_env() { char buf[4096]; @@ -145,12 +152,20 @@ static bool magisk_env() { unlink("/sbin/magiskhide"); } - if (access(DATABIN "/busybox", X_OK) == -1) - return false; + if (access(DATABIN "/busybox.bin", X_OK)) { + if (access(DATABIN "/busybox", X_OK)) + return false; + rename(DATABIN "/busybox", DATABIN "/busybox.bin"); + } sprintf(buf, "%s/" BBPATH "/busybox", MAGISKTMP.data()); + { + auto fp = open_file(DATABIN "/busybox", "we"); + fprintf(fp.get(), bb_script, buf); + } + chmod(DATABIN "/busybox", 0755); mkdir(dirname(buf), 0755); - cp_afc(DATABIN "/busybox", buf); + cp_afc(DATABIN "/busybox.bin", buf); exec_command_async(buf, "--install", "-s", dirname(buf)); return true;