Add a temporary workaround to fix Application#attach(Context) hook not working
This commit is contained in:
parent
2366e5a0d3
commit
045104d1bf
|
|
@ -0,0 +1,35 @@
|
|||
package com.elderdrivers.riru.xposed.util;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MethodHookUtils {
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* Some methods, for instance Application#attach(Context) in framework would be inlined,
|
||||
* which makes our hooking of them not working.
|
||||
* Actually we can append --debuggable option to dexoat args to avoid inlining,
|
||||
* but it has significant impact on app's performance.
|
||||
* So here is just a temporary workaround.
|
||||
*/
|
||||
public static Member preCheck(Member target) {
|
||||
try {
|
||||
if (target instanceof Method) {
|
||||
Method method = (Method) target;
|
||||
if (method.getDeclaringClass().equals(Application.class)
|
||||
&& method.getName().equals("attach")) {
|
||||
return ContextWrapper.class.getDeclaredMethod("attachBaseContext", Context.class);
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
Utils.logE("error when preCheck " + target, throwable);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import android.util.Log;
|
|||
import com.elderdrivers.riru.xposed.core.HookMain;
|
||||
import com.elderdrivers.riru.xposed.dexmaker.DynamicBridge;
|
||||
import com.elderdrivers.riru.xposed.dexmaker.MethodInfo;
|
||||
import com.elderdrivers.riru.xposed.util.MethodHookUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -154,6 +155,7 @@ public final class XposedBridge {
|
|||
* @see #hookAllConstructors
|
||||
*/
|
||||
public static XC_MethodHook.Unhook hookMethod(Member hookMethod, XC_MethodHook callback) {
|
||||
hookMethod = MethodHookUtils.preCheck(hookMethod);
|
||||
if (!(hookMethod instanceof Method) && !(hookMethod instanceof Constructor<?>)) {
|
||||
throw new IllegalArgumentException("Only methods and constructors can be hooked: " + hookMethod.toString());
|
||||
} else if (hookMethod.getDeclaringClass().isInterface()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue