[core] Support interface default method (#420)

This commit is contained in:
LoveSy 2021-03-27 20:31:06 +08:00 committed by GitHub
parent 0facfb958a
commit 833eef49ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 22 deletions

View File

@ -169,9 +169,12 @@ public final class XposedBridge {
public static XC_MethodHook.Unhook hookMethod(Member hookMethod, XC_MethodHook callback) {
if (!(hookMethod instanceof Executable)) {
throw new IllegalArgumentException("Only methods and constructors can be hooked: " + hookMethod.toString());
} else if (hookMethod.getDeclaringClass().isInterface()) {
}
// No check interface because there may be default methods
/*else if (hookMethod.getDeclaringClass().isInterface()) {
throw new IllegalArgumentException("Cannot hook interfaces: " + hookMethod.toString());
} else if (Modifier.isAbstract(hookMethod.getModifiers())) {
}*/
else if (Modifier.isAbstract(hookMethod.getModifiers())) {
throw new IllegalArgumentException("Cannot hook abstract methods: " + hookMethod.toString());
}
@ -196,7 +199,7 @@ public final class XposedBridge {
if (newMethod) {
AdditionalHookInfo additionalInfo = new AdditionalHookInfo(callbacks);
if (!YahfaHooker.shouldDelayHook(targetMethod)) {
DynamicBridge.hookMethod(targetMethod, (AdditionalHookInfo) additionalInfo);
YahfaHooker.hookMethod(targetMethod, additionalInfo);
} else {
PendingHooks.recordPendingMethod((Method)hookMethod, additionalInfo);
}

View File

@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
import de.robv.android.xposed.LspHooker;
import de.robv.android.xposed.XposedBridge;
import org.lsposed.lspd.util.Logger;
public final class DynamicBridge {
@ -36,9 +37,6 @@ public final class DynamicBridge {
public static synchronized void hookMethod(Executable hookMethod, XposedBridge.AdditionalHookInfo additionalHookInfo) {
Logger.d("hooking " + hookMethod);
if (!checkMember(hookMethod)) {
return;
}
if (hookedInfo.containsKey(hookMethod)) {
Logger.w("already hook method:" + hookMethod.toString());
@ -55,17 +53,6 @@ public final class DynamicBridge {
}
}
private static boolean checkMember(Executable member) {
if (member.getDeclaringClass().isInterface()) {
Logger.e("Cannot hook interfaces: " + member.toString());
return false;
} else if (Modifier.isAbstract(member.getModifiers())) {
Logger.e("Cannot hook abstract methods: " + member.toString());
return false;
}
return true;
}
public static Object invokeOriginalMethod(Member method, Object thisObject, Object[] args)
throws InvocationTargetException, IllegalAccessException {
LspHooker hooker = hookedInfo.get(method);

View File

@ -63,11 +63,6 @@ public class HookerDexMaker {
public void start(Executable member, XposedBridge.AdditionalHookInfo hookInfo,
ClassLoader appClassLoader) throws Exception {
if (member.getDeclaringClass().isInterface()) {
throw new IllegalArgumentException("Cannot hook interfaces: " + member.toString());
} else if (Modifier.isAbstract(member.getModifiers())) {
throw new IllegalArgumentException("Cannot hook abstract methods: " + member.toString());
}
if (member instanceof Method) {
Method method = (Method) member;
mReturnType = method.getReturnType();