@Retention(value=CLASS)
@Target(value={METHOD,CONSTRUCTOR})
public @interface CInject
void and can have the following arguments:InjectionCallback for cancelling the original method and returning valuesObject instead of the actual type (useful if classes are not accessible).CLocalVariable.cancellable() is set to true.
Not doing so will throw an exception when calling InjectionCallback.setCancelled(boolean).
If the target method has a return value you have to use InjectionCallback.setReturnValue(Object) to change it.
Calling this method will also call InjectionCallback.setCancelled(boolean) with true internally.RETURN, TAIL and THROW the callback will contain the return value or the thrown exception.
It can be accessed by calling InjectionCallback.getReturnValue() or InjectionCallback.castReturnValue().
The return value can be changed but skipping the return/throw is not possible.
@CInject(method = "print(Ljava/lang/String;)V", target = @CTarget("HEAD"))
public void injectHead(String text, InjectionCallback callback) {
//Do something at the top of the method
}
Injecting above a method call:
@CInject(method = "print", target = @CTarget(value = "INVOKE", target = "...", shift = CTarget.Shift.BEFORE))
public void injectBefore(String text, InjectionCallback callback) {
//Do something before the method call
}
See CTarget for more information about targets.slice() to narrow down the search.CTarget,
CSlice,
GitHub Wiki| Modifier and Type | Required Element and Description |
|---|---|
java.lang.String[] |
method
The method name and descriptor to inject into.
|
CTarget[] |
target
The targets for the injection.
|
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
cancellable
Allow the target method to be cancelled.
|
CSlice |
slice
The slice to narrow down the search for the target.
|
public abstract java.lang.String[] method
print(Ljava/lang/String;)V or print*public abstract CTarget[] target
public abstract CSlice slice
public abstract boolean cancellable
InjectionCallback.