Add HookFailedError

This commit is contained in:
Nullptr 2023-01-14 22:52:36 +08:00
parent 1eff0ee2c9
commit a43767fa66
No known key found for this signature in database
4 changed files with 102 additions and 24 deletions

View File

@ -80,73 +80,73 @@ public class XposedContextWrapper extends ContextWrapper implements XposedInterf
return getBaseContext().featuredMethod(name, args); return getBaseContext().featuredMethod(name, args);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker<Method> hooker) { final public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker<Method> hooker) {
return getBaseContext().hookBefore(origin, hooker); return getBaseContext().hookBefore(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker<Method> hooker) { final public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker<Method> hooker) {
return getBaseContext().hookAfter(origin, hooker); return getBaseContext().hookAfter(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, @NonNull Hooker<Method> hooker) { final public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, @NonNull Hooker<Method> hooker) {
return getBaseContext().hook(origin, hooker); return getBaseContext().hook(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker<Method> hooker) { final public MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker<Method> hooker) {
return getBaseContext().hookBefore(origin, priority, hooker); return getBaseContext().hookBefore(origin, priority, hooker);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker<Method> hooker) { final public MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker<Method> hooker) {
return getBaseContext().hookAfter(origin, priority, hooker); return getBaseContext().hookAfter(origin, priority, hooker);
} }
@Nullable @NonNull
@Override @Override
final public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker<Method> hooker) { final public MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker<Method> hooker) {
return getBaseContext().hook(origin, priority, hooker); return getBaseContext().hook(origin, priority, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeHooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeHooker<Constructor<T>> hooker) {
return getBaseContext().hookBefore(origin, hooker); return getBaseContext().hookBefore(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterHooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterHooker<Constructor<T>> hooker) {
return getBaseContext().hookAfter(origin, hooker); return getBaseContext().hookAfter(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull Hooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull Hooker<Constructor<T>> hooker) {
return getBaseContext().hook(origin, hooker); return getBaseContext().hook(origin, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, int priority, @NonNull BeforeHooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, int priority, @NonNull BeforeHooker<Constructor<T>> hooker) {
return getBaseContext().hookBefore(origin, priority, hooker); return getBaseContext().hookBefore(origin, priority, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, int priority, @NonNull AfterHooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, int priority, @NonNull AfterHooker<Constructor<T>> hooker) {
return getBaseContext().hookAfter(origin, priority, hooker); return getBaseContext().hookAfter(origin, priority, hooker);
} }
@Nullable @NonNull
@Override @Override
final public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, int priority, @NonNull Hooker<Constructor<T>> hooker) { final public <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, int priority, @NonNull Hooker<Constructor<T>> hooker) {
return getBaseContext().hook(origin, priority, hooker); return getBaseContext().hook(origin, priority, hooker);

View File

@ -16,6 +16,7 @@ import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import io.github.libxposed.errors.HookFailedError;
import io.github.libxposed.utils.DexParser; import io.github.libxposed.utils.DexParser;
/** /**
@ -45,6 +46,19 @@ public interface XposedInterface {
*/ */
int FRAMEWORK_PRIVILEGE_EMBEDDED = 3; int FRAMEWORK_PRIVILEGE_EMBEDDED = 3;
/**
* The default hook priority.
*/
int PRIORITY_DEFAULT = 50;
/**
* Execute the hook callback late.
*/
int PRIORITY_LOWEST = -10000;
/**
* Execute the hook callback early.
*/
int PRIORITY_HIGHEST = 10000;
/** /**
* The interface Before hook callback. * The interface Before hook callback.
* *
@ -343,6 +357,7 @@ public interface XposedInterface {
* @param args the args * @param args the args
* @return the object * @return the object
*/ */
@Nullable
Object featuredMethod(String name, Object... args); Object featuredMethod(String name, Object... args);
/** /**
@ -351,8 +366,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker<Method> hooker); MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker<Method> hooker);
/** /**
@ -361,8 +378,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker<Method> hooker); MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker<Method> hooker);
/** /**
@ -371,8 +390,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, @NonNull Hooker<Method> hooker); MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, @NonNull Hooker<Method> hooker);
/** /**
@ -382,8 +403,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker<Method> hooker); MethodUnhooker<BeforeHooker<Method>, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker<Method> hooker);
/** /**
@ -393,8 +416,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker<Method> hooker); MethodUnhooker<AfterHooker<Method>, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker<Method> hooker);
/** /**
@ -404,8 +429,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker<Method> hooker); MethodUnhooker<Hooker<Method>, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker<Method> hooker);
/** /**
@ -415,8 +442,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeHooker<Constructor<T>> hooker); <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeHooker<Constructor<T>> hooker);
/** /**
@ -426,8 +455,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterHooker<Constructor<T>> hooker); <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterHooker<Constructor<T>> hooker);
/** /**
@ -437,8 +468,10 @@ public interface XposedInterface {
* @param origin the origin * @param origin the origin
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull Hooker<Constructor<T>> hooker); <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull Hooker<Constructor<T>> hooker);
/** /**
@ -449,8 +482,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, int priority, @NonNull BeforeHooker<Constructor<T>> hooker); <T> MethodUnhooker<BeforeHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, int priority, @NonNull BeforeHooker<Constructor<T>> hooker);
/** /**
@ -461,8 +496,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, int priority, @NonNull AfterHooker<Constructor<T>> hooker); <T> MethodUnhooker<AfterHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, int priority, @NonNull AfterHooker<Constructor<T>> hooker);
/** /**
@ -473,8 +510,10 @@ public interface XposedInterface {
* @param priority the priority * @param priority the priority
* @param hooker the hooker * @param hooker the hooker
* @return the method unhooker * @return the method unhooker
* @throws IllegalArgumentException if origin is abstract, framework internal or {@link Method#invoke}
* @throws HookFailedError if hook fails due to framework internal error
*/ */
@Nullable @NonNull
<T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, int priority, @NonNull Hooker<Constructor<T>> hooker); <T> MethodUnhooker<Hooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, int priority, @NonNull Hooker<Constructor<T>> hooker);
/** /**

View File

@ -0,0 +1,20 @@
package io.github.libxposed.errors;
/**
* Thrown to indicate that a hook failed due to framework internal error.
*/
@SuppressWarnings("unused")
public class HookFailedError extends XposedFrameworkError {
public HookFailedError(String message) {
super(message);
}
public HookFailedError(String message, Throwable cause) {
super(message, cause);
}
public HookFailedError(Throwable cause) {
super(cause);
}
}

View File

@ -0,0 +1,19 @@
package io.github.libxposed.errors;
/**
* Thrown to indicate that the Xposed framework function is broken.
*/
public abstract class XposedFrameworkError extends Error {
public XposedFrameworkError(String message) {
super(message);
}
public XposedFrameworkError(String message, Throwable cause) {
super(message, cause);
}
public XposedFrameworkError(Throwable cause) {
super(cause);
}
}