From 15c1aa51d323728135251a6b75f21b720d7439fe Mon Sep 17 00:00:00 2001 From: kotori0 Date: Thu, 5 Nov 2020 20:44:17 +0800 Subject: [PATCH] Get ClassLinker instance from art::Runtime --- .../cpp/main/include/art/runtime/class_linker.h | 16 ++++++++++++++++ .../main/cpp/main/include/art/runtime/runtime.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h b/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h index 2c76d125..60d2aeef 100644 --- a/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h +++ b/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h @@ -23,6 +23,7 @@ namespace art { } CREATE_HOOK_STUB_ENTRIES(void *, Constructor, void *thiz, void *intern_table) { + LOGI("ConstructorReplace called"); if (LIKELY(instance_)) instance_->Reset(thiz); else @@ -62,6 +63,20 @@ namespace art { // @ApiSensitive(Level.MIDDLE) static void Setup(void *handle, HookFunType hook_func) { + LOGD("Classlinker hook setup, handle=%p", handle); + // TODO: Maybe not compatible with Android 10- +#ifdef __LP64__ + size_t OFFSET_classlinker = 472 / 8; +#else + size_t OFFSET_classlinker = 276 / 4; +#endif + // ClassLinker* GetClassLinker() but inlined + void* cl = reinterpret_cast( + reinterpret_cast(Runtime::Current()->Get()) + OFFSET_classlinker + ); + LOGD("Classlinker object: %p", cl); + instance_ = new ClassLinker(cl); + HOOK_FUNC(Constructor, "_ZN3art11ClassLinkerC2EPNS_11InternTableE", "_ZN3art11ClassLinkerC2EPNS_11InternTableEb"); // 10.0 RETRIEVE_FUNC_SYMBOL(SetEntryPointsToInterpreter, @@ -76,6 +91,7 @@ namespace art { } ALWAYS_INLINE void SetEntryPointsToInterpreter(void *art_method) const { + LOGD("SetEntryPointsToInterpreter start, thiz=%p, art_method=%p", thiz_, art_method); if (LIKELY(thiz_)) SetEntryPointsToInterpreter(thiz_, art_method); } diff --git a/edxp-core/src/main/cpp/main/include/art/runtime/runtime.h b/edxp-core/src/main/cpp/main/include/art/runtime/runtime.h index 7451aba2..2e3ddc35 100644 --- a/edxp-core/src/main/cpp/main/include/art/runtime/runtime.h +++ b/edxp-core/src/main/cpp/main/include/art/runtime/runtime.h @@ -41,6 +41,9 @@ namespace art { HOOK_FUNC(Init, "_ZN3art7Runtime4InitEONS_18RuntimeArgumentMapE"); RETRIEVE_FUNC_SYMBOL(DeoptimizeBootImage, "_ZN3art7Runtime19DeoptimizeBootImageEv"); + RETRIEVE_FIELD_SYMBOL(thiz, "_ZN3art7Runtime9instance_E"); + LOGD("_ZN3art7Runtime9instance_E = %p", thiz); + instance_ = new Runtime(thiz); } ALWAYS_INLINE void DeoptimizeBootImage() const {