@@ -66,11 +66,42 @@ namespace art {
6666 static void Setup (void *handle, HookFunType hook_func) {
6767 LOGD (" Classlinker hook setup, handle=%p" , handle);
6868 // TODO: Maybe not compatible with Android 10-
69+ int api_level = GetAndroidApiLevel ();
70+ size_t OFFSET_classlinker; // Get offset from art::Runtime::RunRootClinits() call in IDA
71+ switch (api_level) {
72+ case __ANDROID_API_O__:
73+ case __ANDROID_API_O_MR1__:
6974#ifdef __LP64__
70- size_t OFFSET_classlinker = 472 / 8 ;
75+ OFFSET_classlinker = 400 / 8 ;
7176#else
72- size_t OFFSET_classlinker = 276 / 4 ;
77+ OFFSET_classlinker = 240 / 4 ;
7378#endif
79+ break ;
80+ case __ANDROID_API_P__:
81+ #ifdef __LP64__
82+ OFFSET_classlinker = 528 / 8 ;
83+ #else
84+ OFFSET_classlinker = 336 / 4 ;
85+ #endif
86+ break ;
87+ case __ANDROID_API_Q__:
88+ #ifdef __LP64__
89+ OFFSET_classlinker = 480 / 8 ;
90+ #else
91+ OFFSET_classlinker = 280 / 4 ;
92+ #endif
93+ break ;
94+ default :
95+ LOGE (" No valid offset for art::Runtime::class_linker_ found. Using Android R." );
96+ case __ANDROID_API_R__:
97+ #ifdef __LP64__
98+ OFFSET_classlinker = 472 / 8 ;
99+ #else
100+ OFFSET_classlinker = 276 / 4 ;
101+ #endif
102+ break ;
103+ }
104+
74105 // ClassLinker* GetClassLinker() but inlined
75106 void * cl = reinterpret_cast <void *>(
76107 reinterpret_cast <size_t *>(Runtime::Current ()->Get ()) + OFFSET_classlinker
@@ -88,7 +119,7 @@ namespace art {
88119
89120 // Sandhook will hook ShouldUseInterpreterEntrypoint, so we just skip
90121 // edxp::Context::GetInstance()->GetVariant() will not work here, so we use smh dirty hack
91- if (GetAndroidApiLevel () >= __ANDROID_API_R__ && access (edxp::kLibSandHookNativePath .c_str (), F_OK) == -1 ) {
122+ if (api_level >= __ANDROID_API_R__ && access (edxp::kLibSandHookNativePath .c_str (), F_OK) == -1 ) {
92123 LOGD (" Not sandhook, installing _ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv" );
93124 HOOK_FUNC (ShouldUseInterpreterEntrypoint,
94125 " _ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv" );
0 commit comments