removes rl-client.rs.mixins
This commit is contained in:
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.runelite.client.rs.mixins.transformers.DoNothingTransformer;
|
||||
import net.runelite.client.rs.mixins.transformers.SanityChecker;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MixinRunner
|
||||
{
|
||||
|
||||
private final Map<String, byte[]> classes;
|
||||
private final Map<String, byte[]> patches;
|
||||
|
||||
public Map<String, byte[]> run()
|
||||
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
// runVisitor(InterfaceTransformer.class);
|
||||
// runVisitor(OverwriteTransformer.class);
|
||||
// runSanityChecker(OverwriteSanityCheck.class);
|
||||
// runVisitor(InjectTransformer.class);
|
||||
// runVisitor(AppendTransformer.class); // append has to come before prepend or append does nothing
|
||||
// (test method: Projectile.rl$$init()V )
|
||||
// runVisitor(PrependTransformer.class);
|
||||
// runRemapper(ProtectTransformer.class);
|
||||
|
||||
// recalcMaxes();
|
||||
return classes;
|
||||
}
|
||||
|
||||
private void runRemapper(Class<? extends Remapper> clazz) throws IllegalAccessException, InstantiationException
|
||||
{
|
||||
for (Map.Entry<String, byte[]> entry : classes.entrySet())
|
||||
{
|
||||
if (entry.getKey().contains("META-INF"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Remapper inst = clazz.newInstance();
|
||||
ClassReader cr = new ClassReader(entry.getValue());
|
||||
ClassWriter cw = new ClassWriter(cr, 1);
|
||||
cr.accept(new ClassRemapper(cw, inst), 0);
|
||||
|
||||
entry.setValue(cw.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void runVisitor(Class<? extends ClassVisitor> clazz)
|
||||
throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
|
||||
{
|
||||
runVisitor(clazz, 1);
|
||||
}
|
||||
|
||||
private void runVisitor(Class<? extends ClassVisitor> clazz, int flags)
|
||||
throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
|
||||
{
|
||||
for (Map.Entry<String, byte[]> entry : classes.entrySet())
|
||||
{
|
||||
if (entry.getKey().contains("META-INF"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ClassReader cr = new ClassReader(entry.getValue());
|
||||
ClassWriter cw = new ClassWriter(cr, flags);
|
||||
byte[] patch = patches.getOrDefault(entry.getKey(), null);
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
ClassVisitor inst = clazz.getConstructor(ClassVisitor.class, byte[].class, ClassNode.class).newInstance(cw,
|
||||
patch, node);
|
||||
cr.accept(inst, 0);
|
||||
|
||||
entry.setValue(cw.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void runSanityChecker(Class<? extends SanityChecker> clazz)
|
||||
throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
|
||||
{
|
||||
runSanityChecker(clazz, 1);
|
||||
}
|
||||
|
||||
private void runSanityChecker(Class<? extends SanityChecker> clazz, int flags)
|
||||
throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
|
||||
{
|
||||
for (Map.Entry<String, byte[]> entry : patches.entrySet())
|
||||
{
|
||||
ClassReader cr = new ClassReader(entry.getValue());
|
||||
ClassWriter cw = new ClassWriter(cr, flags);
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
SanityChecker inst = clazz.getConstructor(ClassVisitor.class, ClassNode.class).newInstance(cw, node);
|
||||
cr.accept(inst, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void recalcMaxes()
|
||||
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException
|
||||
{
|
||||
runVisitor(DoNothingTransformer.class, 3);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.util.RefUtils;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.LineNumberNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
@Slf4j
|
||||
public class AppendTransformer extends ClassVisitor implements Opcodes
|
||||
{
|
||||
|
||||
private final byte[] patch;
|
||||
private String className;
|
||||
private ClassNode classNode;
|
||||
|
||||
public AppendTransformer(ClassVisitor classVisitor, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
this.patch = patch;
|
||||
this.classNode = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
|
||||
{
|
||||
if (patch == null)
|
||||
{
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
ClassReader cr = new ClassReader(patch);
|
||||
ClassNode patchNode = new ClassNode(Opcodes.ASM6);
|
||||
cr.accept(patchNode, 0);
|
||||
for (Object obj : patchNode.methods)
|
||||
{
|
||||
MethodNode patchMethod = (MethodNode) obj;
|
||||
if ((patchMethod.access == access && patchMethod.name.equals("append$" + name) &&
|
||||
patchMethod.desc.equals(descriptor)) &&
|
||||
RefUtils.checkAnnotation(patchMethod, "Append"))
|
||||
{
|
||||
MethodVisitor mv =
|
||||
new MethodVisitor(Opcodes.ASM6, super.visitMethod(access, name, descriptor, signature,
|
||||
exceptions))
|
||||
{
|
||||
};
|
||||
mv.visitCode();
|
||||
|
||||
for (Object obj2 : classNode.methods)
|
||||
{
|
||||
MethodNode classMethod = (MethodNode) obj2;
|
||||
if (classMethod.access == access && classMethod.name.equals(name) &&
|
||||
classMethod.desc.equals(descriptor))
|
||||
{
|
||||
AbstractInsnNode inode = classMethod.instructions.getLast();
|
||||
|
||||
while (inode instanceof LabelNode || inode instanceof LineNumberNode)
|
||||
{
|
||||
inode = inode.getPrevious();
|
||||
}
|
||||
|
||||
if (RefUtils.isReturn(inode.getOpcode(), true))
|
||||
{
|
||||
log.error("[Append] Can't append to {}.{}, requires typed return opcode", className, name);
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
classMethod.instructions.remove(inode);
|
||||
|
||||
classMethod.accept(new MethodReflector(mv));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
patchMethod.accept(new MethodReflector(mv));
|
||||
|
||||
mv.visitEnd();
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public class DoNothingTransformer extends ClassVisitor
|
||||
{
|
||||
public DoNothingTransformer(ClassVisitor parent, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, parent);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import net.runelite.client.util.RefUtils;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class InjectTransformer extends ClassVisitor
|
||||
{
|
||||
|
||||
private final byte[] patch;
|
||||
private ClassNode node;
|
||||
private String className;
|
||||
private boolean patching = false;
|
||||
|
||||
public InjectTransformer(ClassVisitor classVisitor, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
this.patch = patch;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
|
||||
{
|
||||
if (patch == null || name.startsWith("1protect$"))
|
||||
{
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
if (name.startsWith("prepend$") || name.startsWith("append$") ||
|
||||
(patching && name.startsWith("<")))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
ClassReader cr = new ClassReader(patch);
|
||||
ClassNode patchNode = new ClassNode(Opcodes.ASM6);
|
||||
cr.accept(patchNode, 0);
|
||||
for (Object obj : patchNode.methods)
|
||||
{
|
||||
MethodNode node = (MethodNode) obj;
|
||||
if ((node.access == access && node.name.equals(name) && node.desc.equals(descriptor)) &&
|
||||
RefUtils.checkAnnotation(node, "Inject"))
|
||||
{
|
||||
mv.visitCode();
|
||||
node.accept(new MethodReflector(mv));
|
||||
mv.visitEnd();
|
||||
}
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd()
|
||||
{
|
||||
|
||||
if (patch == null)
|
||||
{
|
||||
super.visitEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
ClassReader cr = new ClassReader(patch);
|
||||
ClassNode patchNode = new ClassNode(Opcodes.ASM6);
|
||||
cr.accept(patchNode, 0);
|
||||
patching = true;
|
||||
for (Object obj : patchNode.methods)
|
||||
{
|
||||
MethodNode node = (MethodNode) obj;
|
||||
if (RefUtils.checkAnnotation(node, "Inject"))
|
||||
{
|
||||
visitMethod(node.access, node.name, node.desc, node.signature,
|
||||
(String[]) node.exceptions.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
for (Object obj : patchNode.fields)
|
||||
{
|
||||
FieldNode node = (FieldNode) obj;
|
||||
if (RefUtils.checkAnnotation(node, "Inject"))
|
||||
{
|
||||
visitField(node.access, node.name, node.desc, node.signature, node.value);
|
||||
}
|
||||
}
|
||||
patching = false;
|
||||
super.visitEnd();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
@Slf4j
|
||||
public class InterfaceTransformer extends ClassVisitor implements Opcodes
|
||||
{
|
||||
|
||||
private final byte[] patch;
|
||||
private ClassNode node;
|
||||
private String className;
|
||||
|
||||
public InterfaceTransformer(ClassVisitor classVisitor, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
this.patch = patch;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
className = name;
|
||||
if (patch != null)
|
||||
{
|
||||
ClassReader reader = new ClassReader(patch);
|
||||
ClassNode pNode = new ClassNode();
|
||||
reader.accept(pNode, 0);
|
||||
if (pNode.interfaces != null && pNode.interfaces.size() != 0)
|
||||
{
|
||||
if (interfaces == null)
|
||||
{
|
||||
interfaces = (String[]) pNode.interfaces.toArray(new String[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList(interfaces));
|
||||
pNode.interfaces.forEach((s) -> list.add((String) s));
|
||||
interfaces = list.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import org.objectweb.asm.AnnotationVisitor;
|
||||
import org.objectweb.asm.Attribute;
|
||||
import org.objectweb.asm.Handle;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.TypePath;
|
||||
|
||||
public class MethodReflector extends MethodVisitor
|
||||
{
|
||||
|
||||
private MethodVisitor target;
|
||||
|
||||
public MethodReflector(MethodVisitor target)
|
||||
{
|
||||
super(Opcodes.ASM6);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void visitParameter(String var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitParameter(var1, var2);
|
||||
}
|
||||
super.visitParameter(var1, var2);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitAnnotationDefault()
|
||||
{
|
||||
return super.visitAnnotationDefault();
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitAnnotation(String var1, boolean var2)
|
||||
{
|
||||
return super.visitAnnotation(var1, var2);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitTypeAnnotation(int var1, TypePath var2, String var3, boolean var4)
|
||||
{
|
||||
return super.visitTypeAnnotation(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitParameterAnnotation(int var1, String var2, boolean var3)
|
||||
{
|
||||
return super.visitParameterAnnotation(var1, var2, var3);
|
||||
}
|
||||
|
||||
public void visitAttribute(Attribute var1)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitAttribute(var1);
|
||||
}
|
||||
super.visitAttribute(var1);
|
||||
}
|
||||
|
||||
public void visitFrame(int var1, int var2, Object[] var3, int var4, Object[] var5)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitFrame(var1, var2, var3, var4, var5);
|
||||
}
|
||||
super.visitFrame(var1, var2, var3, var4, var5);
|
||||
}
|
||||
|
||||
public void visitInsn(int var1)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitInsn(var1);
|
||||
}
|
||||
super.visitInsn(var1);
|
||||
}
|
||||
|
||||
public void visitIntInsn(int var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitIntInsn(var1, var2);
|
||||
}
|
||||
super.visitIntInsn(var1, var2);
|
||||
}
|
||||
|
||||
public void visitVarInsn(int var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitVarInsn(var1, var2);
|
||||
}
|
||||
super.visitVarInsn(var1, var2);
|
||||
}
|
||||
|
||||
public void visitTypeInsn(int var1, String var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitTypeInsn(var1, var2);
|
||||
}
|
||||
super.visitTypeInsn(var1, var2);
|
||||
}
|
||||
|
||||
public void visitFieldInsn(int var1, String var2, String var3, String var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitFieldInsn(var1, var2, var3, var4);
|
||||
}
|
||||
super.visitFieldInsn(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public void visitMethodInsn(int var1, String var2, String var3, String var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitMethodInsn(var1, var2, var3, var4);
|
||||
}
|
||||
super.visitMethodInsn(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public void visitMethodInsn(int var1, String var2, String var3, String var4, boolean var5)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitMethodInsn(var1, var2, var3, var4, var5);
|
||||
}
|
||||
super.visitMethodInsn(var1, var2, var3, var4, var5);
|
||||
}
|
||||
|
||||
public void visitInvokeDynamicInsn(String var1, String var2, Handle var3, Object... var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitInvokeDynamicInsn(var1, var2, var3, var4);
|
||||
}
|
||||
super.visitInvokeDynamicInsn(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public void visitJumpInsn(int var1, Label var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitJumpInsn(var1, var2);
|
||||
}
|
||||
super.visitJumpInsn(var1, var2);
|
||||
}
|
||||
|
||||
public void visitLabel(Label var1)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLabel(var1);
|
||||
}
|
||||
super.visitLabel(var1);
|
||||
}
|
||||
|
||||
public void visitLdcInsn(Object var1)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLdcInsn(var1);
|
||||
}
|
||||
super.visitLdcInsn(var1);
|
||||
}
|
||||
|
||||
public void visitIincInsn(int var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitIincInsn(var1, var2);
|
||||
}
|
||||
super.visitIincInsn(var1, var2);
|
||||
}
|
||||
|
||||
public void visitTableSwitchInsn(int var1, int var2, Label var3, Label... var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitTableSwitchInsn(var1, var2, var3, var4);
|
||||
}
|
||||
super.visitTableSwitchInsn(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public void visitLookupSwitchInsn(Label var1, int[] var2, Label[] var3)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLookupSwitchInsn(var1, var2, var3);
|
||||
}
|
||||
super.visitLookupSwitchInsn(var1, var2, var3);
|
||||
}
|
||||
|
||||
public void visitMultiANewArrayInsn(String var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitMultiANewArrayInsn(var1, var2);
|
||||
}
|
||||
super.visitMultiANewArrayInsn(var1, var2);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitInsnAnnotation(int var1, TypePath var2, String var3, boolean var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitInsnAnnotation(var1, var2, var3, var4);
|
||||
}
|
||||
return super.visitInsnAnnotation(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public void visitTryCatchBlock(Label var1, Label var2, Label var3, String var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitTryCatchBlock(var1, var2, var3, var4);
|
||||
}
|
||||
super.visitTryCatchBlock(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitTryCatchAnnotation(int var1, TypePath var2, String var3, boolean var4)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitTryCatchAnnotation(var1, var2, var3, var4);
|
||||
}
|
||||
return super.visitTryCatchAnnotation(var1, var2, var3, var4);
|
||||
}
|
||||
|
||||
public void visitLocalVariable(String var1, String var2, String var3, Label var4, Label var5, int var6)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLocalVariable(var1, var2, var3, var4, var5, var6);
|
||||
}
|
||||
super.visitLocalVariable(var1, var2, var3, var4, var5, var6);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitLocalVariableAnnotation(int var1, TypePath var2, Label[] var3, Label[] var4, int[] var5, String var6, boolean var7)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLocalVariableAnnotation(var1, var2, var3, var4, var5, var6, var7);
|
||||
}
|
||||
return super.visitLocalVariableAnnotation(var1, var2, var3, var4, var5, var6, var7);
|
||||
}
|
||||
|
||||
public void visitLineNumber(int var1, Label var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitLineNumber(var1, var2);
|
||||
}
|
||||
super.visitLineNumber(var1, var2);
|
||||
}
|
||||
|
||||
public void visitMaxs(int var1, int var2)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.visitMaxs(var1, var2);
|
||||
}
|
||||
super.visitMaxs(var1, var2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.util.RefUtils;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
@Slf4j
|
||||
public class OverwriteSanityCheck extends SanityChecker implements Opcodes
|
||||
{
|
||||
|
||||
private String className;
|
||||
private ClassNode patchNode;
|
||||
public static final ArrayList<String> methodsUsed = new ArrayList<>();
|
||||
|
||||
public OverwriteSanityCheck(ClassVisitor classVisitor, ClassNode node)
|
||||
{
|
||||
super(ASM6, classVisitor);
|
||||
this.className = node.name;
|
||||
this.patchNode = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
|
||||
{
|
||||
String check = String.format("%s %s %s %s", className, name,
|
||||
descriptor, access);
|
||||
|
||||
MethodNode methodNode = null;
|
||||
for (Object obj2 : patchNode.methods)
|
||||
{
|
||||
MethodNode classMethod = (MethodNode) obj2;
|
||||
if (classMethod.access == access && classMethod.name.equals(name) &&
|
||||
classMethod.desc.equals(descriptor))
|
||||
{
|
||||
methodNode = classMethod;
|
||||
}
|
||||
}
|
||||
|
||||
if (methodNode == null)
|
||||
{
|
||||
log.error("[OverwriteSanity] Failed to find original patch method for {}", check);
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
if (!RefUtils.checkAnnotation(methodNode, "Overwrite"))
|
||||
{
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
if (!methodsUsed.contains(check))
|
||||
{
|
||||
throw new RuntimeException("[OverwriteSanity] Overwrite target not found: " + check);
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.util.RefUtils;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
@Slf4j
|
||||
public class OverwriteTransformer extends ClassVisitor
|
||||
{
|
||||
|
||||
private final byte[] patch;
|
||||
private ClassNode node;
|
||||
private String className;
|
||||
|
||||
public OverwriteTransformer(ClassVisitor classVisitor, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
this.patch = patch;
|
||||
this.node = node;
|
||||
this.className = node.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
|
||||
{
|
||||
if (patch == null || name.startsWith("1protect$"))
|
||||
{
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
if (name.startsWith("prepend$") || name.startsWith("append$"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassReader cr = new ClassReader(patch);
|
||||
ClassNode patchNode = new ClassNode(Opcodes.ASM6);
|
||||
cr.accept(patchNode, 0);
|
||||
|
||||
for (Object obj : patchNode.methods)
|
||||
{
|
||||
MethodNode patchMethod = (MethodNode) obj;
|
||||
|
||||
if (patchMethod.access == access && patchMethod.name.equals(name) && patchMethod.desc.equals(descriptor))
|
||||
{
|
||||
if (RefUtils.checkAnnotation(patchMethod, "Overwrite"))
|
||||
{
|
||||
MethodVisitor mv =
|
||||
new MethodVisitor(Opcodes.ASM6, super.visitMethod(access, name, descriptor, signature,
|
||||
exceptions))
|
||||
{
|
||||
};
|
||||
mv.visitCode();
|
||||
patchMethod.accept(new MethodReflector(mv));
|
||||
mv.visitEnd();
|
||||
String s = String.format("%s %s %s %s", className, patchMethod.name,
|
||||
patchMethod.desc, patchMethod.access);
|
||||
OverwriteSanityCheck.methodsUsed.add(s);
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import net.runelite.client.util.RefUtils;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class PrependTransformer extends ClassVisitor
|
||||
{
|
||||
|
||||
private final byte[] patch;
|
||||
private String className;
|
||||
private ClassNode classNode;
|
||||
|
||||
public PrependTransformer(ClassVisitor classVisitor, byte[] patch, ClassNode node)
|
||||
{
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
this.patch = patch;
|
||||
this.classNode = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
|
||||
{
|
||||
if (patch == null)
|
||||
{
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
ClassReader cr = new ClassReader(patch);
|
||||
ClassNode patchNode = new ClassNode(Opcodes.ASM6);
|
||||
cr.accept(patchNode, 0);
|
||||
for (Object obj : patchNode.methods)
|
||||
{
|
||||
MethodNode patchMethod = (MethodNode) obj;
|
||||
if ((patchMethod.access == access && patchMethod.name.equals("prepend$" + name) &&
|
||||
patchMethod.desc.equals(descriptor)) &&
|
||||
RefUtils.checkAnnotation(patchMethod, "Prepend"))
|
||||
{
|
||||
MethodVisitor mv =
|
||||
new MethodVisitor(Opcodes.ASM6, super.visitMethod(access, name, descriptor, signature,
|
||||
exceptions))
|
||||
{
|
||||
};
|
||||
mv.visitCode();
|
||||
|
||||
AbstractInsnNode node = patchMethod.instructions.getLast();
|
||||
while (!(node instanceof InsnNode))
|
||||
{
|
||||
node = node.getPrevious();
|
||||
}
|
||||
|
||||
if (RefUtils.isReturn(node.getOpcode()))
|
||||
{
|
||||
patchMethod.instructions.remove(node);
|
||||
}
|
||||
|
||||
patchMethod.accept(new MethodReflector(mv));
|
||||
|
||||
for (Object obj2 : classNode.methods)
|
||||
{
|
||||
MethodNode classMethod = (MethodNode) obj2;
|
||||
if (classMethod.access == access && classMethod.name.equals(name) &&
|
||||
classMethod.desc.equals(descriptor))
|
||||
{
|
||||
classMethod.accept(new MethodReflector(mv));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mv.visitEnd();
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd()
|
||||
{
|
||||
if (patch == null)
|
||||
{
|
||||
super.visitEnd();
|
||||
return;
|
||||
}
|
||||
super.visitEnd();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class ProtectTransformer extends Remapper
|
||||
{
|
||||
|
||||
public String mapFieldName(String owner, String name, String descriptor)
|
||||
{
|
||||
if (name.startsWith("1protect$"))
|
||||
{
|
||||
name = name.substring("1protect$".length());
|
||||
}
|
||||
return super.mapFieldName(owner, name, descriptor);
|
||||
}
|
||||
|
||||
public String mapMethodName(String owner, String name, String descriptor)
|
||||
{
|
||||
if (name.startsWith("1protect$"))
|
||||
{
|
||||
name = name.substring("1protect$".length());
|
||||
}
|
||||
return super.mapMethodName(owner, name, descriptor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.rs.mixins.transformers;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public abstract class SanityChecker extends ClassVisitor implements Opcodes
|
||||
{
|
||||
protected SanityChecker(int i, ClassVisitor classVisitor)
|
||||
{
|
||||
super(i, classVisitor);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user