Throw HookFailedException

This commit is contained in:
Nullptr 2023-01-11 23:40:04 +08:00 committed by LoveSy
parent 73a98d6b9d
commit c69bd3fbcc
1 changed files with 48 additions and 45 deletions

View File

@ -1,7 +1,5 @@
package org.lsposed.lspd.impl;
import static de.robv.android.xposed.callbacks.XCallback.PRIORITY_DEFAULT;
import android.app.ActivityThread;
import android.app.LoadedApk;
import android.content.BroadcastReceiver;
@ -852,6 +850,7 @@ public class LSPosedContext extends XposedContext {
}
private <T, U extends Executable> MethodUnhooker<T, U> doHook(U hookMethod, int priority, T callback) {
try {
if (Modifier.isAbstract(hookMethod.getModifiers())) {
throw new IllegalArgumentException("Cannot hook abstract methods: " + hookMethod);
} else if (hookMethod.getDeclaringClass().getClassLoader() == LSPosedContext.class.getClassLoader()) {
@ -884,78 +883,82 @@ public class LSPosedContext extends XposedContext {
}
};
}
} catch (Throwable t) {
throw new HookFailedException(t);
}
log("Cannot hook " + hookMethod);
return null;
throw new HookFailedException("Cannot hook " + hookMethod);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker<Method> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker<Method> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, @NonNull Hooker<Method> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker<Method> hooker) {
return doHook(origin, priority, hooker);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker<Method> hooker) {
return doHook(origin, priority, hooker);
}
@Override
@Nullable
@NonNull
public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker<Method> hooker) {
return doHook(origin, priority, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeHooker<Constructor<T>> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterHooker<Constructor<T>> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull Hooker<Constructor<T>> hooker) {
return doHook(origin, PRIORITY_DEFAULT, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, int priority, @NonNull BeforeHooker<Constructor<T>> hooker) {
return doHook(origin, priority, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, int priority, @NonNull AfterHooker<Constructor<T>> hooker) {
return doHook(origin, priority, hooker);
}
@Override
@Nullable
@NonNull
public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, int priority, @NonNull Hooker<Constructor<T>> hooker) {
return doHook(origin, priority, hooker);
}