Search in sources :

Example 16 with FrameNode

use of org.objectweb.asm.tree.FrameNode in project phosphor by gmu-swe.

the class TaintPassingMV method retrieveTaintedArrayWithoutTags.

public void retrieveTaintedArrayWithoutTags(String type) {
    // A
    Label isNull = new Label();
    Label isDone = new Label();
    FrameNode fn = getCurrentFrameNode();
    super.visitInsn(DUP);
    if (!isIgnoreAllInstrumenting)
        super.visitInsn(TaintUtils.IGNORE_EVERYTHING);
    super.visitJumpInsn(IFNULL, isNull);
    if (!isIgnoreAllInstrumenting)
        super.visitInsn(TaintUtils.IGNORE_EVERYTHING);
    // System.out.println("unbox: " + onStack + " type passed is " + type);
    Class boxType = MultiDTaintedArray.getClassForComponentType(Type.getType(type).getElementType().getSort());
    super.visitTypeInsn(CHECKCAST, Type.getInternalName(boxType));
    Type arrayDesc = Type.getType(type);
    // System.out.println("Get tainted array from " + arrayDesc);
    super.visitFieldInsn(GETFIELD, Type.getInternalName(boxType), "val", type);
    FrameNode fn2 = getCurrentFrameNode();
    super.visitJumpInsn(GOTO, isDone);
    super.visitLabel(isNull);
    acceptFn(fn);
    super.visitTypeInsn(CHECKCAST, type);
    super.visitLabel(isDone);
    acceptFn(fn2);
}
Also used : FrameNode(org.objectweb.asm.tree.FrameNode) Type(org.objectweb.asm.Type) Label(org.objectweb.asm.Label) OffsetPreservingLabel(edu.columbia.cs.psl.phosphor.instrumenter.asm.OffsetPreservingLabel)

Example 17 with FrameNode

use of org.objectweb.asm.tree.FrameNode in project phosphor by gmu-swe.

