From 50c343d152f82b2c8a1e9b8cfa75836a8273b3ff Mon Sep 17 00:00:00 2001 From: LoveSy Date: Fri, 6 Oct 2023 13:43:59 +0800 Subject: [PATCH] No cache setOverrideTable (#2789) --- core/src/main/jni/include/symbol_cache.h | 4 +--- core/src/main/jni/src/symbol_cache.cpp | 21 ++++----------------- magisk-loader/src/main/jni/src/service.cpp | 10 ++++++---- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/core/src/main/jni/include/symbol_cache.h b/core/src/main/jni/include/symbol_cache.h index 419a726e..7369c311 100644 --- a/core/src/main/jni/include/symbol_cache.h +++ b/core/src/main/jni/include/symbol_cache.h @@ -35,13 +35,11 @@ namespace lspd { struct SymbolCache { std::atomic_flag initialized{}; void *do_dlopen; - void *setTableOverride; SymbolCache() = default; SymbolCache(const SymbolCache &other) : - do_dlopen(other.do_dlopen), - setTableOverride(other.setTableOverride) {} + do_dlopen(other.do_dlopen) {} SymbolCache &operator=(const SymbolCache &other) { new(this)SymbolCache(other); diff --git a/core/src/main/jni/src/symbol_cache.cpp b/core/src/main/jni/src/symbol_cache.cpp index 2b07315d..db27ac62 100644 --- a/core/src/main/jni/src/symbol_cache.cpp +++ b/core/src/main/jni/src/symbol_cache.cpp @@ -44,13 +44,6 @@ namespace lspd { } - bool FindLibArt() { - auto &art = GetArt(); - if (!art->isValid()) return false; - return symbol_cache->setTableOverride = art->getSymbAddress( - "_ZN3art9JNIEnvExt16SetTableOverrideEPK18JNINativeInterface"); - } - void InitSymbolCache(SymbolCache *other) { LOGD("InitSymbolCache"); if (other && other->initialized.test(std::memory_order_acquire)) { @@ -59,18 +52,12 @@ namespace lspd { symbol_cache->initialized.test_and_set(std::memory_order_relaxed); return; } - auto ok = FindLibArt(); symbol_cache->do_dlopen = SandHook::ElfImg("/linker").getSymbAddress( "__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv"); - if (!ok) [[unlikely]] { - GetArt(true); - LOGE("Init symbol cache failed"); - } else { - symbol_cache->initialized.test_and_set(std::memory_order_relaxed); - if (other) { - *other = *symbol_cache; - other->initialized.test_and_set(std::memory_order_acq_rel); - } + symbol_cache->initialized.test_and_set(std::memory_order_relaxed); + if (other) { + *other = *symbol_cache; + other->initialized.test_and_set(std::memory_order_acq_rel); } } } // namespace lspd diff --git a/magisk-loader/src/main/jni/src/service.cpp b/magisk-loader/src/main/jni/src/service.cpp index 1c92f4d1..6027c734 100644 --- a/magisk-loader/src/main/jni/src/service.cpp +++ b/magisk-loader/src/main/jni/src/service.cpp @@ -29,6 +29,7 @@ #include "utils/jni_helper.hpp" #include "symbol_cache.h" #include "config_bridge.h" +#include "elf_util.h" using namespace lsplant; @@ -197,7 +198,9 @@ namespace lspd { auto binder_class = JNI_FindClass(env, "android/os/Binder"); exec_transact_backup_methodID_ = JNI_GetMethodID(env, binder_class, "execTransact", "(IJJI)Z"); - if (!symbol_cache->setTableOverride) { + auto *setTableOverride = SandHook::ElfImg("/libart.so").getSymbAddress( + "_ZN3art9JNIEnvExt16SetTableOverrideEPK18JNINativeInterface"); + if (!setTableOverride) { LOGE("set table override not found"); } memcpy(&native_interface_replace_, env->functions, sizeof(JNINativeInterface)); @@ -205,9 +208,8 @@ namespace lspd { call_boolean_method_va_backup_ = env->functions->CallBooleanMethodV; native_interface_replace_.CallBooleanMethodV = &call_boolean_method_va_replace; - if (symbol_cache->setTableOverride != nullptr) { - reinterpret_cast(symbol_cache->setTableOverride)( - &native_interface_replace_); + if (setTableOverride != nullptr) { + setTableOverride(&native_interface_replace_); } if (auto activity_thread_class = JNI_FindClass(env, "android/app/IActivityManager$Stub")) { if (auto *set_activity_controller_field = JNI_GetStaticFieldID(env,