diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 885abc485..d805d4618 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -65,7 +65,6 @@ LOCAL_SRC_FILES := \ init/twostage.cpp \ init/selinux.cpp \ magiskpolicy/sepolicy.cpp \ - magiskpolicy/magiskpolicy.cpp \ magiskpolicy/rules.cpp \ magiskpolicy/policydb.cpp \ magiskpolicy/statement.cpp @@ -114,14 +113,12 @@ LOCAL_STATIC_LIBRARIES := \ libsepol LOCAL_SRC_FILES := \ - core/applet_stub.cpp \ + magiskpolicy/main.cpp \ magiskpolicy/sepolicy.cpp \ - magiskpolicy/magiskpolicy.cpp \ magiskpolicy/rules.cpp \ magiskpolicy/policydb.cpp \ magiskpolicy/statement.cpp -LOCAL_CFLAGS := -DAPPLET_STUB_MAIN=magiskpolicy_main include $(BUILD_EXECUTABLE) endif diff --git a/native/jni/include/magisk.hpp b/native/jni/include/magisk.hpp index 02c30e417..a79a2ef6a 100644 --- a/native/jni/include/magisk.hpp +++ b/native/jni/include/magisk.hpp @@ -30,7 +30,6 @@ extern std::string MAGISKTMP; #define SELINUXMOCK INTLROOT "/selinux" constexpr const char *applet_names[] = { "su", "resetprop", nullptr }; -constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr }; #define POST_FS_DATA_WAIT_TIME 40 #define POST_FS_DATA_SCRIPT_MAX_TIME 35 @@ -40,7 +39,6 @@ extern int SDK_INT; // Multi-call entrypoints int magisk_main(int argc, char *argv[]); -int magiskpolicy_main(int argc, char *argv[]); int su_client_main(int argc, char *argv[]); int resetprop_main(int argc, char *argv[]); int app_process_main(int argc, char *argv[]); diff --git a/native/jni/init/init.cpp b/native/jni/init/init.cpp index 4f11b187f..940e57f76 100644 --- a/native/jni/init/init.cpp +++ b/native/jni/init/init.cpp @@ -1,13 +1,10 @@ #include #include -#include -#include #include #include #include -#include #include #include @@ -15,12 +12,6 @@ using namespace std; -// Debug toggle -#define ENABLE_TEST 0 - -constexpr int (*init_applet_main[])(int, char *[]) = - { magiskpolicy_main, magiskpolicy_main, nullptr }; - bool unxz(int fd, const uint8_t *buf, size_t size) { uint8_t out[8192]; xz_crc32_init(); @@ -65,64 +56,12 @@ public: } }; -#if ENABLE_TEST -class TestInit : public BaseInit { -public: - TestInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {}; - void start() override { - // Place init tests here - } -}; - -static int test_main(int argc, char *argv[]) { - // Log to console - cmdline_logging(); - log_cb.ex = nop_ex; - - // Switch to isolate namespace - xunshare(CLONE_NEWNS); - xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr); - - // Unmount everything in reverse - vector mounts; - parse_mnt("/proc/mounts", [&](mntent *me) { - if (me->mnt_dir != "/"sv) - mounts.emplace_back(me->mnt_dir); - return true; - }); - for (auto &m : reversed(mounts)) - xumount(m.data()); - - // chroot jail - chdir(dirname(argv[0])); - chroot("."); - chdir("/"); - - cmdline cmd{}; - load_kernel_info(&cmd); - - auto init = make_unique(argv, &cmd); - init->start(); - - return 1; -} -#endif // ENABLE_TEST - int main(int argc, char *argv[]) { umask(0); auto name = basename(argv[0]); if (name == "magisk"sv) return magisk_proxy_main(argc, argv); - for (int i = 0; init_applet[i]; ++i) { - if (strcmp(name, init_applet[i]) == 0) - return (*init_applet_main[i])(argc, argv); - } - -#if ENABLE_TEST - if (getenv("INIT_TEST") != nullptr) - return test_main(argc, argv); -#endif if (argc > 1 && argv[1] == "-x"sv) { if (argc > 2 && argv[2] == "manager"sv) diff --git a/native/jni/magiskpolicy/magiskpolicy.cpp b/native/jni/magiskpolicy/main.cpp similarity index 98% rename from native/jni/magiskpolicy/magiskpolicy.cpp rename to native/jni/magiskpolicy/main.cpp index 03dd33ba0..a7c713a96 100644 --- a/native/jni/magiskpolicy/magiskpolicy.cpp +++ b/native/jni/magiskpolicy/main.cpp @@ -32,7 +32,7 @@ it will load from current live policies (/sys/fs/selinux/policy) exit(1); } -int magiskpolicy_main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { cmdline_logging(); const char *out_file = nullptr; vector rule_files;