Skip to content

Commit

Permalink
Propagate slice to context-sensitive injection points, fixes SpongePo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Oct 18, 2020
1 parent 0177c2d commit a77b390
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private Collection<TargetNode> findTargetNodes(InjectorTarget injectorTarget, Li
injectorTarget, injectorTarget.getMergedBy(), injectorTarget.getMergedPriority()));
}

if (this.findTargetNodes(method, injectionPoint, injectorTarget.getSlice(injectionPoint), nodes)) {
if (this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) {
for (AbstractInsnNode insn : nodes) {
Integer key = method.instructions.indexOf(insn);
TargetNode targetNode = targetNodes.get(key);
Expand All @@ -311,8 +311,9 @@ private Collection<TargetNode> findTargetNodes(InjectorTarget injectorTarget, Li
return targetNodes.values();
}

protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InsnList insns, Collection<AbstractInsnNode> nodes) {
return injectionPoint.find(into.desc, insns, nodes);
protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget,
Collection<AbstractInsnNode> nodes) {
return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes);
}

protected void sanityCheck(Target target, List<InjectionPoint> injectionPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
Expand Down Expand Up @@ -199,10 +200,10 @@ protected BeforeLoadLocal(InjectionPointData data, int opcode, boolean opcodeAft
}

@Override
boolean find(InjectionInfo info, Target target, Collection<AbstractInsnNode> nodes) {
boolean find(InjectionInfo info, InsnList insns, Collection<AbstractInsnNode> nodes, Target target) {
SearchState state = new SearchState();

ListIterator<AbstractInsnNode> iter = target.method.instructions.iterator();
ListIterator<AbstractInsnNode> iter = insns.iterator();
while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();
if (state.isPendingCheck()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.code.InjectorTarget;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.injection.struct.Target.Extension;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
Expand Down Expand Up @@ -88,7 +89,7 @@ public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> no
throw new InvalidInjectionException(this.mixin, this.getAtCode() + " injection point must be used in conjunction with @ModifyVariable");
}

abstract boolean find(InjectionInfo info, Target target, Collection<AbstractInsnNode> nodes);
abstract boolean find(InjectionInfo info, InsnList insns, Collection<AbstractInsnNode> nodes, Target target);

}

Expand All @@ -107,12 +108,13 @@ public ModifyVariableInjector(InjectionInfo info, LocalVariableDiscriminator dis
}

@Override
protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InsnList insns, Collection<AbstractInsnNode> nodes) {
protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget,
Collection<AbstractInsnNode> nodes) {
if (injectionPoint instanceof LocalVariableInjectionPoint) {
Target target = this.info.getContext().getTargetMethod(into);
return ((LocalVariableInjectionPoint)injectionPoint).find(this.info, target, nodes);
return ((LocalVariableInjectionPoint)injectionPoint).find(this.info, injectorTarget.getSlice(injectionPoint), nodes,
injectorTarget.getTarget());
}
return injectionPoint.find(into.desc, insns, nodes);
return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes);
}

/* (non-Javadoc)
Expand Down

0 comments on commit a77b390

Please sign in to comment.