No cache setOverrideTable (#2789)
This commit is contained in:
parent
932612aa9c
commit
50c343d152
|
|
@ -35,13 +35,11 @@ namespace lspd {
|
||||||
struct SymbolCache {
|
struct SymbolCache {
|
||||||
std::atomic_flag initialized{};
|
std::atomic_flag initialized{};
|
||||||
void *do_dlopen;
|
void *do_dlopen;
|
||||||
void *setTableOverride;
|
|
||||||
|
|
||||||
SymbolCache() = default;
|
SymbolCache() = default;
|
||||||
|
|
||||||
SymbolCache(const SymbolCache &other) :
|
SymbolCache(const SymbolCache &other) :
|
||||||
do_dlopen(other.do_dlopen),
|
do_dlopen(other.do_dlopen) {}
|
||||||
setTableOverride(other.setTableOverride) {}
|
|
||||||
|
|
||||||
SymbolCache &operator=(const SymbolCache &other) {
|
SymbolCache &operator=(const SymbolCache &other) {
|
||||||
new(this)SymbolCache(other);
|
new(this)SymbolCache(other);
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
void InitSymbolCache(SymbolCache *other) {
|
||||||
LOGD("InitSymbolCache");
|
LOGD("InitSymbolCache");
|
||||||
if (other && other->initialized.test(std::memory_order_acquire)) {
|
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);
|
symbol_cache->initialized.test_and_set(std::memory_order_relaxed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto ok = FindLibArt();
|
|
||||||
symbol_cache->do_dlopen = SandHook::ElfImg("/linker").getSymbAddress(
|
symbol_cache->do_dlopen = SandHook::ElfImg("/linker").getSymbAddress(
|
||||||
"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv");
|
"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv");
|
||||||
if (!ok) [[unlikely]] {
|
symbol_cache->initialized.test_and_set(std::memory_order_relaxed);
|
||||||
GetArt(true);
|
if (other) {
|
||||||
LOGE("Init symbol cache failed");
|
*other = *symbol_cache;
|
||||||
} else {
|
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
|
} // namespace lspd
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
#include "utils/jni_helper.hpp"
|
#include "utils/jni_helper.hpp"
|
||||||
#include "symbol_cache.h"
|
#include "symbol_cache.h"
|
||||||
#include "config_bridge.h"
|
#include "config_bridge.h"
|
||||||
|
#include "elf_util.h"
|
||||||
|
|
||||||
using namespace lsplant;
|
using namespace lsplant;
|
||||||
|
|
||||||
|
|
@ -197,7 +198,9 @@ namespace lspd {
|
||||||
auto binder_class = JNI_FindClass(env, "android/os/Binder");
|
auto binder_class = JNI_FindClass(env, "android/os/Binder");
|
||||||
exec_transact_backup_methodID_ = JNI_GetMethodID(env, binder_class, "execTransact",
|
exec_transact_backup_methodID_ = JNI_GetMethodID(env, binder_class, "execTransact",
|
||||||
"(IJJI)Z");
|
"(IJJI)Z");
|
||||||
if (!symbol_cache->setTableOverride) {
|
auto *setTableOverride = SandHook::ElfImg("/libart.so").getSymbAddress<void (*)(JNINativeInterface *)>(
|
||||||
|
"_ZN3art9JNIEnvExt16SetTableOverrideEPK18JNINativeInterface");
|
||||||
|
if (!setTableOverride) {
|
||||||
LOGE("set table override not found");
|
LOGE("set table override not found");
|
||||||
}
|
}
|
||||||
memcpy(&native_interface_replace_, env->functions, sizeof(JNINativeInterface));
|
memcpy(&native_interface_replace_, env->functions, sizeof(JNINativeInterface));
|
||||||
|
|
@ -205,9 +208,8 @@ namespace lspd {
|
||||||
call_boolean_method_va_backup_ = env->functions->CallBooleanMethodV;
|
call_boolean_method_va_backup_ = env->functions->CallBooleanMethodV;
|
||||||
native_interface_replace_.CallBooleanMethodV = &call_boolean_method_va_replace;
|
native_interface_replace_.CallBooleanMethodV = &call_boolean_method_va_replace;
|
||||||
|
|
||||||
if (symbol_cache->setTableOverride != nullptr) {
|
if (setTableOverride != nullptr) {
|
||||||
reinterpret_cast<void (*)(JNINativeInterface *)>(symbol_cache->setTableOverride)(
|
setTableOverride(&native_interface_replace_);
|
||||||
&native_interface_replace_);
|
|
||||||
}
|
}
|
||||||
if (auto activity_thread_class = JNI_FindClass(env, "android/app/IActivityManager$Stub")) {
|
if (auto activity_thread_class = JNI_FindClass(env, "android/app/IActivityManager$Stub")) {
|
||||||
if (auto *set_activity_controller_field = JNI_GetStaticFieldID(env,
|
if (auto *set_activity_controller_field = JNI_GetStaticFieldID(env,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue