mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-18 20:49:12 +00:00
Add AfterInvoke (INVOKE_ASSIGN) injection point type
This commit is contained in:
1 parent
10040e9f3d
commit
7427f06dbb
4 files changed
+124
-6
No files matched your search
@@ -62,6 +62,8 @@ public @interface At {
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.MethodHead HEAD},
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.BeforeReturn RETURN},
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.BeforeInvoke INVOKE},
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.AfterInvoke
|
||||
* INVOKE_ASSIGN},
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess
|
||||
* FIELD},
|
||||
* {@link org.spongepowered.asm.mixin.injection.points.BeforeNew NEW},
|
||||
@@ -104,10 +106,10 @@ public @interface At {
|
||||
public String[] args() default { };
|
||||
|
||||
/**
|
||||
* Target member used by INVOKE, INVOKE_STRING and FIELD. This <b>must be
|
||||
* specified as a fully-qualified member path</b> including the class name
|
||||
* and signature. Failing to fully-qualify the target member will result in
|
||||
* an error at obfuscation time.
|
||||
* Target member used by INVOKE, INVOKE_STRING, INVOKE_ASSIGN and FIELD.
|
||||
* This <b>must be specified as a fully-qualified member path</b> including
|
||||
* the class name and signature. Failing to fully-qualify the target member
|
||||
* will result in an error at obfuscation time.
|
||||
*
|
||||
* @return target reference for supported InjectionPoint types
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.List;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.mixin.injection.points.AfterInvoke;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeInvoke;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeNew;
|
||||
@@ -91,6 +92,22 @@ public abstract class InjectionPoint {
|
||||
public String toString() {
|
||||
return "InjectionPoint(" + this.getClass().getSimpleName() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the insn immediately following the specified insn, or return the same
|
||||
* insn if the insn is the last insn in the list
|
||||
*
|
||||
* @param insns Insn list to fetch from
|
||||
* @param insn Insn node
|
||||
* @return Next insn or the same insn if last in the list
|
||||
*/
|
||||
protected static AbstractInsnNode nextNode(InsnList insns, AbstractInsnNode insn) {
|
||||
int index = insns.indexOf(insn) + 1;
|
||||
if (index > 0 && index < insns.size()) {
|
||||
return insns.get(index);
|
||||
}
|
||||
return insn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Composite injection point
|
||||
@@ -360,6 +377,8 @@ public abstract class InjectionPoint {
|
||||
point = new JumpInsnPoint(data);
|
||||
} else if (MethodHead.CODE.equals(at)) {
|
||||
point = new MethodHead(data);
|
||||
} else if (AfterInvoke.CODE.equals(at)) {
|
||||
point = new AfterInvoke(data);
|
||||
} else if (at.matches("^([A-Za-z_][A-Za-z0-9_]*\\.)+[A-Za-z_][A-Za-z0-9_]*$")) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked") Class<? extends InjectionPoint> cls = (Class<? extends InjectionPoint>) Class.forName(at);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.points;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
|
||||
|
||||
/**
|
||||
* <p>This injection point searches for INVOKEVIRTUAL, INVOKESTATIC and
|
||||
* INVOKESPECIAL opcodes matching its arguments and returns a list of insns
|
||||
* after the matching instructions, with special handling for methods
|
||||
* invocations which return a value and immediately assign it to a local
|
||||
* variable. It accepts the following parameters from
|
||||
* {@link org.spongepowered.asm.mixin.injection.At At}:</p>
|
||||
*
|
||||
* <dl>
|
||||
* <dt>target</dt>
|
||||
* <dd>A
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo MemberInfo}
|
||||
* which identifies the target method</dd>
|
||||
* <dt>ordinal</dt>
|
||||
* <dd>The ordinal position of the method invocation to match. For example if
|
||||
* the method is invoked 3 times and you want to match the 3rd then you can
|
||||
* specify an <em>ordinal</em> of <b>2</b> (ordinals are zero-indexed). The
|
||||
* default value is <b>-1</b> which supresses ordinal matching</dd>
|
||||
* </dl>
|
||||
*
|
||||
* <p>Example:</p>
|
||||
* <blockquote><pre>
|
||||
* @At(value = "INVOKE_ASSIGN", target="func_1234_a(III)J")</pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p>Note that unlike other standard injection points, this class matches the
|
||||
* insn after the invocation, and after any local variable assignment. Use the
|
||||
* {@link org.spongepowered.asm.mixin.injection.At#shift shift} specifier to
|
||||
* adjust the matched opcode as necessary.</p>
|
||||
*/
|
||||
public class AfterInvoke extends BeforeInvoke {
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
public static final String CODE = "INVOKE_ASSIGN";
|
||||
|
||||
public AfterInvoke(InjectionPointData data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean addInsn(InsnList insns, Collection<AbstractInsnNode> nodes, AbstractInsnNode insn) {
|
||||
MethodInsnNode methodNode = (MethodInsnNode)insn;
|
||||
if (Type.getReturnType(methodNode.desc) == Type.VOID_TYPE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
insn = InjectionPoint.nextNode(insns, insn);
|
||||
if (insn instanceof VarInsnNode && insn.getOpcode() >= Opcodes.ISTORE) {
|
||||
insn = InjectionPoint.nextNode(insns, insn);
|
||||
}
|
||||
|
||||
nodes.add(insn);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -137,8 +137,7 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
this.logger.info("{} > > > found a matching insn at ordinal {}", this.className, ordinal);
|
||||
}
|
||||
|
||||
nodes.add(insn);
|
||||
found = true;
|
||||
found |= this.addInsn(insns, nodes, insn);
|
||||
|
||||
if (this.ordinal == ordinal) {
|
||||
break;
|
||||
@@ -155,6 +154,11 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
return found;
|
||||
}
|
||||
|
||||
protected boolean addInsn(InsnList insns, Collection<AbstractInsnNode> nodes, AbstractInsnNode insn) {
|
||||
nodes.add(insn);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean matchesInsn(AbstractInsnNode insn) {
|
||||
return insn instanceof MethodInsnNode;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user