the class TaintPassingMV method visitMethodInsn.

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itfc) {
    if (isIgnoreAllInstrumenting || isRawInsns) {
        super.visitMethodInsn(opcode, owner, name, desc, itfc);
        return;
    }
    // Stupid workaround for eclipse benchmark
    if (name.equals("getProperty") && className.equals("org/eclipse/jdt/core/tests/util/Util")) {
        owner = Type.getInternalName(ReflectionMasker.class);
        System.out.println("Fixing getproperty");
        name = "getPropertyHideBootClasspath";
    }
    if (opcode == INVOKESTATIC && isBoxUnboxMethodToWrap(owner, name, desc)) {
        if (name.equals("valueOf") && desc.startsWith("(Ljava/lang/String;"))
            switch(owner) {
                case BYTE_NAME:
                    name = "valueOfB";
                    break;
                case BOOLEAN_NAME:
                    name = "valueOfZ";
                    break;
                case CHARACTER_NAME:
                    name = "valueOfC";
                    break;
                case SHORT_NAME:
                    name = "valueOfS";
                    break;
                default:
                    throw new UnsupportedOperationException(owner);
            }
        owner = "edu/columbia/cs/psl/phosphor/runtime/RuntimeBoxUnboxPropogator";
    }
    boolean isPreAllocedReturnType = TaintUtils.isPreAllocReturnType(desc);
    if (Instrumenter.isClassWithHashmapTag(owner) && name.equals("valueOf")) {
        Type[] args = Type.getArgumentTypes(desc);
        if (args[0].getSort() != Type.OBJECT) {
            if (!Configuration.MULTI_TAINTING) {
                owner = Type.getInternalName(BoxedPrimitiveStoreWithIntTags.class);
                desc = "(I" + desc.substring(1);
            } else {
                owner = Type.getInternalName(BoxedPrimitiveStoreWithObjTags.class);
                desc = "(" + Configuration.TAINT_TAG_DESC + desc.substring(1);
            }
            super.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name, desc, false);
            return;
        }
    } else if (Instrumenter.isClassWithHashmapTag(owner) && (name.equals("byteValue") || name.equals("booleanValue") || name.equals("charValue") || name.equals("shortValue"))) {
        Type returnType = Type.getReturnType(desc);
        Type boxedReturn = TaintUtils.getContainerReturnType(returnType);
        desc = "(L" + owner + ";)" + boxedReturn.getDescriptor();
        if (!Configuration.MULTI_TAINTING)
            owner = Type.getInternalName(BoxedPrimitiveStoreWithIntTags.class);
        else
            owner = Type.getInternalName(BoxedPrimitiveStoreWithObjTags.class);
        super.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name, desc, false);
        if (nextLoadisTracked) {
            super.visitInsn(DUP);
            getTaintFieldOfBoxedType(boxedReturn.getInternalName());
            super.visitInsn(SWAP);
        }
        super.visitFieldInsn(GETFIELD, boxedReturn.getInternalName(), "val", returnType.getDescriptor());
        if (nextLoadisTracked) {
            analyzer.setTopOfStackTagged();
            nextLoadisTracked = false;
        }
        return;
    }
    Type ownerType = Type.getObjectType(owner);
    if (opcode == INVOKEVIRTUAL && ownerType.getSort() == Type.ARRAY && ownerType.getElementType().getSort() != Type.OBJECT && ownerType.getDimensions() > 1) {
        // System.out.println("got to change the owner on primitive array call from " +owner+" to " + MultiDTaintedArray.getTypeForType(ownerType));
        owner = MultiDTaintedArray.getTypeForType(ownerType).getInternalName();
    }
    // Type ownerType = Type.getType(owner + ";");
    boolean isCallToPrimitiveArrayClone = opcode == INVOKEVIRTUAL && desc.equals("()Ljava/lang/Object;") && name.equals("clone") && getTopOfStackType().getSort() == Type.ARRAY && getTopOfStackType().getElementType().getSort() != Type.OBJECT;
    // When you call primitive array clone, we should first clone the taint array, then register that taint array to the cloned object after calling clone
    Type primitiveArrayType = null;
    if (isCallToPrimitiveArrayClone) {
        // System.out.println("Call to primitive array clone: " + analyzer.stack + " " + owner);
        registerTaintedArray();
        primitiveArrayType = getTopOfStackType();
        Configuration.taintTagFactory.methodOp(opcode, primitiveArrayType.getInternalName(), "clone", "()Ljava/lang/Object", false, mv, lvs, this);
        super.visitMethodInsn(opcode, primitiveArrayType.getInternalName(), "clone", "()Ljava/lang/Object;", false);
        return;
    }
    if ((owner.equals("java/lang/System") || owner.equals("java/lang/VMSystem") || owner.equals("java/lang/VMMemoryManager")) && name.equals("arraycopy") && !desc.equals("(Ljava/lang/Object;ILjava/lang/Object;IILjava/lang/DCompMarker;)V")) {
        if (Instrumenter.IS_KAFFE_INST)
            name = "arraycopyVM";
        else if (Instrumenter.IS_HARMONY_INST)
            name = "arraycopyHarmony";
        owner = Type.getInternalName(TaintUtils.class);
        // We have several scenarios here. src/dest may or may not have shadow arrays on the stack
        boolean destIsPrimitve = false;
        Type destType = getStackTypeAtOffset(4);
        // System.out.println(analyzer.stack);
        destIsPrimitve = !stackElIsNull(4) && destType.getSort() != Type.OBJECT && destType.getElementType().getSort() != Type.OBJECT;
        int srcOffset = 7;
        if (destIsPrimitve)
            srcOffset++;
        // System.out.println("Sysarracopy with " + analyzer.stack);
        Type srcType = getStackTypeAtOffset(srcOffset);
        boolean srcIsPrimitive = srcType.getSort() != Type.OBJECT && srcType.getElementType().getSort() != Type.OBJECT && !stackElIsNull(srcOffset);
        if (!Configuration.MULTI_TAINTING) {
            if (srcIsPrimitive) {
                if (destIsPrimitve) {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;IILjava/lang/Object;Ljava/lang/Object;IIII)V";
                    if (Configuration.IMPLICIT_TRACKING)
                        name = "arraycopyControlTrack";
                } else {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;IILjava/lang/Object;IIII)V";
                }
            } else {
                if (destIsPrimitve) {
                    desc = "(Ljava/lang/Object;IILjava/lang/Object;Ljava/lang/Object;IIII)V";
                } else {
                    desc = "(Ljava/lang/Object;IILjava/lang/Object;IIII)V";
                }
            }
        } else {
            if (srcIsPrimitive) {
                if (destIsPrimitve) {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;I)V";
                    if (Configuration.IMPLICIT_TRACKING)
                        name = "arraycopyControlTrack";
                } else {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;I)V";
                }
            } else {
                if (destIsPrimitve) {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;I)V";
                } else {
                    desc = "(Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;I)V";
                }
            }
        }
    }
    if (owner.startsWith("edu/columbia/cs/psl/phosphor") && !name.equals("printConstraints") && !name.equals("hasNoDependencies") && !desc.equals("(I)V") && !owner.endsWith("Tainter") && !name.equals("getPHOSPHOR_TAG") && !name.equals("setPHOSPHOR_TAG") && !owner.equals("edu/columbia/cs/psl/phosphor/runtime/RuntimeBoxUnboxPropogator")) {
        Configuration.taintTagFactory.methodOp(opcode, owner, name, desc, itfc, mv, lvs, this);
        super.visitMethodInsn(opcode, owner, name, desc, itfc);
        return;
    }
    // to reduce how much we need to wrap, we will only rename methods that actually have a different descriptor
    boolean hasNewName = !TaintUtils.remapMethodDesc(desc).equals(desc);
    if (isCallToPrimitiveArrayClone) {
        hasNewName = false;
    }
    boolean isIgnoredForTaints = Configuration.WITH_SELECTIVE_INST && Instrumenter.isIgnoredMethodFromOurAnalysis(owner, name, desc);
    if ((Instrumenter.isIgnoredClass(owner) || isIgnoredForTaints || Instrumenter.isIgnoredMethod(owner, name, desc)) && !isInternalTaintingMethod(owner)) {
        Type[] args = Type.getArgumentTypes(desc);
        if (TaintUtils.DEBUG_CALLS) {
            System.out.println("Calling non-inst: " + owner + "." + name + desc + " stack " + analyzer.stack);
        }
        int argsSize = 0;
        for (int i = 0; i < args.length; i++) {
            argsSize += args[args.length - i - 1].getSize();
            if (TaintUtils.DEBUG_CALLS)
                System.out.println(i + ", " + analyzer.stack.get(analyzer.stack.size() - argsSize) + " " + args[args.length - i - 1]);
            if (args[args.length - i - 1].getSort() == Type.ARRAY && args[args.length - i - 1].getElementType().getSort() != Type.OBJECT && args[args.length - i - 1].getDimensions() > 1) {
                if (!isIgnoredForTaints)
                    ensureUnBoxedAt(i, args[args.length - i - 1]);
            // unboxTaintArrayAt(i+1, args[args.length - i - 1].getDescriptor());
            } else if (isPrimitiveType(args[args.length - i - 1]) || (args[args.length - i - 1].equals(Type.getType(Object.class)) && isPrimitiveStackType(analyzer.stack.get(analyzer.stack.size() - argsSize)))) {
                // Wooahhh let's do nothing here if it's a null on the stack
                if (isPrimitiveType(args[args.length - i - 1]) && analyzer.stack.get(analyzer.stack.size() - argsSize) == Opcodes.NULL) {
                } else
                    popAt(i + 1);
            }
        }
        // System.out.println("After modifying, Calling non-inst: " + owner + "." + name + desc + " stack " + analyzer.stack);
        boolean isCalledOnAPrimitiveArrayType = false;
        if (opcode == INVOKEVIRTUAL) {
            Type callee = getTypeForStackType(analyzer.stack.get(analyzer.stack.size() - argsSize - 1));
            if (TaintUtils.DEBUG_CALLS)
                System.out.println("CALLEE IS " + callee);
            if (callee.getSort() == Type.ARRAY && callee.getElementType().getSort() != Type.OBJECT)
                isCalledOnAPrimitiveArrayType = true;
        }
        if (isIgnoredForTaints && !owner.startsWith("[") && !Instrumenter.isIgnoredClass(owner)) {
            if (name.equals("<init>")) {
                super.visitInsn(Opcodes.ACONST_NULL);
                desc = desc.substring(0, desc.indexOf(')')) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + desc.substring(desc.indexOf(')') + 1);
            } else
                name += TaintUtils.METHOD_SUFFIX_UNINST;
        }
        Configuration.taintTagFactory.methodOp(opcode, owner, name, TaintUtils.remapMethodDescForUninst(desc), itfc, mv, lvs, this);
        super.visitMethodInsn(opcode, owner, name, TaintUtils.remapMethodDescForUninst(desc), itfc);
        if (isCallToPrimitiveArrayClone) {
            // Now we have cloned (but not casted) array, and a clopned( but not casted) taint array
            // TA A
            super.visitTypeInsn(CHECKCAST, primitiveArrayType.getInternalName());
            registerTaintedArray();
        } else if (isCalledOnAPrimitiveArrayType) {
            if (TaintUtils.DEBUG_CALLS)
                System.out.println("Post invoke stack: " + analyzer.stack);
            if (Type.getReturnType(desc).getSort() == Type.VOID) {
                super.visitInsn(POP);
            } else if (analyzer.stack.size() >= 2) {
                // && analyzer.stack.get(analyzer.stack.size() - 2).equals("[I")) {
                // this is so dumb that it's an array type.
                super.visitInsn(SWAP);
                // This is the case that we are calling a method on a primitive array type so need to pop the taint
                super.visitInsn(POP);
            }
        }
        Type returnType = Type.getReturnType(desc);
        if (dontUnboxTaints && isIgnoredForTaints) {
            dontUnboxTaints = false;
            if (returnType.getSize() == 2) {
                super.visitInsn(POP2);
                super.visitInsn(ACONST_NULL);
                return;
            } else {
                super.visitInsn(POP);
                super.visitInsn(ACONST_NULL);
                return;
            }
        }
        if (isPrimitiveType(returnType)) {
            if (!nextLoadisTracked) {
                return;
            }
            nextLoadisTracked = false;
            if (returnType.getSort() == Type.ARRAY) {
                generateEmptyTaintArray(returnType.getDescriptor());
            } else if (returnType.getSize() == 2) {
                generateUnconstrainedTaint(0);
                super.visitInsn(DUP_X2);
                super.visitInsn(POP);
            } else {
                generateUnconstrainedTaint(0);
                super.visitInsn(SWAP);
            }
            analyzer.setTopOfStackTagged();
        // System.out.println("Post" + name + desc + analyzer.stackTagStatus);
        } else if (returnType.getDescriptor().endsWith("Ljava/lang/Object;")) {
            super.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MultiDTaintedArray.class), "boxIfNecessary", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
            super.visitTypeInsn(Opcodes.CHECKCAST, returnType.getInternalName());
        }
        if (TaintUtils.DEBUG_CALLS)
            System.out.println("Post invoke stack post swap pop maybe: " + analyzer.stack);
        return;
    }
    String newDesc = TaintUtils.remapMethodDesc(desc);
    if (Configuration.IMPLICIT_TRACKING) {
        if ((isInternalTaintingMethod(owner) || owner.startsWith("[")) && !name.equals("getControlFlow")) {
            newDesc = newDesc.replace(Type.getDescriptor(ControlTaintTagStack.class), "");
        } else
            super.visitVarInsn(ALOAD, lvs.getIdxOfMasterControlLV());
        if (owner.startsWith("["))
            hasNewName = false;
    }
    // boolean pushNull = false;
    if (name.equals("<init>") && !newDesc.equals(desc)) {
        // Add the taint sentinel to the desc
        super.visitInsn(ACONST_NULL);
        newDesc = newDesc.substring(0, newDesc.indexOf(")")) + Type.getDescriptor(TaintSentinel.class) + ")" + Type.getReturnType(newDesc).getDescriptor();
    }
    if (isPreAllocedReturnType) {
        // System.out.println("\t\tAdding stuff for " + owner + "." + name + newDesc);
        Type t = Type.getReturnType(newDesc);
        newDesc = newDesc.substring(0, newDesc.indexOf(")")) + t.getDescriptor() + ")" + t.getDescriptor();
        super.visitVarInsn(ALOAD, lvs.getPreAllocedReturnTypeVar(t));
    // System.out.println("n: " + lvs.getPreAllocedReturnTypeVar(t));
    // System.out.println("Analyzer lcoal is: " + analyzer.locals.get(lvs.getPreAllocedReturnTypeVar(t)));
    }
    Type origReturnType = Type.getReturnType(desc);
    Type returnType = TaintUtils.getContainerReturnType(Type.getReturnType(desc));
    if (TaintUtils.DEBUG_CALLS)
        System.out.println("Remapped call from " + owner + "." + name + desc + " to " + owner + "." + name + newDesc);
    if (!name.contains("<") && hasNewName)
        name += TaintUtils.METHOD_SUFFIX;
    if (TaintUtils.DEBUG_CALLS) {
        System.out.println("Calling w/ stack: " + analyzer.stack);
    }
    // if you call a method and instead of passing a primitive array you pass ACONST_NULL, we need to insert another ACONST_NULL in the stack
    // for the taint for that array
    Type[] args = Type.getArgumentTypes(newDesc);
    Type[] argsInReverse = new Type[args.length];
    int argsSize = 0;
    for (int i = 0; i < args.length; i++) {
        argsInReverse[args.length - i - 1] = args[i];
        argsSize += args[i].getSize();
    }
    int i = 1;
    int n = 1;
    boolean ignoreNext = false;
    // System.out.println("12dw23 Calling "+owner+"."+name+newDesc + "with " + analyzer.stack);
    for (Type t : argsInReverse) {
        if (analyzer.stack.get(analyzer.stack.size() - i) == Opcodes.TOP)
            i++;
        // if(ignoreNext)
        // System.out.println("ignore next i");
        Type onStack = getTypeForStackType(analyzer.stack.get(analyzer.stack.size() - i));
        if (!ignoreNext && t.getSort() == Type.ARRAY && t.getElementType().getSort() != Type.OBJECT) {
            // Need to check to see if there's a null on the stack in this position
            if (analyzer.stack.get(analyzer.stack.size() - i) == Opcodes.NULL) {
            // if (TaintUtils.DEBUG_CALLS)
            // System.err.println("Adding a null in call at " + n);
            // insertNullAt(n);
            } else if (onStack.getSort() == Type.OBJECT && (!isIgnoredForTaints || t.getDimensions() == 1)) {
                // Unbox this
                unboxTaintArrayAt(n, t.getDescriptor());
            }
        } else if (!ignoreNext && onStack.getSort() == Type.ARRAY && onStack.getElementType().getSort() != Type.OBJECT) {
            // There is an extra taint on the stack at this position
            if (TaintUtils.DEBUG_CALLS)
                System.err.println("removing taint array in call at " + n);
            storeTaintArrayAt(n, onStack.getDescriptor());
        }
        if ((t.getSort() == Type.ARRAY && t.getElementType().getSort() != Type.OBJECT) || (t.getDescriptor().startsWith("Ledu/columbia/cs/psl/phosphor/struct/Lazy")))
            ignoreNext = !ignoreNext;
        n++;
        i++;
    }
    // System.out.println("Args size: " + argsSize + " nargs " + args.length);
    // if (TaintUtils.DEBUG_CALLS)
    // System.out.println("No more changes: calling " + owner + "." + name + newDesc + " w/ stack: " + analyzer.stack);
    boolean isCalledOnAPrimitiveArrayType = false;
    if (opcode == INVOKEVIRTUAL) {
        if (analyzer.stack.get(analyzer.stack.size() - argsSize - 1) == null)
            System.out.println("NULL on stack for calllee???" + analyzer.stack + " argsize " + argsSize);
        Type callee = getTypeForStackType(analyzer.stack.get(analyzer.stack.size() - argsSize - 1));
        if (TaintUtils.DEBUG_CALLS)
            System.out.println("CALLEE IS " + callee);
        if (callee.getSort() == Type.ARRAY && callee.getElementType().getSort() != Type.OBJECT)
            isCalledOnAPrimitiveArrayType = true;
    }
    Configuration.taintTagFactory.methodOp(opcode, owner, name, newDesc, itfc, mv, lvs, this);
    super.visitMethodInsn(opcode, owner, name, newDesc, itfc);
    // System.out.println("Now: " + analyzer.stack);
    if (isCallToPrimitiveArrayClone) {
        // Now we have cloned (but not casted) array, and a clopned( but not casted) taint array
        // TA A
        // System.out.println(owner + name + newDesc + ": " + analyzer.stack);
        super.visitTypeInsn(CHECKCAST, primitiveArrayType.getInternalName());
        // System.out.println(owner + name + newDesc + ": " + analyzer.stack);
        registerTaintedArray();
    } else if (isCalledOnAPrimitiveArrayType) {
        if (TaintUtils.DEBUG_CALLS)
            System.out.println("Post invoke stack: " + analyzer.stack);
        if (Type.getReturnType(desc).getSort() == Type.VOID) {
            super.visitInsn(POP);
        } else if (analyzer.stack.size() >= 2) {
            // && analyzer.stack.get(analyzer.stack.size() - 2).equals("[I")) {
            // this is so dumb that it's an array type.
            super.visitInsn(SWAP);
            super.visitInsn(POP);
        }
    }
    if (dontUnboxTaints) {
        dontUnboxTaints = false;
        return;
    }
    String taintType = TaintUtils.getShadowTaintType(Type.getReturnType(desc).getDescriptor());
    if (taintType != null) {
        if (nextLoadisTracked) {
            FrameNode fn = getCurrentFrameNode();
            fn.type = Opcodes.F_NEW;
            super.visitInsn(DUP);
            String taintTypeRaw = Configuration.TAINT_TAG_DESC;
            if (Type.getReturnType(desc).getSort() == Type.ARRAY) {
                nextLoadisTracked = false;
                Label ok = new Label();
                Label isnull = new Label();
                super.visitJumpInsn(IFNULL, isnull);
                super.visitInsn(DUP);
                super.visitFieldInsn(GETFIELD, returnType.getInternalName(), "val", origReturnType.getDescriptor());
                FrameNode fn2 = getCurrentFrameNode();
                fn2.type = Opcodes.F_NEW;
                super.visitJumpInsn(GOTO, ok);
                super.visitLabel(isnull);
                fn.accept(this);
                super.visitInsn(ACONST_NULL);
                super.visitTypeInsn(CHECKCAST, origReturnType.getInternalName());
                super.visitLabel(ok);
                fn2.accept(this);
                analyzer.setTopOfStackTagged();
            } else {
                super.visitFieldInsn(GETFIELD, returnType.getInternalName(), "taint", taintTypeRaw);
                super.visitInsn(SWAP);
                nextLoadisTracked = false;
                super.visitFieldInsn(GETFIELD, returnType.getInternalName(), "val", origReturnType.getDescriptor());
                analyzer.setTopOfStackTagged();
            }
        } else {
            if (Type.getReturnType(desc).getSort() == Type.ARRAY) {
                FrameNode fn = getCurrentFrameNode();
                fn.type = Opcodes.F_NEW;
                nextLoadisTracked = false;
                Label ok = new Label();
                Label isnull = new Label();
                super.visitInsn(DUP);
                super.visitJumpInsn(IFNULL, isnull);
                super.visitFieldInsn(GETFIELD, returnType.getInternalName(), "val", origReturnType.getDescriptor());
                FrameNode fn2 = getCurrentFrameNode();
                fn2.type = Opcodes.F_NEW;
                super.visitJumpInsn(GOTO, ok);
                super.visitLabel(isnull);
                fn.accept(this);
                super.visitTypeInsn(CHECKCAST, origReturnType.getInternalName());
                super.visitLabel(ok);
                fn2.accept(this);
            } else
                super.visitFieldInsn(GETFIELD, returnType.getInternalName(), "val", origReturnType.getDescriptor());
        }
    }
    if (TaintUtils.DEBUG_CALLS)
        System.out.println("Post invoke stack post swap pop maybe: " + analyzer.stack);
}
Also used : FrameNode(org.objectweb.asm.tree.FrameNode) BoxedPrimitiveStoreWithIntTags(edu.columbia.cs.psl.phosphor.runtime.BoxedPrimitiveStoreWithIntTags) Label(org.objectweb.asm.Label) OffsetPreservingLabel(edu.columbia.cs.psl.phosphor.instrumenter.asm.OffsetPreservingLabel) TaintUtils(edu.columbia.cs.psl.phosphor.TaintUtils) BoxedPrimitiveStoreWithObjTags(edu.columbia.cs.psl.phosphor.runtime.BoxedPrimitiveStoreWithObjTags) Type(org.objectweb.asm.Type) ReflectionMasker(edu.columbia.cs.psl.phosphor.runtime.ReflectionMasker)

