public class RedirectInjector extends InvokeInjector
A bytecode injector which allows a method call, field access or new object creation to be redirected to the annotated handler method. For method redirects, the handler method signature must match the hooked method precisely but prepended with an arg of the owning object's type to accept the object instance the method was going to be invoked upon. For example when hooking the following call:
int abc = 0; int def = 1; Foo someObject = new Foo(); // Hooking this method boolean xyz = someObject.bar(abc, def);
The signature of the redirected method should be:
public boolean barProxy(Foo someObject, int abc, int def)
For obvious reasons this does not apply for static methods, for static methods it is sufficient that the signature simply match the hooked method.
For field redirections, see the details in Redirect for the
required signature of the handler method.
For constructor redirections, the signature of the handler method should match the constructor itself, return type should be of the type of object being created.
Injector.TargetNode| Modifier and Type | Field and Description |
|---|---|
protected org.spongepowered.asm.mixin.injection.invoke.RedirectInjector.Meta |
meta |
annotationTypeclassNode, info, isStatic, logger, methodArgs, methodNode, returnType| Modifier | Constructor and Description |
|---|---|
|
RedirectInjector(InjectionInfo info) |
protected |
RedirectInjector(InjectionInfo info,
java.lang.String annotationType) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addTargetNode(Target target,
java.util.List<InjectionNodes.InjectionNode> myNodes,
org.spongepowered.asm.lib.tree.AbstractInsnNode insn,
java.util.Set<InjectionPoint> nominators) |
protected boolean |
checkDescriptor(java.lang.String desc,
Target target,
java.lang.String type)
Check that the handler descriptor matches the calculated descriptor for
the access being redirected.
|
protected void |
checkTarget(Target target)
Sanity checks on target
|
protected void |
inject(Target target,
InjectionNodes.InjectionNode node) |
void |
injectArrayRedirect(Target target,
org.spongepowered.asm.lib.tree.FieldInsnNode fieldNode,
org.spongepowered.asm.lib.tree.AbstractInsnNode varNode,
boolean withArgs,
java.lang.String type)
The code for actually redirecting the array element is the same
regardless of whether it's a read or write because it just depends on the
actual handler signature, the correct arguments are already on the stack
thanks to the nature of xALOAD and xASTORE.
|
protected void |
injectAtConstructor(Target target,
InjectionNodes.InjectionNode node) |
protected void |
injectAtInvoke(Target target,
InjectionNodes.InjectionNode node)
Redirect a method invocation
|
void |
injectAtScalarField(Target target,
org.spongepowered.asm.lib.tree.FieldInsnNode fieldNode,
int opCode,
org.spongepowered.asm.lib.Type ownerType,
org.spongepowered.asm.lib.Type fieldType)
Redirect a field get or set
|
protected void |
postInject(Target target,
InjectionNodes.InjectionNode node) |
protected boolean |
preInject(InjectionNodes.InjectionNode node) |
protected void |
validateParams(org.spongepowered.asm.mixin.injection.invoke.RedirectInjector.RedirectedInvoke invoke)
Perform validation of an invoke handler parameters, each parameter in the
handler must match the expected type or be annotated with
Coerce
and be a supported supertype of the incoming type. |
checkTargetForNode, checkTargetModifiers, invokeHandlerWithArgs, invokeHandlerWithArgs, pushArgs, sanityCheck, storeArgs, storeArgscanCoerce, canCoerce, canCoerce, find, findTargetNodes, inject, invokeHandler, invokeHandler, throwException, toStringpublic RedirectInjector(InjectionInfo info)
info - Injection infoprotected RedirectInjector(InjectionInfo info, java.lang.String annotationType)
protected void checkTarget(Target target)
InvokeInjectorcheckTarget in class InvokeInjectortarget - targetprotected void addTargetNode(Target target, java.util.List<InjectionNodes.InjectionNode> myNodes, org.spongepowered.asm.lib.tree.AbstractInsnNode insn, java.util.Set<InjectionPoint> nominators)
addTargetNode in class Injectorprotected void inject(Target target, InjectionNodes.InjectionNode node)
inject in class InvokeInjectorprotected boolean preInject(InjectionNodes.InjectionNode node)
protected void postInject(Target target, InjectionNodes.InjectionNode node)
postInject in class Injectorprotected void injectAtInvoke(Target target, InjectionNodes.InjectionNode node)
injectAtInvoke in class InvokeInjectortarget - Target to inject intonode - Discovered instruction nodeprotected void validateParams(org.spongepowered.asm.mixin.injection.invoke.RedirectInjector.RedirectedInvoke invoke)
Coerce
and be a supported supertype of the incoming type.invoke - invocation being redirectedpublic void injectArrayRedirect(Target target, org.spongepowered.asm.lib.tree.FieldInsnNode fieldNode, org.spongepowered.asm.lib.tree.AbstractInsnNode varNode, boolean withArgs, java.lang.String type)
target - target methodfieldNode - field nodevarNode - array access nodewithArgs - true if the descriptor includes captured arguments from
the target method signaturetype - description of access type for use in error messagespublic void injectAtScalarField(Target target, org.spongepowered.asm.lib.tree.FieldInsnNode fieldNode, int opCode, org.spongepowered.asm.lib.Type ownerType, org.spongepowered.asm.lib.Type fieldType)
target - target methodfieldNode - field access nodeopCode - field access typeownerType - type of the field ownerfieldType - field typeprotected boolean checkDescriptor(java.lang.String desc,
Target target,
java.lang.String type)
desc - computed descriptortarget - target methodtype - redirector type in human-readable text, for error messagesprotected void injectAtConstructor(Target target, InjectionNodes.InjectionNode node)