No cache setOverrideTable (#2789)
This commit is contained in:
parent
932612aa9c
commit
50c343d152
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<void (*)(JNINativeInterface *)>(
|
||||
"_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<void (*)(JNINativeInterface *)>(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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue