Add back hook callbacks
This commit is contained in:
parent
74534aa0c1
commit
b581d269a3
|
|
@ -64,10 +64,128 @@ public interface XposedInterface {
|
||||||
*/
|
*/
|
||||||
int PRIORITY_HIGHEST = 10000;
|
int PRIORITY_HIGHEST = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contextual interface for before invocation callbacks.
|
||||||
|
*/
|
||||||
|
interface BeforeHookCallback {
|
||||||
|
/**
|
||||||
|
* Gets the method / constructor to be hooked.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Member getMember();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@code this} object, or {@code null} if the method is static.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
Object getThisObject();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the arguments passed to the method / constructor. You can modify the arguments.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Object[] getArgs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the return value of the method and skip the invocation. If the procedure is a constructor,
|
||||||
|
* the {@code result} param will be ignored.
|
||||||
|
* Note that the after invocation callback will still be called.
|
||||||
|
*
|
||||||
|
* @param result The return value
|
||||||
|
*/
|
||||||
|
void returnAndSkip(@Nullable Object result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw an exception from the method / constructor and skip the invocation.
|
||||||
|
* Note that the after invocation callback will still be called.
|
||||||
|
*
|
||||||
|
* @param throwable The exception to be thrown
|
||||||
|
*/
|
||||||
|
void throwAndSkip(@Nullable Throwable throwable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an extra object to the hook context in order to share additional contextual information
|
||||||
|
* between the before and after invocation callbacks of the same procedure call.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the extra object
|
||||||
|
* @param key The name of the extra object
|
||||||
|
* @param value The extra object
|
||||||
|
*/
|
||||||
|
<T> void setExtra(@NonNull String key, @Nullable T value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contextual interface for after invocation callbacks.
|
||||||
|
*/
|
||||||
|
interface AfterHookCallback {
|
||||||
|
/**
|
||||||
|
* Gets the method / constructor to be hooked.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Member getMember();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@code this} object, or {@code null} if the method is static.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
Object getThisObject();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all arguments passed to the method / constructor.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Object[] getArgs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the return value of the method or the before invocation callback. If the procedure is a
|
||||||
|
* constructor, a void method or an exception was thrown, the return value will be {@code null}.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
Object getResult();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the exception thrown by the method / constructor or the before invocation callback. If the
|
||||||
|
* procedure call was successful, the return value will be {@code null}.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
Throwable getThrowable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the invocation was skipped by the before invocation callback.
|
||||||
|
*/
|
||||||
|
boolean isSkipped();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the return value of the method and skip the invocation. If the procedure is a constructor,
|
||||||
|
* the {@code result} param will be ignored.
|
||||||
|
*
|
||||||
|
* @param result The return value
|
||||||
|
*/
|
||||||
|
void setResult(@Nullable Object result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the exception thrown by the method / constructor.
|
||||||
|
*
|
||||||
|
* @param throwable The exception to be thrown.
|
||||||
|
*/
|
||||||
|
void setThrowable(@Nullable Throwable throwable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an extra object saved by the before invocation callback of the same procedure call.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the extra object
|
||||||
|
* @param key The name of the extra object
|
||||||
|
* @return The extra object, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
<T> T getExtra(@NonNull String key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for method / constructor hooking. Xposed modules should define their own hooker class
|
* Interface for method / constructor hooking. Xposed modules should define their own hooker class
|
||||||
* and implement this interface. Normally, there could be one global hooker class for all method
|
* and implement this interface. Normally, a hooker class corresponds to a method / constructor, but
|
||||||
* hooking.
|
* there could also be a single hooker class for all of them. By this way you can implement an interface
|
||||||
|
* like the old API.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Classes implementing this interface should be annotated with {@link XposedHooker} and should provide
|
* Classes implementing this interface should be annotated with {@link XposedHooker} and should provide
|
||||||
|
|
@ -77,19 +195,12 @@ public interface XposedInterface {
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* The before invocation method should have the following signature:<br/>
|
* The before invocation method should have the following signature:<br/>
|
||||||
* params: {@code member} - The {@link Member} object representing the method or constructor being hooked<br/>
|
* params: {@code callback} - The {@link BeforeHookCallback} of the procedure call<br/>
|
||||||
*
|
|
||||||
* {@code thisObject} - The {@code this} pointer, or null if the method is static<br/>
|
|
||||||
*
|
|
||||||
* {@code args} - The arguments used for the method call<br/>
|
|
||||||
* returns: An {@link Hooker} object, used to save contextual information for current invocation routine
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* The after invocation method should have the following signature:<br/>
|
* The after invocation method should have the following signature:<br/>
|
||||||
* params: {@code extras} - The {@link Hooker} object returned by the before invocation method<br/>
|
* params: {@code callback} - The {@link AfterHookCallback} of the procedure call<br/>
|
||||||
*
|
|
||||||
* {@code result} - The result of the invocation
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>Example usage:</p>
|
* <p>Example usage:</p>
|
||||||
|
|
@ -99,14 +210,12 @@ public interface XposedInterface {
|
||||||
* public class ExampleHooker implements XposedInterface.Hooker {
|
* public class ExampleHooker implements XposedInterface.Hooker {
|
||||||
*
|
*
|
||||||
* @BeforeInvocation
|
* @BeforeInvocation
|
||||||
* public static @Nullable XposedInterface.Hooker
|
* public static void before(@NonNull BeforeHookCallback callback) {
|
||||||
* before(@NonNull Member member, @Nullable Object thisObject, @NonNull Object[] args) {
|
|
||||||
* // Pre-hooking logic goes here
|
* // Pre-hooking logic goes here
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @AfterInvocation
|
* @AfterInvocation
|
||||||
* public static void
|
* public static void after(@NonNull AfterHookCallback callback) {
|
||||||
* after(@Nullable XposedInterface.Hooker extras, @Nullable Object result) {
|
|
||||||
* // Post-hooking logic goes here
|
* // Post-hooking logic goes here
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue