public abstract class XC_MethodReplacement extends XC_MethodHook
XC_MethodHook
which completely replaces the original method.XC_MethodHook.MethodHookParam<T extends java.lang.reflect.Executable>, XC_MethodHook.Unhook
XCallback.Param
Modifier and Type | Field and Description |
---|---|
static XC_MethodReplacement |
DO_NOTHING
Predefined callback that skips the method without replacements.
|
priority, PRIORITY_DEFAULT, PRIORITY_HIGHEST, PRIORITY_LOWEST
Modifier and Type | Method and Description |
---|---|
protected void |
afterHookedMethod(XC_MethodHook.MethodHookParam param)
Called after the invocation of the method.
|
protected void |
beforeHookedMethod(XC_MethodHook.MethodHookParam param)
Called before the invocation of the method.
|
protected abstract java.lang.Object |
replaceHookedMethod(XC_MethodHook.MethodHookParam param)
Shortcut for replacing a method completely.
|
static XC_MethodReplacement |
returnConstant(int priority,
java.lang.Object result)
Like
returnConstant(Object) , but allows to specify a priority for the callback. |
static XC_MethodReplacement |
returnConstant(java.lang.Object result)
Creates a callback which always returns a specific value.
|
callAfterHookedMethod, callBeforeHookedMethod
public static final XC_MethodReplacement DO_NOTHING
protected final void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws java.lang.Throwable
XC_MethodHook
You can use XC_MethodHook.MethodHookParam.setResult(java.lang.Object)
and XC_MethodHook.MethodHookParam.setThrowable(java.lang.Throwable)
to prevent the original method from being called.
Note that implementations shouldn't call super(param)
, it's not necessary.
beforeHookedMethod
in class XC_MethodHook
param
- Information about the method call.java.lang.Throwable
- Everything the callback throws is caught and logged.protected final void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws java.lang.Throwable
XC_MethodHook
You can use XC_MethodHook.MethodHookParam.setResult(java.lang.Object)
and XC_MethodHook.MethodHookParam.setThrowable(java.lang.Throwable)
to modify the return value of the original method.
Note that implementations shouldn't call super(param)
, it's not necessary.
afterHookedMethod
in class XC_MethodHook
param
- Information about the method call.java.lang.Throwable
- Everything the callback throws is caught and logged.protected abstract java.lang.Object replaceHookedMethod(XC_MethodHook.MethodHookParam param) throws java.lang.Throwable
Note that implementations shouldn't call super(param)
, it's not necessary.
param
- Information about the method call.java.lang.Throwable
- Anything that is thrown by the callback will be passed on to the original caller.public static XC_MethodReplacement returnConstant(java.lang.Object result)
result
- The value that should be returned to callers of the hooked method.public static XC_MethodReplacement returnConstant(int priority, java.lang.Object result)
returnConstant(Object)
, but allows to specify a priority for the callback.priority
- See XCallback.priority
.result
- The value that should be returned to callers of the hooked method.