Example usage for org.objectweb.asm Opcodes DUP

List of usage examples for org.objectweb.asm Opcodes DUP

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes DUP.

Prototype

int DUP

To view the source code for org.objectweb.asm Opcodes DUP.

Click Source Link

Usage

From source file:tk.wurst_client.hooks.injector.MethodHookInjector.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();
    if (methodData.hasHookAt(HookPosition.METHOD_START)) {
        HookData hookData = methodData.getHook(HookPosition.METHOD_START);
        super.visitLdcInsn(className + "." + methodName + "|start");

        if (hookData.collectsParams()) {
            super.visitIntInsn(Opcodes.BIPUSH, paramCount);
            super.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
            for (byte i = 0; i < paramCount; i++) {
                super.visitInsn(Opcodes.DUP);
                super.visitIntInsn(Opcodes.BIPUSH, i);
                super.visitVarInsn(Opcodes.ALOAD, i);
                super.visitInsn(Opcodes.AASTORE);
            }/*w  ww .  j a v a  2 s  .  c o m*/
        }

        // TODO: Custom class path
        super.visitMethodInsn(Opcodes.INVOKESTATIC, "tk/wurst_client/hooks/HookManager", "hook",
                "(Ljava/lang/String;" + (hookData.collectsParams() ? "[Ljava/lang/Object;" : "") + ")V", false);
    }
}

From source file:tk.wurst_client.hooks.injector.MethodHookInjector.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    if (methodData.hasHookAt(HookPosition.METHOD_END) && opcode >= 172 && opcode <= 177) {
        HookData hookData = methodData.getHook(HookPosition.METHOD_END);
        super.visitLdcInsn(className + "." + methodName + "|end");

        if (hookData.collectsParams()) {

            super.visitIntInsn(Opcodes.BIPUSH, paramCount);
            super.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
            for (byte i = 0; i < paramCount; i++) {
                super.visitInsn(Opcodes.DUP);
                super.visitIntInsn(Opcodes.BIPUSH, i);
                super.visitVarInsn(Opcodes.ALOAD, i);
                super.visitInsn(Opcodes.AASTORE);
            }//w w  w  . j av  a2  s.  com
        }

        // TODO: Custom class path
        super.visitMethodInsn(Opcodes.INVOKESTATIC, "tk/wurst_client/hooks/HookManager", "hook",
                "(Ljava/lang/String;" + (hookData.collectsParams() ? "[Ljava/lang/Object;" : "") + ")V", false);
    }
    super.visitInsn(opcode);
}

From source file:uk.ac.cam.cl.dtg.teaching.programmingtest.java.bytecode.InstructionCounterMethodAdapter.java

License:Open Source License

private void increment(int type) {
    switch (type) {
    case INCREMENT_ALLOCATION:
        count += 2;/*  w  w  w .j a v a  2s. co  m*/
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, INSTRUCTION_COUNTER_CLASSNAME, "incrementAllocations",
                "(Ljava/lang/Object;)V", false);
        break;
    default: // case INCREMENT_INSTRUCTION:
        count++;
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, INSTRUCTION_COUNTER_CLASSNAME, "incrementInstructions", "()V",
                false);
    }
}

From source file:vazkii.quark.base.asm.ClassTransformer.java

License:Creative Commons License

private static byte[] transformWorldServer(byte[] basicClass) {
    log("Transforming WorldServer");
    MethodSignature sig = new MethodSignature("areAllPlayersAsleep", "func_73056_e", "g", "()Z");

    return transform(basicClass, Pair.of(sig, combine((AbstractInsnNode node) -> { // Filter
        return true;
    }, (MethodNode method, AbstractInsnNode node) -> { // Action
        InsnList newInstructions = new InsnList();

        newInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        newInstructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ASM_HOOKS, "isEveryoneAsleep",
                "(Lnet/minecraft/world/World;)I"));
        newInstructions.add(new InsnNode(Opcodes.DUP));
        LabelNode label = new LabelNode();
        newInstructions.add(new JumpInsnNode(Opcodes.IFEQ, label));
        newInstructions.add(new InsnNode(Opcodes.ICONST_1));
        newInstructions.add(new InsnNode(Opcodes.ISUB));
        newInstructions.add(new InsnNode(Opcodes.IRETURN));
        newInstructions.add(label);/*w  ww.  jav  a 2  s .co m*/

        method.instructions.insertBefore(node, newInstructions);
        return true;
    })));
}