Search in sources :

Example 16 with TypeInsnNode

use of org.objectweb.asm.tree.TypeInsnNode in project robolectric by robolectric.

the class ClassInstrumentor method rewriteMethodBody.

/**
 * Filters methods that might need special treatment because of various reasons
 */
private void rewriteMethodBody(MutableClass mutableClass, MethodNode callingMethod) {
    ListIterator<AbstractInsnNode> instructions = callingMethod.instructions.iterator();
    while (instructions.hasNext()) {
        AbstractInsnNode node = instructions.next();
        switch(node.getOpcode()) {
            case Opcodes.NEW:
                TypeInsnNode newInsnNode = (TypeInsnNode) node;
                newInsnNode.desc = mutableClass.config.mappedTypeName(newInsnNode.desc);
                break;
            case Opcodes.GETFIELD:
            /* falls through */
            case Opcodes.PUTFIELD:
            /* falls through */
            case Opcodes.GETSTATIC:
            /* falls through */
            case Opcodes.PUTSTATIC:
                FieldInsnNode fieldInsnNode = (FieldInsnNode) node;
                // todo test
                fieldInsnNode.desc = mutableClass.config.mappedTypeName(fieldInsnNode.desc);
                break;
            case Opcodes.INVOKESTATIC:
            /* falls through */
            case Opcodes.INVOKEINTERFACE:
            /* falls through */
            case Opcodes.INVOKESPECIAL:
            /* falls through */
            case Opcodes.INVOKEVIRTUAL:
                MethodInsnNode targetMethod = (MethodInsnNode) node;
                targetMethod.desc = mutableClass.config.remapParams(targetMethod.desc);
                if (isGregorianCalendarBooleanConstructor(targetMethod)) {
                    replaceGregorianCalendarBooleanConstructor(instructions, targetMethod);
                } else if (mutableClass.config.shouldIntercept(targetMethod)) {
                    interceptInvokeVirtualMethod(mutableClass, instructions, targetMethod);
                }
                break;
            case Opcodes.INVOKEDYNAMIC:
                /* no unusual behavior */
                break;
            default:
                break;
        }
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 17 with TypeInsnNode

use of org.objectweb.asm.tree.TypeInsnNode in project bytecode-viewer by Konloch.

the class RegexInsnFinder method getInsString.

private static String getInsString(AbstractInsnNode ain) {
    String insnString = "";
    switch(ain.getType()) {
        case AbstractInsnNode.INT_INSN:
            final IntInsnNode iin = (IntInsnNode) ain;
            insnString += "{" + iin.operand + "}";
            break;
        case AbstractInsnNode.LDC_INSN:
            final LdcInsnNode lin = (LdcInsnNode) ain;
            insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}";
            break;
        case AbstractInsnNode.VAR_INSN:
            final VarInsnNode vin = (VarInsnNode) ain;
            insnString += "_" + vin.var;
            break;
        case AbstractInsnNode.IINC_INSN:
            final IincInsnNode iiin = (IincInsnNode) ain;
            insnString += "{" + iiin.var + "," + iiin.incr + "}";
            break;
        case AbstractInsnNode.FIELD_INSN:
            final FieldInsnNode fin = (FieldInsnNode) ain;
            insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}";
            break;
        case AbstractInsnNode.METHOD_INSN:
            final MethodInsnNode min = (MethodInsnNode) ain;
            insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}";
            break;
        case AbstractInsnNode.TYPE_INSN:
            final TypeInsnNode tin = (TypeInsnNode) ain;
            insnString += "{" + tin.desc + "}";
            break;
        case AbstractInsnNode.MULTIANEWARRAY_INSN:
            final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain;
            insnString += "{" + manain.dims + "," + manain.desc + "}";
            break;
    }
    return insnString;
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 18 with TypeInsnNode

use of org.objectweb.asm.tree.TypeInsnNode in project jphp by jphp-compiler.

