From 21d05486df6362ba620762d3bba5939f8e019f97 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Mon, 24 May 2021 08:34:22 +0800 Subject: [PATCH] [core] Remove reflection hook (#666) We previously hook reflection because we want only the hooker class to have the privilege to access the backup method. However, we now found that the backup method is a private copy and cannot be accessed by outer classes, so we remove the relection hook for efficiency. --- .../cpp/main/include/art/runtime/reflection.h | 44 ------------------- core/src/main/cpp/main/src/native_hook.cpp | 2 - .../de/robv/android/xposed/LspHooker.java | 1 + 3 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 core/src/main/cpp/main/include/art/runtime/reflection.h diff --git a/core/src/main/cpp/main/include/art/runtime/reflection.h b/core/src/main/cpp/main/include/art/runtime/reflection.h deleted file mode 100644 index 8fcec9a1..00000000 --- a/core/src/main/cpp/main/include/art/runtime/reflection.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of LSPosed. - * - * LSPosed is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LSPosed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LSPosed. If not, see . - * - * Copyright (C) 2020 EdXposed Contributors - * Copyright (C) 2021 LSPosed Contributors - */ - -#ifndef LSPOSED_REFLECTION_H -#define LSPOSED_REFLECTION_H - -#include "base/object.h" - -namespace art { - - CREATE_HOOK_STUB_ENTRIES( - "_ZN3art12VerifyAccessENS_6ObjPtrINS_6mirror6ObjectEEENS0_INS1_5ClassEEEjS5_", - bool, VerifyAccess, - (void * obj, void * declaring_class, uint32_t access_flags, void * calling_class), { - auto calling_desc = art::mirror::Class(calling_class).GetDescriptor(); - if (UNLIKELY(calling_desc.find("de/robv/android/xposed/LspHooker") != - std::string::npos)) { - return true; - } - return backup(obj, declaring_class, access_flags, calling_class); - }); - - static void PermissiveAccessByReflection(void *handle) { - lspd::HookSym(handle, VerifyAccess); - } -} -#endif //LSPOSED_REFLECTION_H diff --git a/core/src/main/cpp/main/src/native_hook.cpp b/core/src/main/cpp/main/src/native_hook.cpp index 5c76f89f..da0caff3 100644 --- a/core/src/main/cpp/main/src/native_hook.cpp +++ b/core/src/main/cpp/main/src/native_hook.cpp @@ -36,7 +36,6 @@ #include "art/runtime/thread.h" #include "art/runtime/hidden_api.h" #include "art/runtime/instrumentation.h" -#include "art/runtime/reflection.h" #include "art/runtime/thread_list.h" #include "art/runtime/gc/scoped_gc_critical_section.h" @@ -69,7 +68,6 @@ namespace lspd { art::mirror::Class::Setup(art_handle); art::JNIEnvExt::Setup(art_handle); art::instrumentation::DisableUpdateHookedMethodsCode(art_handle); - art::PermissiveAccessByReflection(art_handle); art::thread_list::ScopedSuspendAll::Setup(art_handle); art::gc::ScopedGCCriticalSection::Setup(art_handle); diff --git a/core/src/main/java/de/robv/android/xposed/LspHooker.java b/core/src/main/java/de/robv/android/xposed/LspHooker.java index b452769d..80b0f025 100644 --- a/core/src/main/java/de/robv/android/xposed/LspHooker.java +++ b/core/src/main/java/de/robv/android/xposed/LspHooker.java @@ -34,6 +34,7 @@ public class LspHooker { this.additionalInfo = info; this.method = origin; this.backup = backup; + this.backup.setAccessible(true); } public Object invokeOriginalMethod(Object thisObject, Object[] args) throws InvocationTargetException, IllegalAccessException {