From e5379ea27ee682e6f0f1fe1c4d2bf61f9a1d0077 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Fri, 29 Jan 2021 06:42:41 +0800 Subject: [PATCH] Fix pendding hook on R --- .../main/include/art/runtime/class_linker.h | 24 +++++++++++++------ .../github/lsposed/lspd/util/ClassUtils.java | 4 ---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/src/main/cpp/main/include/art/runtime/class_linker.h b/core/src/main/cpp/main/include/art/runtime/class_linker.h index 46bc1cbd..1fc11288 100644 --- a/core/src/main/cpp/main/include/art/runtime/class_linker.h +++ b/core/src/main/cpp/main/include/art/runtime/class_linker.h @@ -45,11 +45,12 @@ namespace art { }); CREATE_MEM_HOOK_STUB_ENTRIES( - "_ZN3art11ClassLinker22FixupStaticTrampolinesEPNS_6ThreadENS_6ObjPtrINS_6mirror5ClassEEE", - void, FixupStaticTrampolinesWithThread, (void * thiz, - void * thread, void * clazz_ptr), { - backup(thiz, thread, clazz_ptr); - MaybeDelayHook(clazz_ptr); + "_ZN3art11ClassLinker20MarkClassInitializedEPNS_6ThreadENS_6HandleINS_6mirror5ClassEEE", + void*, MarkClassInitialized, (void * thiz, void * self, uint32_t * clazz_ptr), { + void *result = backup(thiz, self, clazz_ptr); + auto ptr = reinterpret_cast(*clazz_ptr); + MaybeDelayHook(ptr); + return result; }); CREATE_MEM_FUNC_SYMBOL_ENTRY(void, MakeInitializedClassesVisiblyInitialized, void *thiz, @@ -126,10 +127,19 @@ namespace art { RETRIEVE_MEM_FUNC_SYMBOL(SetEntryPointsToInterpreter, "_ZNK3art11ClassLinker27SetEntryPointsToInterpreterEPNS_9ArtMethodE"); - lspd::HookSyms(handle, hook_func, FixupStaticTrampolines, - FixupStaticTrampolinesWithThread); lspd::HookSyms(handle, hook_func, ShouldUseInterpreterEntrypoint); + if (api_level >= __ANDROID_API_R__) { + // In android R, FixupStaticTrampolines won't be called unless it's marking it as + // invisiblyInitialized. + // So we miss some calls between initialized and invisiblyInitialized. + // Therefore we hook the new introduced MarkClassInitialized instead + // This only happens on non-x86 devices + lspd::HookSyms(handle, hook_func, MarkClassInitialized); + } else { + lspd::HookSyms(handle, hook_func, FixupStaticTrampolines); + } + // MakeInitializedClassesVisiblyInitialized will cause deadlock // IsQuickToInterpreterBridge is inlined // So we use GetSavedEntryPointOfPreCompiledMethod instead diff --git a/core/src/main/java/io/github/lsposed/lspd/util/ClassUtils.java b/core/src/main/java/io/github/lsposed/lspd/util/ClassUtils.java index a24da956..407ce36e 100644 --- a/core/src/main/java/io/github/lsposed/lspd/util/ClassUtils.java +++ b/core/src/main/java/io/github/lsposed/lspd/util/ClassUtils.java @@ -29,13 +29,9 @@ public class ClassUtils { * 5.0-8.0: kInitialized = 10 int * 8.1: kInitialized = 11 int * 9.0+: kInitialized = 14 uint8_t - * 11.0+: kVisiblyInitialized = 15 uint8_t */ @ApiSensitive(Level.MIDDLE) public static boolean isInitialized(Class clazz) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - return getClassStatus(clazz, true) == 15; - } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { return getClassStatus(clazz, true) == 14; } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) {