the class ClosureValueCompiler method write.

@Override
public void write(ClosureStmtToken closure, boolean returnValue) {
    if (returnValue) {
        ClosureEntity entity = compiler.getModule().findClosure(closure.getId());
        boolean thisExists = closure.getFunction().isThisExists();
        if (entity.isStatic()) {
            thisExists = false;
        }
        boolean staticExists = closure.getFunction().isStaticExists();
        if (closure.getFunction().getUses().isEmpty() && !thisExists && !staticExists && closure.getFunction().getStaticLocal().isEmpty()) {
            expr.writePushEnv();
            expr.writePushConstString(compiler.getModule().getInternalName());
            expr.writePushConstInt((int) entity.getId());
            writeContext();
            expr.writeSysDynamicCall(Environment.class, "__getSingletonClosure", Memory.class, String.class, Integer.TYPE, String.class);
        } else {
            add(new TypeInsnNode(NEW, entity.getInternalName()));
            expr.stackPush(Memory.Type.REFERENCE);
            expr.writePushDup();
            expr.writePushEnv();
            expr.writePushEnv();
            expr.writePushConstString(compiler.getModule().getInternalName());
            expr.writePushConstInt((int) entity.getId());
            expr.writeSysDynamicCall(Environment.class, "__getClosure", ClassEntity.class, String.class, Integer.TYPE);
            if (thisExists) {
                expr.writePushThis();
            } else {
                expr.writePushNull();
            }
            writeContext();
            writePushUses(closure.getFunction().getUses());
            add(new MethodInsnNode(INVOKESPECIAL, entity.getInternalName(), Constants.INIT_METHOD, Type.getMethodDescriptor(Type.getType(void.class), Type.getType(Environment.class), Type.getType(ClassEntity.class), Type.getType(Memory.class), Type.getType(String.class), Type.getType(Memory[].class)), false));
            expr.stackPop();
            expr.stackPop();
            expr.stackPop();
            expr.stackPop();
            expr.stackPop();
            expr.stackPop();
            expr.writeSysStaticCall(ObjectMemory.class, "valueOf", Memory.class, IObject.class);
        }
        expr.setStackPeekAsImmutable();
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) Environment(php.runtime.env.Environment) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode)

Example 19 with TypeInsnNode

use of org.objectweb.asm.tree.TypeInsnNode 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)

Example 20 with TypeInsnNode

use of org.objectweb.asm.tree.TypeInsnNode in project drill by axbaretto.

the class ReplacingInterpreter method newOperation.

@Override
public BasicValue newOperation(final AbstractInsnNode insn) throws AnalyzerException {
    if (insn.getOpcode() == Opcodes.NEW) {
        final TypeInsnNode t = (TypeInsnNode) insn;
        // if this is for a holder class, we'll replace it
        final ValueHolderIden iden = HOLDERS.get(t.desc);
        if (iden != null) {
            return ReplacingBasicValue.create(Type.getObjectType(t.desc), iden, index++, valueList);
        }
    }
    return super.newOperation(insn);
}
Also used : TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode)

Aggregations

TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)29 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)18 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)14 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)13 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)12 InsnNode (org.objectweb.asm.tree.InsnNode)11 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)9 IntInsnNode (org.objectweb.asm.tree.IntInsnNode)8 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)8 MethodNode (org.objectweb.asm.tree.MethodNode)8 Type (org.objectweb.asm.Type)7 InsnList (org.objectweb.asm.tree.InsnList)7 LabelNode (org.objectweb.asm.tree.LabelNode)7 ClassNode (org.objectweb.asm.tree.ClassNode)5 FieldNode (org.objectweb.asm.tree.FieldNode)4 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)3 JsonObject (com.google.gson.JsonObject)2 ClassWriter (org.objectweb.asm.ClassWriter)2 FrameNode (org.objectweb.asm.tree.FrameNode)2 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)2