Example 18 with FrameNode

use of org.objectweb.asm.tree.FrameNode in project phosphor by gmu-swe.

the class TaintPassingMV method retrieveTaintedArray.

/**
 * Pre: A Post: TA A
 *
 * @param type
 */
public void retrieveTaintedArray(String type) {
    // A
    Label isNull = new Label();
    Label isDone = new Label();
    Type toCastTo = MultiDTaintedArray.getTypeForType(Type.getType(type));
    super.visitInsn(DUP);
    if (!isIgnoreAllInstrumenting)
        super.visitInsn(TaintUtils.IGNORE_EVERYTHING);
    super.visitJumpInsn(IFNULL, isNull);
    if (!isIgnoreAllInstrumenting)
        super.visitInsn(TaintUtils.IGNORE_EVERYTHING);
    // System.out.println("unbox: " + getTopOfStackType() + " type passed is " + type);
    super.visitTypeInsn(CHECKCAST, toCastTo.getInternalName());
    FrameNode fn = getCurrentFrameNode();
    super.visitInsn(DUP);
    Type arrayDesc = Type.getType(type);
    // System.out.println("Get tainted array from " + arrayDesc);
    // A A
    super.visitFieldInsn(GETFIELD, toCastTo.getInternalName(), "val", type);
    FrameNode fn2 = getCurrentFrameNode();
    super.visitJumpInsn(GOTO, isDone);
    super.visitLabel(isNull);
    acceptFn(fn);
    super.visitTypeInsn(CHECKCAST, toCastTo.getInternalName());
    super.visitInsn(ACONST_NULL);
    // if (arrayDesc.getElementType().getSort() == Type.OBJECT)
    // super.visitTypeInsn(CHECKCAST, "[Ljava/lang/Object;");
    // else
    // super.visitTypeInsn(CHECKCAST, Type.getType(TaintUtils.getShadowTaintType(arrayDesc.getDescriptor())).getInternalName());
    super.visitTypeInsn(CHECKCAST, type);
    super.visitLabel(isDone);
    acceptFn(fn2);
}
Also used : Type(org.objectweb.asm.Type) FrameNode(org.objectweb.asm.tree.FrameNode) Label(org.objectweb.asm.Label) OffsetPreservingLabel(edu.columbia.cs.psl.phosphor.instrumenter.asm.OffsetPreservingLabel)

Example 19 with FrameNode

use of org.objectweb.asm.tree.FrameNode in project phosphor by gmu-swe.

