static void OnAtraceFuncCalled() {
void
*
current_thread_ptr
=
runtime::CurrentThreadFunc();
JNIEnv
*
env
=
runtime::GetJNIEnvFromThread(current_thread_ptr);
if
(!env) {
LOGE(
"Failed to get JNIEnv, Inject Xposed Module failed."
);
return
;
}
InjectXposedLibraryInternal(env);
}
int
DoInjection(JNIEnv
*
env) {
runtime::InitRuntime();
void
*
current_thread_ptr
=
nullptr;
if
(!env) {
current_thread_ptr
=
runtime::CurrentThreadFunc();
env
=
runtime::GetJNIEnvFromThread(current_thread_ptr);
}
if
(!env) {
LOGE(
"Failed to get JNIEnv !!"
);
return
-
1
;
}
/
/
ptrace到JNI方法Java_java_lang_Object_wait时,会出现由于等锁导致的env
-
>FindClass卡死的问题,这里Handler中加载xposed模块
/
/
ptrace到JNIT方法Java_com_android_internal_os_ClassLoaderFactory_createClassloaderNamespace时,正在构造classLoader此时调用FindClass会卡死
/
/
这里绕过这两个方法,发送任务到主线程Handler执行;
void
*
art_method
=
runtime::GetCurrentMethod(current_thread_ptr, false, false);
if
(art_method !
=
nullptr) {
std::string name
=
runtime::JniShortName(art_method);
if
(strcmp(name.c_str(),
"Java_java_lang_Object_wait"
)
=
=
0
|| strcmp(name.c_str(),
"Java_com_android_internal_os_ClassLoaderFactory_createClassloaderNamespace"
)
=
=
0
) {
/
/
load xposed modules after
in
the main message handler, this
is
later than application's attachBaseContext
and
onCreate method.
InjectXposedLibraryByHandler(env);
return
0
;
}
}
/
/
If the inject time
is
very early, then, the loadedapk info
and
the app classloader
is
not
ready, so we
try
to hook atrace_set_debuggable function to make sure
/
/
the injection
is
early enough
and
the classloader has also been created.
jobject loaded_apk_obj
=
jni::GetLoadedApkObj(env);
LOGD(
"Try to get the app loaded apk info, loadedapk jobject: %p"
, loaded_apk_obj);
if
(loaded_apk_obj
=
=
nullptr) {
/
/
load xposed modules after atrace_set_debuggable
or
atrace_update_tags
is
called.
HookAtraceFunctions(OnAtraceFuncCalled);
}
else
{
/
/
loadedapk
and
classloader
is
ready, so load the xposed modules directly.
InjectXposedLibraryInternal(env);
}
return
0
;
}