diff --git a/magisk-loader/magisk_module/daemon b/magisk-loader/magisk_module/daemon index fb08a51031c..2f68cff1bab 100644 --- a/magisk-loader/magisk_module/daemon +++ b/magisk-loader/magisk_module/daemon @@ -23,8 +23,6 @@ if [ $debug = "true" ]; then fi fi -mount tmpfs -t tmpfs /data/resource-cache - if [ ! -S "/dev/socket/zygote" ]; then timeout 0.5 inotifyd - /dev/socket:near | while read -r line; do $debug && log -p v -t "LSPosed" "inotify: $line" diff --git a/magisk-loader/magisk_module/system.prop b/magisk-loader/magisk_module/system.prop deleted file mode 100644 index 64184152a10..00000000000 --- a/magisk-loader/magisk_module/system.prop +++ /dev/null @@ -1 +0,0 @@ -dalvik.vm.dex2oat-flags=--inline-max-code-units=0 diff --git a/magisk-loader/src/main/jni/api/zygisk_main.cpp b/magisk-loader/src/main/jni/api/zygisk_main.cpp index 39ca59ec922..8c61c8fd69e 100644 --- a/magisk-loader/src/main/jni/api/zygisk_main.cpp +++ b/magisk-loader/src/main/jni/api/zygisk_main.cpp @@ -40,7 +40,7 @@ class ZygiskModule : public zygisk::ModuleBase { void onLoad(zygisk::Api *api, JNIEnv *env) override { env_ = env; api_ = api; - MagiskLoader::Init(api); + MagiskLoader::Init(); ConfigImpl::Init(); } @@ -51,7 +51,7 @@ class ZygiskModule : public zygisk::ModuleBase { } void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override { - MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env_, args->nice_name, + MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env_, api_, args->nice_name, args->app_data_dir); if (*allowUnload) api_->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); } @@ -69,7 +69,7 @@ class ZygiskModule : public zygisk::ModuleBase { env_->DeleteLocalRef(name); env_->DeleteLocalRef(process); } - MagiskLoader::GetInstance()->OnNativeForkSystemServerPost(env_); + MagiskLoader::GetInstance()->OnNativeForkSystemServerPost(env_, api_); if (*allowUnload) api_->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); } }; diff --git a/magisk-loader/src/main/jni/src/magisk_loader.cpp b/magisk-loader/src/main/jni/src/magisk_loader.cpp index 6f309e0272a..812e7f9d0a7 100644 --- a/magisk-loader/src/main/jni/src/magisk_loader.cpp +++ b/magisk-loader/src/main/jni/src/magisk_loader.cpp @@ -59,12 +59,12 @@ std::vector MapInfo::Scan(std::string_view pid) { constexpr static auto kMapEntry = 7; std::vector info; auto path = "/proc/" + std::string{pid} + "/maps"; - auto maps = std::unique_ptr{fopen(path.c_str(), "r"), &fclose}; + auto maps = fopen(path.c_str(), "r"); if (maps) { char *line = nullptr; size_t len = 0; ssize_t read; - while ((read = getline(&line, &len, maps.get())) > 0) { + while ((read = getline(&line, &len, maps)) > 0) { line[read - 1] = '\0'; uintptr_t start = 0; uintptr_t end = 0; @@ -89,10 +89,12 @@ std::vector MapInfo::Scan(std::string_view pid) { } free(line); } + fclose(maps); return info; } -void MagiskLoader::InitializeZygiskApi(zygisk::Api *api) { +void MagiskLoader::InitializeLSPlant(zygisk::Api *api) { + if (lsplant_initilized) return; std::vector> plt_hook_saved = {}; const std::string libArtPath = GetArt()->name(); @@ -151,6 +153,7 @@ void MagiskLoader::InitializeZygiskApi(zygisk::Api *api) { .art_symbol_prefix_resolver = [](auto symbol) { return GetArt()->getSymbPrefixFirstAddress(symbol); }, .is_plt_hook = true}; + lsplant_initilized = true; } void MagiskLoader::LoadDex(JNIEnv *env, PreloadedDex &&dex) { @@ -195,7 +198,7 @@ void MagiskLoader::OnNativeForkSystemServerPre(JNIEnv *env) { setAllowUnload(skip_); } -void MagiskLoader::OnNativeForkSystemServerPost(JNIEnv *env) { +void MagiskLoader::OnNativeForkSystemServerPost(JNIEnv *env, zygisk::Api *api) { if (!skip_) { auto *instance = Service::instance(); auto system_server_binder = instance->RequestSystemServerBinder(env); @@ -218,6 +221,7 @@ void MagiskLoader::OnNativeForkSystemServerPost(JNIEnv *env) { instance->HookBridge(*this, env); // always inject into system server + InitializeLSPlant(api); InitArtHooker(env, initInfo); InitHooks(env); SetupEntryClass(env); @@ -272,7 +276,8 @@ void MagiskLoader::OnNativeForkAndSpecializePre(JNIEnv *env, jint uid, jintArray setAllowUnload(skip_); } -void MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name, jstring app_dir) { +void MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, zygisk::Api *api, jstring nice_name, + jstring app_dir) { const JUTFString process_name(env, nice_name); auto *instance = Service::instance(); if (is_parasitic_manager) nice_name = JNI_NewStringUTF(env, "org.lsposed.manager").release(); @@ -284,6 +289,7 @@ void MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name, ConfigBridge::GetInstance()->obfuscation_map(std::move(obfs_map)); LoadDex(env, PreloadedDex(dex_fd, size)); close(dex_fd); + InitializeLSPlant(api); InitArtHooker(env, initInfo); InitHooks(env); SetupEntryClass(env); diff --git a/magisk-loader/src/main/jni/src/magisk_loader.h b/magisk-loader/src/main/jni/src/magisk_loader.h index 2c8b9cff4f6..89efde6a3e2 100644 --- a/magisk-loader/src/main/jni/src/magisk_loader.h +++ b/magisk-loader/src/main/jni/src/magisk_loader.h @@ -29,10 +29,7 @@ namespace lspd { class MagiskLoader : public Context { public: - inline static void Init(zygisk::Api *api) { - instance_ = std::make_unique(); - GetInstance()->InitializeZygiskApi(api); - } + inline static void Init() { instance_ = std::make_unique(); } inline static MagiskLoader *GetInstance() { return static_cast(instance_.get()); @@ -41,12 +38,13 @@ class MagiskLoader : public Context { void OnNativeForkAndSpecializePre(JNIEnv *env, jint uid, jintArray &gids, jstring &nice_name, jboolean is_child_zygote, jstring app_data_dir); - void OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name, jstring app_dir); - - void OnNativeForkSystemServerPost(JNIEnv *env); + void OnNativeForkAndSpecializePost(JNIEnv *env, zygisk::Api *api, jstring nice_name, + jstring app_dir); void OnNativeForkSystemServerPre(JNIEnv *env); + void OnNativeForkSystemServerPost(JNIEnv *env, zygisk::Api *api); + protected: void LoadDex(JNIEnv *env, PreloadedDex &&dex) override; @@ -54,9 +52,10 @@ class MagiskLoader : public Context { private: bool skip_ = false; + bool lsplant_initilized = false; lsplant::InitInfo initInfo; - void InitializeZygiskApi(zygisk::Api *api); + void InitializeLSPlant(zygisk::Api *api); static void setAllowUnload(bool unload); };