the class PrimitiveBoxingFixer method visitMethodInsn.

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itfc) {
    int nArgs = Type.getArgumentTypes(desc).length;
    boolean argIsStr = false;
    for (Type t : Type.getArgumentTypes(desc)) if (t.getSort() == Type.OBJECT && t.getDescriptor().equals("Ljava/lang/String;"))
        argIsStr = true;
    // Get an extra copy of the taint
    if (Configuration.WITH_ENUM_BY_VAL && opcode == INVOKESTATIC && owner.equals(Type.getInternalName(Enum.class))) {
        super.visitMethodInsn(opcode, Type.getInternalName(TaintUtils.class), "enumValueOf", desc, itfc);
        return;
    } else if ((owner.equals(Type.getInternalName(Integer.class)) || // || owner.equals(Type.getInternalName(Short.class)) ||  owner.equals(Type.getInternalName(Float.class))
    owner.equals(Type.getInternalName(Long.class)) || owner.equals(Type.getInternalName(Double.class))) && name.equals("valueOf$$PHOSPHORTAGGED") && nArgs == 2 && !argIsStr) {
        Type argT = Type.getArgumentTypes(desc)[1];
        int argSize = argT.getSize();
        if (argSize == 1) {
            // System.out.println(analyzer.stack);
            // stack is currently T I <top>
            // we'll support (Integer) 1 == (Integer) 1 as long as there is no taint on it.
            super.visitInsn(SWAP);
            FrameNode fn = getCurrentFrameNode();
            super.visitInsn(DUP);
            Label makeNew = new Label();
            Label isOK = new Label();
            super.visitJumpInsn((Configuration.MULTI_TAINTING ? IFNONNULL : IFNE), makeNew);
            super.visitInsn(SWAP);
            super.visitMethodInsn(opcode, owner, name, desc, itfc);
            super.visitJumpInsn(GOTO, isOK);
            super.visitLabel(makeNew);
            acceptFn(fn);
            super.visitInsn(SWAP);
            super.visitTypeInsn(Opcodes.NEW, owner);
            super.visitInsn(Opcodes.DUP);
            // T I N N
            super.visitInsn(Opcodes.DUP2_X2);
            super.visitInsn(Opcodes.POP2);
            // N N T I
            super.visitInsn(Opcodes.ACONST_NULL);
            super.visitMethodInsn(Opcodes.INVOKESPECIAL, owner, "<init>", "(" + Configuration.TAINT_TAG_DESC + Type.getArgumentTypes(desc)[1].getDescriptor() + Type.getDescriptor(TaintSentinel.class) + ")V", false);
            super.visitInsn(DUP);
            super.visitInsn(DUP);
            super.visitFieldInsn(GETFIELD, owner, "value" + TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
            super.visitMethodInsn(INVOKEVIRTUAL, owner, "set" + TaintUtils.TAINT_FIELD, "(" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I") + ")V", false);
            FrameNode fn2 = getCurrentFrameNode();
            super.visitLabel(isOK);
            if (!followedByFrame)
                acceptFn(fn2);
        } else if (argT.getSort() == Type.LONG) {
            super.visitMethodInsn(INVOKESTATIC, "edu/columbia/cs/psl/phosphor/runtime/RuntimeBoxUnboxPropogator", "valueOf", desc, false);
            return;
        } else {
            // T V V <top>
            super.visitInsn(DUP2_X1);
            super.visitInsn(POP2);
            // VV T
            FrameNode fn = getCurrentFrameNode();
            super.visitInsn(DUP);
            Label makeNew = new Label();
            Label isOK = new Label();
            super.visitJumpInsn((Configuration.MULTI_TAINTING ? IFNONNULL : IFNE), makeNew);
            // T VV
            super.visitInsn(DUP_X2);
            super.visitInsn(POP);
            super.visitMethodInsn(opcode, owner, name, desc, false);
            super.visitJumpInsn(GOTO, isOK);
            super.visitLabel(makeNew);
            acceptFn(fn);
            Type taintType = Type.getType(Configuration.TAINT_TAG_DESC);
            // VV T
            int tmp = lvs.getTmpLV(argT);
            int tmpT = lvs.getTmpLV(taintType);
            super.visitVarInsn(taintType.getOpcode(ISTORE), tmpT);
            super.visitVarInsn(argT.getOpcode(ISTORE), tmp);
            super.visitTypeInsn(Opcodes.NEW, owner);
            super.visitInsn(Opcodes.DUP);
            // T I N N
            super.visitVarInsn(taintType.getOpcode(ILOAD), tmpT);
            super.visitVarInsn(argT.getOpcode(ILOAD), tmp);
            super.visitInsn(Opcodes.ACONST_NULL);
            super.visitMethodInsn(Opcodes.INVOKESPECIAL, owner, "<init>", "(" + Configuration.TAINT_TAG_DESC + Type.getArgumentTypes(desc)[1].getDescriptor() + Type.getDescriptor(TaintSentinel.class) + ")V", false);
            super.visitInsn(DUP);
            super.visitInsn(DUP);
            super.visitFieldInsn(GETFIELD, owner, "value" + TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
            super.visitMethodInsn(INVOKEVIRTUAL, owner, "set" + TaintUtils.TAINT_FIELD, "(" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I") + ")V", false);
            lvs.freeTmpLV(tmp);
            lvs.freeTmpLV(tmpT);
            FrameNode fn2 = getCurrentFrameNode();
            super.visitLabel(isOK);
            if (!followedByFrame)
                acceptFn(fn2);
        // super.visitMethodInsn(opcode, owner, name, desc,itfc);
        }
    } else
        // else if (owner.equals(Type.getInternalName(Integer.class)) && name.equals("parseInt$$PHOSPHORTAGGED")) {
        // if (nArgs == 2) {
        // super.visitInsn(Opcodes.DUP);
        // super.visitMethodInsn(opcode, owner, name, desc,itfc);
        // super.visitInsn(DUP_X1);
        // super.visitInsn(SWAP);
        // retrieveTopOfStackTaintAndPop();
        // } else if (nArgs == 4) {
        // //S I I
        // super.visitInsn(DUP2_X1);
        // //				//I I S II
        // super.visitInsn(POP2);
        // //				//II S
        // retrieveTopOfStackTaint(true, true);
        // int tmpInt = lvs.getTmpLV(Type.INT_TYPE);
        // 
        // super.visitVarInsn(ISTORE, tmpInt);
        // super.visitInsn(DUP_X2);
        // super.visitInsn(POP);
        // super.visitMethodInsn(opcode, owner, name, desc,itfc);
        // super.visitInsn(DUP);
        // super.visitVarInsn(ILOAD, tmpInt);
        // lvs.freeTmpLV(tmpInt);
        // 
        // }
        // //stack is now <Integer Integer taint TOP>
        // super.visitFieldInsn(PUTFIELD, Type.getInternalName(TaintedInt.class), "taint", "I");
        // }
        super.visitMethodInsn(opcode, owner, name, desc, itfc);
    // TODO handle situations with radix param
    if (followedByFrame)
        followedByFrame = false;
}
Also used : Type(org.objectweb.asm.Type) FrameNode(org.objectweb.asm.tree.FrameNode) Label(org.objectweb.asm.Label) TaintUtils(edu.columbia.cs.psl.phosphor.TaintUtils) TaintSentinel(edu.columbia.cs.psl.phosphor.runtime.TaintSentinel)

Example 20 with FrameNode

use of org.objectweb.asm.tree.FrameNode in project phosphor by gmu-swe.

the class TaintTrackingClassVisitor method visitEnd.

@Override
public void visitEnd() {
    if ((isEnum || className.equals("java/lang/Enum")) && Configuration.WITH_ENUM_BY_VAL) {
        MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "clone", "()Ljava/lang/Object;", null, new String[] { "java/lang/CloneNotSupportedException" });
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "clone", "()Ljava/lang/Object;", false);
        mv.visitInsn(Opcodes.ARETURN);
        mv.visitEnd();
        mv.visitMaxs(0, 0);
    }
    boolean goLightOnGeneratedStuff = className.equals("java/lang/Byte");
    // }
    if (!hasSerialUID && !isInterface && !goLightOnGeneratedStuff) {
        if (!Configuration.MULTI_TAINTING)
            super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "serialVersionUIDPHOSPHOR_TAG", Configuration.TAINT_TAG_DESC, null, 0);
        else
            super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "serialVersionUIDPHOSPHOR_TAG", Configuration.TAINT_TAG_DESC, null, null);
    }
    // Add a field to track the instance's taint
    if (addTaintField && !goLightOnGeneratedStuff) {
        if (!Configuration.MULTI_TAINTING)
            super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD, "I", null, 0);
        else
            super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD, TaintAdapter.getTagType(className).getDescriptor(), null, null);
    // if(GEN_HAS_TAINTS_METHOD){
    // super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.HAS_TAINT_FIELD, "Z", null, 0);
    // super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.IS_TAINT_SEATCHING_FIELD, "Z", null, 0);
    // }
    }
    if (this.className.equals("java/lang/reflect/Method")) {
        super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD + "marked", "Z", null, 0);
        super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD + "method", "Ljava/lang/reflect/Method;", null, 0);
    } else if (this.className.equals("java/lang/Class")) {
        super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD + "marked", "Z", null, 0);
        super.visitField(Opcodes.ACC_PUBLIC, TaintUtils.TAINT_FIELD + "class", "Ljava/lang/Class;", null, 0);
    }
    for (FieldNode fn : extraFieldsToVisit) {
        if (className.equals("java/lang/Byte") && !fn.name.startsWith("value"))
            continue;
        if (isNormalClass) {
            fn.access = fn.access & ~Opcodes.ACC_FINAL;
            fn.access = fn.access & ~Opcodes.ACC_PRIVATE;
            fn.access = fn.access & ~Opcodes.ACC_PROTECTED;
            fn.access = fn.access | Opcodes.ACC_PUBLIC;
        }
        if ((fn.access & Opcodes.ACC_STATIC) != 0) {
            if (fn.desc.equals("I"))
                super.visitField(fn.access, fn.name, fn.desc, fn.signature, 0);
            else
                super.visitField(fn.access, fn.name, fn.desc, fn.signature, null);
        } else
            super.visitField(fn.access, fn.name, fn.desc, fn.signature, null);
    }
    if (FIELDS_ONLY)
        return;
    if ((isAbstractClass || isInterface) && implementsComparable && !goLightOnGeneratedStuff) {
        // Need to add this to interfaces so that we can call it on the interface
        if (Configuration.IMPLICIT_TRACKING)
            super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "compareTo$$PHOSPHORTAGGED", "(Ljava/lang/Object;" + Type.getDescriptor(ControlTaintTagStack.class) + Configuration.TAINTED_INT_DESC + ")" + Configuration.TAINTED_INT_DESC, null, null);
        else
            super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "compareTo$$PHOSPHORTAGGED", "(Ljava/lang/Object;" + Configuration.TAINTED_INT_DESC + ")" + Configuration.TAINTED_INT_DESC, null, null);
        if (Configuration.GENERATE_UNINST_STUBS) {
            super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "compareTo$$PHOSPHORUNTAGGED", "(Ljava/lang/Object;)I", null, null);
        }
    }
    if (generateEquals && !goLightOnGeneratedStuff) {
        superMethodsToOverride.remove("equals(Ljava/lang/Object;)Z");
        methodsToAddWrappersFor.add(new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_NATIVE, "equals", "(Ljava/lang/Object;)Z", null, null));
        MethodVisitor mv;
        mv = super.visitMethod(Opcodes.ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null);
        mv.visitCode();
        Label start = new Label();
        Label end = new Label();
        mv.visitLabel(start);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
        mv.visitLabel(end);
        mv.visitInsn(Opcodes.IRETURN);
        mv.visitLocalVariable("this", "L" + className + ";", null, start, end, 0);
        mv.visitLocalVariable("other", "Ljava/lang/Object;", null, start, end, 1);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (generateHashCode && !goLightOnGeneratedStuff) {
        superMethodsToOverride.remove("hashCode()I");
        methodsToAddWrappersFor.add(new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_NATIVE, "hashCode", "()I", null, null));
        MethodVisitor mv;
        mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hashCode", "()I", null, null);
        mv.visitCode();
        Label start = new Label();
        Label end = new Label();
        mv.visitLabel(start);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "hashCode", "()I", false);
        mv.visitLabel(end);
        mv.visitInsn(Opcodes.IRETURN);
        mv.visitLocalVariable("this", "L" + className + ";", null, start, end, 0);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (addTaintMethod) {
        if (isInterface) {
            super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "get" + TaintUtils.TAINT_FIELD, "()" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I"), null, null);
            if (GEN_HAS_TAINTS_METHOD)
                super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "hasAnyTaints", "()Z", null, null);
            super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "set" + TaintUtils.TAINT_FIELD, "(" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I") + ")V", null, null);
        } else {
            MethodVisitor mv;
            if (!Configuration.MULTI_TAINTING) {
                mv = super.visitMethod(Opcodes.ACC_PUBLIC, "get" + TaintUtils.TAINT_FIELD, "()" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I"), null, null);
                mv.visitCode();
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, className, TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
                mv.visitInsn(Opcodes.IRETURN);
                mv.visitMaxs(0, 0);
                mv.visitEnd();
                mv = super.visitMethod(Opcodes.ACC_PUBLIC, "set" + TaintUtils.TAINT_FIELD, "(" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I") + ")V", null, null);
                mv.visitCode();
                Configuration.taintTagFactory.generateSetTag(mv, className);
                if (className.equals("java/lang/String")) {
                    // Also overwrite the taint tag of all of the chars behind this string
                    Type taintType = MultiDTaintedArray.getTypeForType(Type.getType(char[].class));
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitInsn(Opcodes.DUP);
                    mv.visitFieldInsn(Opcodes.GETFIELD, className, "value", "[C");
                    // A
                    mv.visitTypeInsn(Opcodes.NEW, taintType.getInternalName());
                    // A T
                    mv.visitInsn(Opcodes.DUP_X1);
                    // T A T
                    mv.visitInsn(Opcodes.SWAP);
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, taintType.getInternalName(), "<init>", "([C)V", false);
                    // T
                    mv.visitInsn(Opcodes.DUP_X1);
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "value" + TaintUtils.TAINT_FIELD, taintType.getDescriptor());
                    mv.visitVarInsn(Opcodes.ILOAD, 1);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Configuration.STRING_SET_TAG_TAINT_CLASS, "setTaints", "(" + taintType.getDescriptor() + "I)V", false);
                // =======
                // mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(TaintChecker.class), "setTaints", "([II)V", false);
                } else if ((className.equals(TaintPassingMV.INTEGER_NAME) || className.equals(TaintPassingMV.LONG_NAME) || className.equals(TaintPassingMV.FLOAT_NAME) || className.equals(TaintPassingMV.DOUBLE_NAME))) {
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitVarInsn(Opcodes.ILOAD, 1);
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "value" + TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
                // For primitive types, also set the "value" field
                // >>>>>>> master
                }
                mv.visitInsn(Opcodes.RETURN);
                mv.visitMaxs(0, 0);
                mv.visitEnd();
            } else {
                mv = super.visitMethod(Opcodes.ACC_PUBLIC, "get" + TaintUtils.TAINT_FIELD, "()" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I"), null, null);
                mv = new TaintTagFieldCastMV(mv);
                mv.visitCode();
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, className, TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
                mv.visitInsn(Opcodes.ARETURN);
                mv.visitMaxs(0, 0);
                mv.visitEnd();
                mv = super.visitMethod(Opcodes.ACC_PUBLIC, "set" + TaintUtils.TAINT_FIELD, "(" + (Configuration.MULTI_TAINTING ? "Ljava/lang/Object;" : "I") + ")V", null, null);
                mv = new TaintTagFieldCastMV(mv);
                mv.visitCode();
                Configuration.taintTagFactory.generateSetTag(mv, className);
                if (className.equals("java/lang/String")) {
                    // Also overwrite the taint tag of all of the chars behind this string
                    Type taintType = MultiDTaintedArray.getTypeForType(Type.getType(char[].class));
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitInsn(Opcodes.DUP);
                    mv.visitFieldInsn(Opcodes.GETFIELD, className, "value", "[C");
                    // A
                    mv.visitTypeInsn(Opcodes.NEW, taintType.getInternalName());
                    // A T
                    mv.visitInsn(Opcodes.DUP_X1);
                    // T A T
                    mv.visitInsn(Opcodes.SWAP);
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, taintType.getInternalName(), "<init>", "([C)V", false);
                    // T
                    mv.visitInsn(Opcodes.DUP_X1);
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "value" + TaintUtils.TAINT_FIELD, taintType.getDescriptor());
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Configuration.STRING_SET_TAG_TAINT_CLASS, "setTaints", "(" + taintType.getDescriptor() + "Ljava/lang/Object;)V", false);
                } else if ((className.equals(TaintPassingMV.INTEGER_NAME) || className.equals(TaintPassingMV.LONG_NAME) || className.equals(TaintPassingMV.FLOAT_NAME) || className.equals(TaintPassingMV.DOUBLE_NAME))) {
                    // For primitive types, also set the "value" field
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "value" + TaintUtils.TAINT_FIELD, Configuration.TAINT_TAG_DESC);
                }
                mv.visitInsn(Opcodes.RETURN);
                mv.visitMaxs(0, 0);
                mv.visitEnd();
            }
        // if (!this.isProxyClass && GEN_HAS_TAINTS_METHOD) {
        // mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasAnyTaints", "()Z", null, null);
        // mv.visitCode();
        // Label keepGoing1 = new Label();
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitFieldInsn(Opcodes.GETFIELD, className, TaintUtils.HAS_TAINT_FIELD, "Z");
        // mv.visitJumpInsn(Opcodes.IFEQ, keepGoing1);
        // mv.visitInsn(Opcodes.ICONST_1);
        // mv.visitInsn(Opcodes.IRETURN);
        // mv.visitLabel(keepGoing1);
        // //TODO if the istaitnsearchingfield is 1, then return 0.
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitFieldInsn(Opcodes.GETFIELD, className, TaintUtils.IS_TAINT_SEATCHING_FIELD, "Z");
        // Label keepGoing = new Label();
        // mv.visitJumpInsn(Opcodes.IFEQ, keepGoing);
        // mv.visitInsn(Opcodes.ICONST_0);
        // mv.visitInsn(Opcodes.IRETURN);
        // mv.visitLabel(keepGoing);
        // if (myFields.size() > 0) {
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitInsn(Opcodes.ICONST_1);
        // mv.visitFieldInsn(Opcodes.PUTFIELD, className, TaintUtils.IS_TAINT_SEATCHING_FIELD, "Z");
        // 
        // Label hasTaint = new Label();
        // for (FieldNode fn : myFields) {
        // Type fieldDesc = Type.getType(fn.desc);
        // if (TaintUtils.getShadowTaintType(fn.desc) != null) {
        // if (fieldDesc.getSort() == Type.ARRAY) {
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitFieldInsn(Opcodes.GETFIELD, className, fn.name + TaintUtils.TAINT_FIELD, TaintUtils.getShadowTaintType(fn.desc));
        // if (fieldDesc.getDimensions() == 1) {
        // mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(TaintUtils.class), "arrayHasTaints", "([I)Z",false);
        // } else if (fieldDesc.getDimensions() == 2) {
        // mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(TaintUtils.class), "arrayHasTaints", "([[I)Z",false);
        // } else if (fieldDesc.getDimensions() == 3) {
        // mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(TaintUtils.class), "arrayHasTaints", "([[[I)Z",false);
        // } else {
        // //bail and say that it has a taint i guess
        // mv.visitInsn(Opcodes.POP);
        // mv.visitInsn(Opcodes.ICONST_1);
        // }
        // mv.visitJumpInsn(Opcodes.IFNE, hasTaint);
        // } else {
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitFieldInsn(Opcodes.GETFIELD, className, fn.name + TaintUtils.TAINT_FIELD, "I");
        // mv.visitJumpInsn(Opcodes.IFNE, hasTaint);
        // }
        // } else if (!Instrumenter.isIgnoredClass(fieldDesc.getInternalName()) && GEN_HAS_TAINTS_METHOD) {
        // int op = Opcodes.INVOKEVIRTUAL;
        // if (Instrumenter.isInterface(fieldDesc.getInternalName()))
        // op = Opcodes.INVOKEINTERFACE;
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitFieldInsn(Opcodes.GETFIELD, className, fn.name, fn.desc);
        // mv.visitMethodInsn(op, fieldDesc.getInternalName(), "hasAnyTaints", "()Z",false);
        // mv.visitJumpInsn(Opcodes.IFNE, hasTaint);
        // } else {
        // //TODO XXX MUST FETCH THE TAINT SOMEHOW FOR IGNORED CLASSES FOR THIS TO BE SOUND
        // }
        // }
        // 
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitInsn(Opcodes.ICONST_0);
        // mv.visitFieldInsn(Opcodes.PUTFIELD, className, TaintUtils.IS_TAINT_SEATCHING_FIELD, "Z");
        // 
        // mv.visitInsn(Opcodes.ICONST_0);
        // mv.visitInsn(Opcodes.IRETURN);
        // 
        // mv.visitLabel(hasTaint);
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitInsn(Opcodes.ICONST_0);
        // mv.visitFieldInsn(Opcodes.PUTFIELD, className, TaintUtils.IS_TAINT_SEATCHING_FIELD, "Z");
        // 
        // mv.visitVarInsn(Opcodes.ALOAD, 0);
        // mv.visitInsn(Opcodes.ICONST_1);
        // mv.visitFieldInsn(Opcodes.PUTFIELD, className, TaintUtils.HAS_TAINT_FIELD, "Z");
        // mv.visitInsn(Opcodes.ICONST_1);
        // mv.visitInsn(Opcodes.IRETURN);
        // } else {
        // mv.visitInsn(Opcodes.ICONST_0);
        // mv.visitInsn(Opcodes.IRETURN);
        // }
        // mv.visitMaxs(0, 0);
        // mv.visitEnd();
        // }
        }
    }
    // generateStrLdcWrapper();
    if (!goLightOnGeneratedStuff)
        for (MethodNode m : methodsToAddWrappersFor) {
            if ((m.access & Opcodes.ACC_NATIVE) == 0) {
                if ((m.access & Opcodes.ACC_ABSTRACT) == 0) {
                    // not native
                    MethodNode fullMethod = forMore.get(m);
                    Type origReturn = Type.getReturnType(m.desc);
                    Type newReturn = TaintUtils.getContainerReturnType(origReturn);
                    boolean needToPrealloc = TaintUtils.isPreAllocReturnType(m.desc);
                    String[] exceptions = new String[m.exceptions.size()];
                    exceptions = (String[]) m.exceptions.toArray(exceptions);
                    MethodVisitor mv = super.visitMethod(m.access, m.name, m.desc, m.signature, exceptions);
                    mv = new TaintTagFieldCastMV(mv);
                    if (fullMethod != null) {
                        visitAnnotations(mv, fullMethod);
                    }
                    NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(className, m.access, m.name, m.desc, mv);
                    MethodVisitor soc = new SpecialOpcodeRemovingMV(an, false, className, false);
                    LocalVariableManager lvs = new LocalVariableManager(m.access, m.desc, soc, an, mv, generateExtraLVDebug);
                    lvs.setPrimitiveArrayAnalyzer(new PrimitiveArrayAnalyzer(newReturn));
                    GeneratorAdapter ga = new GeneratorAdapter(lvs, m.access, m.name, m.desc);
                    Label startLabel = new Label();
                    ga.visitCode();
                    ga.visitLabel(startLabel);
                    ga.visitLineNumber(0, startLabel);
                    Type[] argTypes = Type.getArgumentTypes(m.desc);
                    int idx = 0;
                    if ((m.access & Opcodes.ACC_STATIC) == 0) {
                        ga.visitVarInsn(Opcodes.ALOAD, 0);
                        idx++;
                    }
                    String newDesc = "(";
                    for (Type t : argTypes) {
                        boolean loaded = false;
                        boolean needToBoxMultiD = false;
                        if (t.getSort() == Type.ARRAY) {
                            if (t.getElementType().getSort() != Type.OBJECT) {
                                if (t.getDimensions() == 1) {
                                    newDesc += TaintUtils.getShadowTaintType(t.getDescriptor());
                                    ga.visitVarInsn(Opcodes.ALOAD, idx);
                                    TaintAdapter.createNewTaintArray(t.getDescriptor(), an, lvs, lvs);
                                    loaded = true;
                                } else {
                                    newDesc += MultiDTaintedArray.getTypeForType(t).getDescriptor();
                                    needToBoxMultiD = true;
                                }
                            }
                        } else if (t.getSort() != Type.OBJECT) {
                            newDesc += Configuration.TAINT_TAG_DESC;
                            Configuration.taintTagFactory.generateEmptyTaint(ga);
                        }
                        if (!loaded)
                            ga.visitVarInsn(t.getOpcode(Opcodes.ILOAD), idx);
                        if (NATIVE_BOX_UNBOX && t.getSort() == Type.OBJECT && Instrumenter.isCollection(t.getInternalName())) {
                            // //  public final static ensureIsBoxed(Ljava/util/Collection;)Ljava/util/Collection;
                            ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(NativeHelper.class), "ensureIsBoxed" + (Configuration.MULTI_TAINTING ? "ObjTags" : ""), "(Ljava/util/Collection;)Ljava/util/Collection;", false);
                            ga.visitTypeInsn(Opcodes.CHECKCAST, t.getInternalName());
                        }
                        if (t.getDescriptor().endsWith("java/lang/Object;")) {
                            ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MultiDTaintedArray.class), "boxIfNecessary", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
                            ga.visitTypeInsn(Opcodes.CHECKCAST, t.getInternalName());
                        }
                        if (!needToBoxMultiD)
                            newDesc += t.getDescriptor();
                        else {
                            // Label isNull = new Label();
                            Label isDone = new Label();
                            ga.visitInsn(Opcodes.DUP);
                            ga.visitJumpInsn(Opcodes.IFNULL, isDone);
                            ga.visitIntInsn(Opcodes.BIPUSH, t.getElementType().getSort());
                            ga.visitIntInsn(Opcodes.BIPUSH, t.getDimensions());
                            ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "initWithEmptyTaints", "([Ljava/lang/Object;II)Ljava/lang/Object;", false);
                            FrameNode fn = TaintAdapter.getCurrentFrameNode(an);
                            fn.stack.set(fn.stack.size() - 1, "java/lang/Object");
                            ga.visitLabel(isDone);
                            TaintAdapter.acceptFn(fn, lvs);
                            ga.visitTypeInsn(Opcodes.CHECKCAST, MultiDTaintedArray.getTypeForType(t).getDescriptor());
                        }
                        idx += t.getSize();
                    }
                    if (Configuration.IMPLICIT_TRACKING) {
                        newDesc += Type.getDescriptor(ControlTaintTagStack.class);
                        ga.visitTypeInsn(Opcodes.NEW, Type.getInternalName(ControlTaintTagStack.class));
                        ga.visitInsn(Opcodes.DUP);
                        ga.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ControlTaintTagStack.class), "<init>", "()V", false);
                    }
                    if (m.name.equals("<init>")) {
                        newDesc += Type.getDescriptor(TaintSentinel.class);
                        ga.visitInsn(Opcodes.ACONST_NULL);
                    }
                    if (needToPrealloc) {
                        newDesc += newReturn.getDescriptor();
                        an.visitVarInsn(Opcodes.ALOAD, lvs.getPreAllocedReturnTypeVar(newReturn));
                    }
                    newDesc += ")" + newReturn.getDescriptor();
                    int opcode;
                    if ((m.access & Opcodes.ACC_STATIC) == 0) {
                        opcode = Opcodes.INVOKESPECIAL;
                    } else
                        opcode = Opcodes.INVOKESTATIC;
                    if (m.name.equals("<init>")) {
                        ga.visitMethodInsn(Opcodes.INVOKESPECIAL, className, m.name, newDesc, false);
                    } else
                        ga.visitMethodInsn(opcode, className, m.name + TaintUtils.METHOD_SUFFIX, newDesc, false);
                    // unbox collections
                    idx = 0;
                    if ((m.access & Opcodes.ACC_STATIC) == 0) {
                        idx++;
                    }
                    for (Type t : argTypes) {
                        if (NATIVE_BOX_UNBOX && t.getSort() == Type.OBJECT && Instrumenter.isCollection(t.getInternalName())) {
                            // //  public final static ensureIsBoxed(Ljava/util/Collection;)Ljava/util/Collection;
                            ga.visitVarInsn(t.getOpcode(Opcodes.ILOAD), idx);
                            ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(NativeHelper.class), "ensureIsUnBoxed" + (Configuration.MULTI_TAINTING ? "ObjTags" : ""), "(Ljava/util/Collection;)Ljava/util/Collection;", false);
                            ga.visitInsn(Opcodes.POP);
                        }
                        idx += t.getSize();
                    }
                    if (origReturn != newReturn) {
                        String taintType = TaintUtils.getShadowTaintType(origReturn.getDescriptor());
                        if (taintType != null) {
                            // ga.visitInsn(Opcodes.SWAP);
                            if (origReturn.getSort() == Type.ARRAY) {
                                FrameNode fn2 = TaintAdapter.getCurrentFrameNode(an);
                                Label isNull = new Label();
                                ga.visitInsn(Opcodes.DUP);
                                Label isDone = new Label();
                                ga.visitJumpInsn(Opcodes.IFNULL, isNull);
                                ga.visitFieldInsn(Opcodes.GETFIELD, newReturn.getInternalName(), "val", origReturn.getDescriptor());
                                FrameNode fn = TaintAdapter.getCurrentFrameNode(an);
                                ga.visitJumpInsn(Opcodes.GOTO, isDone);
                                fn.type = Opcodes.F_NEW;
                                fn2.type = Opcodes.F_NEW;
                                ga.visitLabel(isNull);
                                TaintAdapter.acceptFn(fn2, ga);
                                ga.visitInsn(Opcodes.POP);
                                ga.visitInsn(Opcodes.ACONST_NULL);
                                ga.visitLabel(isDone);
                                TaintAdapter.acceptFn(fn, ga);
                            } else
                                ga.visitFieldInsn(Opcodes.GETFIELD, newReturn.getInternalName(), "val", origReturn.getDescriptor());
                        } else {
                            // Need to convert from [[WrapperForCArray to [[[C
                            Label isDone = new Label();
                            ga.visitInsn(Opcodes.DUP);
                            ga.visitJumpInsn(Opcodes.IFNULL, isDone);
                            ga.visitIntInsn(Opcodes.BIPUSH, origReturn.getElementType().getSort());
                            ga.visitIntInsn(Opcodes.BIPUSH, origReturn.getDimensions() - 1);
                            ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxVal", "(Ljava/lang/Object;II)Ljava/lang/Object;", false);
                            FrameNode fn = TaintAdapter.getCurrentFrameNode(an);
                            fn.stack.set(fn.stack.size() - 1, "java/lang/Object");
                            ga.visitLabel(isDone);
                            TaintAdapter.acceptFn(fn, lvs);
                            ga.visitTypeInsn(Opcodes.CHECKCAST, origReturn.getInternalName());
                        }
                    }
                    Label endLabel = new Label();
                    ga.visitLabel(endLabel);
                    ga.returnValue();
                    // int j = 0;
                    for (Object o : m.localVariables) {
                        LocalVariableNode n = (LocalVariableNode) o;
                        ga.visitLocalVariable(n.name, n.desc, n.signature, startLabel, endLabel, n.index);
                    }
                    if (m.name.equals("<init>")) {
                    }
                    ga.visitMaxs(0, 0);
                    ga.visitEnd();
                } else {
                    String[] exceptions = new String[m.exceptions.size()];
                    exceptions = (String[]) m.exceptions.toArray(exceptions);
                    MethodNode fullMethod = forMore.get(m);
                    MethodVisitor mv = super.visitMethod(m.access, m.name, m.desc, m.signature, exceptions);
                    if (fullMethod.annotationDefault != null) {
                        AnnotationVisitor av = mv.visitAnnotationDefault();
                        acceptAnnotationRaw(av, null, fullMethod.annotationDefault);
                        av.visitEnd();
                    }
                    m.accept(mv);
                }
            } else {
                // generate wrapper for native method - a native wrapper
                generateNativeWrapper(m, m.name, false);
                if (className.equals("sun/misc/Unsafe"))
                    generateNativeWrapper(m, m.name, true);
            }
        }
    superMethodsToOverride.remove("wait(JI)V");
    superMethodsToOverride.remove("wait(J)V");
    superMethodsToOverride.remove("wait()V");
    superMethodsToOverride.remove("notify()V");
    superMethodsToOverride.remove("notifyAll()V");
    for (Method m : superMethodsToOverride.values()) {
        int acc = Opcodes.ACC_PUBLIC;
        if (Modifier.isProtected(m.getModifiers()) && isInterface)
            continue;
        else if (Modifier.isPrivate(m.getModifiers()))
            continue;
        if (Modifier.isStatic(m.getModifiers()))
            acc = acc | Opcodes.ACC_STATIC;
        if (isInterface)
            acc = acc | Opcodes.ACC_ABSTRACT;
        else
            acc = acc & ~Opcodes.ACC_ABSTRACT;
        MethodNode mn = new MethodNode(Opcodes.ASM5, acc, m.getName(), Type.getMethodDescriptor(m), null, null);
        generateNativeWrapper(mn, mn.name, false);
        if (Configuration.GENERATE_UNINST_STUBS) {
            MethodVisitor mv = super.visitMethod((isInterface ? mn.access : mn.access & ~Opcodes.ACC_ABSTRACT), mn.name + TaintUtils.METHOD_SUFFIX_UNINST, mn.desc, mn.signature, (String[]) mn.exceptions.toArray(new String[0]));
            GeneratorAdapter ga = new GeneratorAdapter(mv, mn.access, mn.name, mn.desc);
            visitAnnotations(mv, mn);
            if (!isInterface) {
                mv.visitCode();
                int opcode;
                if ((mn.access & Opcodes.ACC_STATIC) == 0) {
                    ga.loadThis();
                    opcode = Opcodes.INVOKESPECIAL;
                } else
                    opcode = Opcodes.INVOKESTATIC;
                ga.loadArgs();
                ga.visitMethodInsn(opcode, className, mn.name, mn.desc, false);
                ga.returnValue();
                mv.visitMaxs(0, 0);
                mv.visitEnd();
            }
        }
    }
    if (Configuration.WITH_SELECTIVE_INST) {
        // Make sure that there's a wrapper in place for each method
        for (MethodNode m : methodsToMakeUninstWrappersAround) {
            // these methods were previously renamed to be $$PHOSPHORUNTASGGED
            // first, make one that has a descriptor WITH taint tags, that calls into the uninst one
            generateNativeWrapper(m, m.name + TaintUtils.METHOD_SUFFIX_UNINST, false);
            // next, make one WITHOUT taint tags, and WITHOUT the suffix
            String mName = m.name;
            String mToCall = m.name;
            String descToCall = m.desc;
            boolean isInit = false;
            String mDesc = m.desc;
            if ((Opcodes.ACC_NATIVE & m.access) != 0) {
                mName += TaintUtils.METHOD_SUFFIX_UNINST;
                m.access = m.access & ~Opcodes.ACC_NATIVE;
                mDesc = TaintUtils.remapMethodDescForUninst(mDesc);
            } else if (m.name.equals("<init>")) {
                isInit = true;
                descToCall = mDesc.substring(0, m.desc.indexOf(')')) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + mDesc.substring(mDesc.indexOf(')') + 1);
                descToCall = TaintUtils.remapMethodDescForUninst(descToCall);
            } else {
                mToCall += TaintUtils.METHOD_SUFFIX_UNINST;
                descToCall = TaintUtils.remapMethodDescForUninst(descToCall);
            }
            MethodVisitor mv = super.visitMethod(m.access, mName, mDesc, m.signature, (String[]) m.exceptions.toArray(new String[0]));
            visitAnnotations(mv, m);
            if (!isInterface) {
                GeneratorAdapter ga = new GeneratorAdapter(mv, m.access, m.name, mDesc);
                mv.visitCode();
                int opcode;
                if ((m.access & Opcodes.ACC_STATIC) == 0) {
                    ga.loadThis();
                    opcode = Opcodes.INVOKESPECIAL;
                } else
                    opcode = Opcodes.INVOKESTATIC;
                Type[] origArgs = Type.getArgumentTypes(m.desc);
                Type[] newArgs = Type.getArgumentTypes(descToCall);
                for (int i = 0; i < origArgs.length; i++) {
                    ga.loadArg(i);
                    if (origArgs[i].getSort() == Type.ARRAY && origArgs[i].getElementType().getSort() != Type.OBJECT && origArgs[i].getDimensions() > 1) {
                        ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MultiDTaintedArray.class), "boxIfNecessary", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
                        ga.visitTypeInsn(Opcodes.CHECKCAST, newArgs[i].getInternalName());
                    }
                }
                if (isInit)
                    ga.visitInsn(Opcodes.ACONST_NULL);
                Type retType = Type.getReturnType(m.desc);
                ga.visitMethodInsn(opcode, className, mToCall, descToCall, false);
                if (retType.getSort() == Type.ARRAY && retType.getDimensions() > 1 && retType.getElementType().getSort() != Type.OBJECT) {
                    ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxRaw", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
                    ga.checkCast(retType);
                }
                ga.returnValue();
                mv.visitMaxs(0, 0);
            }
            mv.visitEnd();
        }
    }
    if (Configuration.GENERATE_UNINST_STUBS) {
        // one level deep - and it will call back into instrumented versions
        for (Entry<MethodNode, MethodNode> am : forMore.entrySet()) {
            MethodNode mn = am.getKey();
            if (mn.name.equals("<clinit>"))
                continue;
            String mName = mn.name;
            String mDesc = TaintUtils.remapMethodDescForUninst(mn.desc);
            if (mName.equals("<init>")) {
                mDesc = mDesc.substring(0, mDesc.indexOf(')')) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + mDesc.substring(mDesc.indexOf(')') + 1);
            } else {
                mName += TaintUtils.METHOD_SUFFIX_UNINST;
            }
            MethodVisitor mv = super.visitMethod(mn.access & ~Opcodes.ACC_NATIVE, mName, mDesc, mn.signature, (String[]) mn.exceptions.toArray(new String[0]));
            MethodNode meth = am.getValue();
            if ((mn.access & Opcodes.ACC_NATIVE) != 0) {
                GeneratorAdapter ga = new GeneratorAdapter(mv, mn.access, mn.name, mn.desc);
                visitAnnotations(mv, mn);
                mv.visitCode();
                int opcode;
                if ((mn.access & Opcodes.ACC_STATIC) == 0) {
                    ga.loadThis();
                    opcode = Opcodes.INVOKESPECIAL;
                } else
                    opcode = Opcodes.INVOKESTATIC;
                Type[] args = Type.getArgumentTypes(mn.desc);
                for (int i = 0; i < args.length; i++) {
                    ga.loadArg(i);
                    if (args[i].getSort() == Type.ARRAY && args[i].getDimensions() > 1 && args[i].getElementType().getSort() != Type.OBJECT) {
                        ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxRaw", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
                        ga.visitTypeInsn(Opcodes.CHECKCAST, args[i].getInternalName());
                    }
                }
                ga.visitMethodInsn(opcode, className, mn.name, mn.desc, false);
                ga.returnValue();
                mv.visitMaxs(0, 0);
                mv.visitEnd();
            } else {
                mv = new SpecialOpcodeRemovingMV(mv, ignoreFrames, className, fixLdcClass);
                NeverNullArgAnalyzerAdapter analyzer = new NeverNullArgAnalyzerAdapter(className, mn.access, mn.name, mDesc, mv);
                mv = analyzer;
                mv = new UninstrumentedReflectionHidingMV(mv, className);
                UninstrumentedReflectionHidingMV ta = (UninstrumentedReflectionHidingMV) mv;
                mv = new UninstrumentedCompatMV(mn.access, className, mn.name, mn.desc, mn.signature, (String[]) mn.exceptions.toArray(new String[0]), mv, analyzer, ignoreFrames);
                LocalVariableManager lvs = new LocalVariableManager(mn.access, mn.desc, mv, analyzer, analyzer, generateExtraLVDebug);
                final PrimitiveArrayAnalyzer primArrayAnalyzer = new PrimitiveArrayAnalyzer(className, mn.access, mn.name, mn.desc, null, null, null);
                lvs.disable();
                lvs.setPrimitiveArrayAnalyzer(primArrayAnalyzer);
                ((UninstrumentedCompatMV) mv).setLocalVariableSorter(lvs);
                ta.setLvs(lvs);
                mv = lvs;
                meth.accept(new MethodVisitor(Opcodes.ASM5) {

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                        // determine if this is going to be uninst, and then if we need to pre-alloc for its return :/
                        if (Configuration.WITH_SELECTIVE_INST && Instrumenter.isIgnoredMethodFromOurAnalysis(owner, name, desc)) {
                        // uninst
                        } else {
                            Type returnType = Type.getReturnType(desc);
                            Type newReturnType = TaintUtils.getContainerReturnType(returnType);
                            if (newReturnType != returnType && !(returnType.getSort() == Type.ARRAY))
                                primArrayAnalyzer.wrapperTypesToPreAlloc.add(newReturnType);
                        }
                    }
                });
                meth.accept(mv);
            }
        }
    }
    // if (!goLightOnGeneratedStuff && TaintUtils.GENERATE_FASTPATH_VERSIONS)
    // for (final MethodNode m : myMethods) {
    // final String oldDesc = m.desc;
    // if (m.name.equals("<init>")) {
    // m.desc = m.desc.substring(0, m.desc.indexOf(")")) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + Type.getReturnType(m.desc).getDescriptor();
    // } else if (m.name.equals("<clinit>")) {
    // continue;
    // } else {
    // m.name = m.name.replace(TaintUtils.METHOD_SUFFIX, "") + "$$INVIVO_UNINST";
    // }
    // if ((m.access & Opcodes.ACC_ABSTRACT) != 0 && !isInterface) {
    // //Let's see what happens if we make these non-abstract, with no body, to try to fix
    // //problems with jasper usage.
    // m.access = m.access & ~Opcodes.ACC_ABSTRACT;
    // m.instructions = new InsnList();
    // Type ret = Type.getReturnType(m.desc);
    // switch (ret.getSort()) {
    // case Type.BOOLEAN:
    // case Type.BYTE:
    // case Type.CHAR:
    // case Type.SHORT:
    // case Type.INT:
    // m.instructions.add(new InsnNode(Opcodes.ICONST_0));
    // m.instructions.add(new InsnNode(Opcodes.IRETURN));
    // break;
    // case Type.DOUBLE:
    // m.instructions.add(new InsnNode(Opcodes.DCONST_0));
    // m.instructions.add(new InsnNode(Opcodes.DRETURN));
    // break;
    // case Type.FLOAT:
    // m.instructions.add(new InsnNode(Opcodes.FCONST_0));
    // m.instructions.add(new InsnNode(Opcodes.FRETURN));
    // break;
    // case Type.LONG:
    // m.instructions.add(new InsnNode(Opcodes.LCONST_0));
    // m.instructions.add(new InsnNode(Opcodes.LRETURN));
    // break;
    // case Type.ARRAY:
    // case Type.OBJECT:
    // m.instructions.add(new InsnNode(Opcodes.ACONST_NULL));
    // m.instructions.add(new InsnNode(Opcodes.ARETURN));
    // break;
    // case Type.VOID:
    // m.instructions.add(new InsnNode(Opcodes.RETURN));
    // break;
    // }
    // }
    // m.accept(new ClassVisitor(Opcodes.ASM5, this.cv) {
    // @Override
    // public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    // MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    // if (name.equals("<init>")) {
    // mv = new ConstructorArgReindexer(mv, access, name, desc, oldDesc);
    // }
    // return new MethodVisitor(api, mv) {
    // @Override
    // public void visitVarInsn(int opcode, int var) {
    // super.visitVarInsn(opcode, var);
    // }
    // 
    // @Override
    // public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    // if (!Instrumenter.isIgnoredClass(owner)) {
    // if (name.equals("<init>")) {
    // super.visitInsn(Opcodes.ACONST_NULL);
    // desc = desc.substring(0, desc.indexOf(")")) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + Type.getReturnType(desc).getDescriptor();
    // } else
    // name = name + "$$INVIVO_UNINST";
    // }
    // super.visitMethodInsn(opcode, owner, name, desc);
    // }
    // };
    // }
    // });
    // }
    super.visitEnd();
}
Also used : MultiDTaintedArray(edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArray) FrameNode(org.objectweb.asm.tree.FrameNode) Label(org.objectweb.asm.Label) MultiDTaintedArrayWithIntTag(edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArrayWithIntTag) UninstrumentedTaintSentinel(edu.columbia.cs.psl.phosphor.runtime.UninstrumentedTaintSentinel) MethodVisitor(org.objectweb.asm.MethodVisitor) MethodNode(org.objectweb.asm.tree.MethodNode) MultiDTaintedArrayWithObjTag(edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArrayWithObjTag) FieldNode(org.objectweb.asm.tree.FieldNode) Method(java.lang.reflect.Method) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode) Type(org.objectweb.asm.Type) NeverNullArgAnalyzerAdapter(edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Aggregations

FrameNode (org.objectweb.asm.tree.FrameNode)25 Label (org.objectweb.asm.Label)15 Type (org.objectweb.asm.Type)15 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)7 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)6 TaintUtils (edu.columbia.cs.psl.phosphor.TaintUtils)5 OffsetPreservingLabel (edu.columbia.cs.psl.phosphor.instrumenter.asm.OffsetPreservingLabel)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)5 InsnNode (org.objectweb.asm.tree.InsnNode)5 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)5 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)5 LabelNode (org.objectweb.asm.tree.LabelNode)4 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)4 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)3 MethodNode (org.objectweb.asm.tree.MethodNode)3 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)2 ReflectionMasker (edu.columbia.cs.psl.phosphor.runtime.ReflectionMasker)2 TaintSentinel (edu.columbia.cs.psl.phosphor.runtime.TaintSentinel)2 UninstrumentedTaintSentinel (edu.columbia.cs.psl.phosphor.runtime.UninstrumentedTaintSentinel)2 MultiDTaintedArray (edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArray)2