Search in sources :

Example 6 with VarInsnNode

use of org.objectweb.asm.tree.VarInsnNode in project pinpoint by naver.

the class ASMClassNodeAdapter method addGetterMethod.

public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
    if (methodName == null || fieldNode == null) {
        throw new IllegalArgumentException("method name or fieldNode annotation must not be null.");
    }
    // no argument is ().
    final String desc = "()" + fieldNode.getDesc();
    final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
    if (methodNode.instructions == null) {
        methodNode.instructions = new InsnList();
    }
    final InsnList instructions = methodNode.instructions;
    // load this.
    instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    // get fieldNode.
    instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
    // return of type.
    final Type type = Type.getType(fieldNode.getDesc());
    instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN)));
    if (this.classNode.methods == null) {
        this.classNode.methods = new ArrayList<MethodNode>();
    }
    this.classNode.methods.add(methodNode);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodNode(org.objectweb.asm.tree.MethodNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 7 with VarInsnNode

use of org.objectweb.asm.tree.VarInsnNode in project Bookshelf by Darkhax-Minecraft.

the class TransformerEnchantmentHelper method transform.

public static byte[] transform(String name, String transformedName, byte[] classBytes) {
    final ClassNode clazz = ASMUtils.createClassFromByteArray(classBytes);
    final MethodNode method = METHOD_GET_ENCH_LEVEL.getMethodNode(clazz);
    final InsnList n1 = new InsnList();
    final LabelNode start = new LabelNode();
    n1.add(start);
    n1.add(new TypeInsnNode(Opcodes.NEW, "net/darkhax/bookshelf/events/EnchantmentModifierEvent"));
    n1.add(new InsnNode(Opcodes.DUP));
    n1.add(new VarInsnNode(Opcodes.ALOAD, 0));
    n1.add(new VarInsnNode(Opcodes.ALOAD, 1));
    n1.add(METHOD_INIT_EVENT.getMethodInsn(Opcodes.INVOKESPECIAL, false));
    n1.add(new VarInsnNode(Opcodes.ASTORE, 2));
    final LabelNode l1 = new LabelNode();
    n1.add(l1);
    n1.add(FIELD_EVENT_BUS.getFieldNode(Opcodes.GETSTATIC));
    n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
    n1.add(METHOD_POST.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
    n1.add(new InsnNode(Opcodes.POP));
    final LabelNode l2 = new LabelNode();
    n1.add(l2);
    n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
    n1.add(METHOD_CANCELED.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
    final LabelNode vanillaLogic = new LabelNode();
    n1.add(new JumpInsnNode(Opcodes.IFEQ, vanillaLogic));
    final LabelNode l4 = new LabelNode();
    n1.add(l4);
    n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
    n1.add(METHOD_GET_LEVELS.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
    n1.add(new InsnNode(Opcodes.IRETURN));
    n1.add(vanillaLogic);
    method.instructions.insertBefore(method.instructions.getFirst(), n1);
    return ASMUtils.createByteArrayFromClass(clazz, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Aggregations

VarInsnNode (org.objectweb.asm.tree.VarInsnNode)7 Type (org.objectweb.asm.Type)4 InsnNode (org.objectweb.asm.tree.InsnNode)4 MethodNode (org.objectweb.asm.tree.MethodNode)4 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)3 InsnList (org.objectweb.asm.tree.InsnList)3 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)2 InterceptorType (com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType)1 Event (net.minecraftforge.fml.common.eventhandler.Event)1 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 FieldNode (org.objectweb.asm.tree.FieldNode)1 FrameNode (org.objectweb.asm.tree.FrameNode)1 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)1