Search in sources :

Example 6 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project robolectric by robolectric.

the class SandboxClassLoader method maybeInstrumentClass.

protected Class<?> maybeInstrumentClass(String className) throws ClassNotFoundException {
    final byte[] origClassBytes = getByteCode(className);
    ClassNode classNode = new ClassNode(Opcodes.ASM4) {

        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            desc = remapParamType(desc);
            return super.visitField(access, name, desc, signature, value);
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor methodVisitor = super.visitMethod(access, name, remapParams(desc), signature, exceptions);
            return new JSRInlinerAdapter(methodVisitor, access, name, desc, signature, exceptions);
        }
    };
    final ClassReader classReader = new ClassReader(origClassBytes);
    classReader.accept(classNode, 0);
    classNode.interfaces.add(Type.getInternalName(ShadowedObject.class));
    try {
        byte[] bytes;
        ClassInfo classInfo = new ClassInfo(className, classNode);
        if (config.shouldInstrument(classInfo)) {
            bytes = getInstrumentedBytes(classNode, config.containsStubs(classInfo));
        } else {
            bytes = origClassBytes;
        }
        ensurePackage(className);
        return defineClass(className, bytes, 0, bytes.length);
    } catch (Exception e) {
        throw new ClassNotFoundException("couldn't load " + className, e);
    } catch (OutOfMemoryError e) {
        System.err.println("[ERROR] couldn't load " + className + " in " + this);
        throw e;
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ClassReader(org.objectweb.asm.ClassReader) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) IOException(java.io.IOException) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 7 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project phosphor by gmu-swe.

the class TaintLoadCoercer method main.

public static void main(String[] args) throws Throwable {
    Configuration.IMPLICIT_TRACKING = true;
    Configuration.MULTI_TAINTING = true;
    // Configuration.IMPLICIT_LIGHT_TRACKING = true;
    // Configuration.ARRAY_LENGTH_TRACKING = true;
    Configuration.ARRAY_INDEX_TRACKING = true;
    // Configuration.ANNOTATE_LOOPS = true;
    // Instrumenter.instrumentClass("asdf", new FileInputStream("z.class"), false);
    ClassReader cr = new ClassReader(new FileInputStream("z.class"));
    // ClassReader cr = new ClassReader(new FileInputStream("target/classes/VarInLoop.class"));
    final String className = cr.getClassName();
    PrintWriter pw = new PrintWriter("z.txt");
    TraceClassVisitor tcv = new TraceClassVisitor(null, new PhosphorTextifier(), pw);
    ClassWriter cw1 = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {

        @Override
        protected String getCommonSuperClass(String arg0, String arg1) {
            try {
                return super.getCommonSuperClass(arg0, arg1);
            } catch (Throwable t) {
                return "java/lang/Object";
            }
        }
    };
    cr.accept(new ClassVisitor(Opcodes.ASM5, cw1) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            mv = new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions);
            return mv;
        }
    }, ClassReader.EXPAND_FRAMES);
    cr = new ClassReader(cw1.toByteArray());
    ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, tcv) {

        String className;

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            this.className = name;
        }

        HashSet<FieldNode> fields = new HashSet<FieldNode>();

        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            fields.add(new FieldNode(access, name, desc, signature, value));
            return super.visitField(access, name, desc, signature, value);
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            // TODO Auto-generated method stub
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            mv = new MethodVisitor(Opcodes.ASM5, mv) {

                @Override
                public void visitInsn(int opcode) {
                    super.visitInsn(opcode);
                }
            };
            // mv = new SpecialOpcodeRemovingMV(mv,false,className,false);
            // NeverNullArgAnalyzerAdapter analyzer = new NeverNullArgAnalyzerAdapter(className, access, className, desc, mv);
            mv = new TaintLoadCoercer(className, access, name, desc, signature, exceptions, mv, true);
            // LocalVariableManager lvs = new LocalVariableManager(access, desc, mv, analyzer, mv, false);
            // mv = lvs;
            PrimitiveArrayAnalyzer paa = new PrimitiveArrayAnalyzer(className, access, name, desc, signature, exceptions, mv);
            NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(className, access, name, desc, paa);
            paa.setAnalyzer(an);
            // ((PrimitiveArrayAnalyzer) mv).setAnalyzer(an);
            mv = an;
            return mv;
        }
    };
    cr.accept(cv, ClassReader.EXPAND_FRAMES);
    pw.flush();
}
Also used : FieldNode(org.objectweb.asm.tree.FieldNode) ClassVisitor(org.objectweb.asm.ClassVisitor) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) FileInputStream(java.io.FileInputStream) ClassWriter(org.objectweb.asm.ClassWriter) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) NeverNullArgAnalyzerAdapter(edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter) ClassReader(org.objectweb.asm.ClassReader) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet)

Example 8 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project phosphor by gmu-swe.

the class DebugPrinter method main.

public static void main(String[] args) throws Exception {
    // Configuration.IMPLICIT_TRACKING = true;
    File clazz = new File(args[0]);
    final ClassReader cr1 = new ClassReader(new FileInputStream(clazz));
    PrintWriter pw = new PrintWriter(new FileWriter("z.txt"));
    ClassWriter cw1 = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {

        @Override
        protected String getCommonSuperClass(String type1, String type2) {
            try {
                return super.getCommonSuperClass(type1, type2);
            } catch (Exception ex) {
                // System.err.println("err btwn " + type1 + " " +type2);
                return "java/lang/Unknown";
            }
        }
    };
    cr1.accept(new ClassVisitor(Opcodes.ASM4, cw1) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            // TODO Auto-generated method stub
            return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions);
        }
    }, ClassReader.EXPAND_FRAMES);
    final ClassReader cr = new ClassReader(cw1.toByteArray());
    TraceClassVisitor tcv = new TraceClassVisitor(new ClassVisitor(Opcodes.ASM5, new ClassWriter(0)) {

        String className;

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            this.className = name;
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            // TODO Auto-generated method stub
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            mv = new PrimitiveArrayAnalyzer(cr.getClassName(), access, name, desc, signature, exceptions, mv);
            NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(cr.getClassName(), access, name, desc, mv);
            ((PrimitiveArrayAnalyzer) mv).setAnalyzer(an);
            mv = an;
            return mv;
        }
    }, pw);
    cr.accept(tcv, ClassReader.EXPAND_FRAMES);
    pw.flush();
}
Also used : FileWriter(java.io.FileWriter) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) FileInputStream(java.io.FileInputStream) ClassWriter(org.objectweb.asm.ClassWriter) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor) PrimitiveArrayAnalyzer(edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) NeverNullArgAnalyzerAdapter(edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter) ClassReader(org.objectweb.asm.ClassReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 9 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project evosuite by EvoSuite.

the class NonTargetClassAdapter method visitMethod.

/**
 * {@inheritDoc}
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, final String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access & ~Opcodes.ACC_FINAL, name, desc, signature, exceptions);
    mv = new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions);
    if (!"<clinit>".equals(name))
        mv = new YieldAtLineNumberMethodAdapter(mv, className, name);
    // new ArrayAllocationLimitMethodAdapter(mv, className, name, access, desc);
    return mv;
}
Also used : JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 10 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project evosuite by EvoSuite.

the class CFGClassAdapter method visitMethod.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.objectweb.asm.ClassAdapter#visitMethod(int, java.lang.String,
	 * java.lang.String, java.lang.String, java.lang.String[])
	 */
/**
 * {@inheritDoc}
 */
@Override
public MethodVisitor visitMethod(int methodAccess, String name, String descriptor, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(methodAccess, name, descriptor, signature, exceptions);
    mv = new JSRInlinerAdapter(mv, methodAccess, name, descriptor, signature, exceptions);
    if ((methodAccess & Opcodes.ACC_SYNTHETIC) != 0 || (methodAccess & Opcodes.ACC_BRIDGE) != 0) {
        return mv;
    }
    if (isEnum) {
        if (name.equals("valueOf") || name.equals("values")) {
            logger.info("Skipping enum valueOf");
            return mv;
        }
        if (name.equals("<init>") && descriptor.equals("(Ljava/lang/String;I)V")) {
            logger.info("Skipping enum default constructor");
            return mv;
        }
    }
    logger.info("Analyzing CFG of " + className);
    String classNameWithDots = ResourceList.getClassNameFromResourcePath(className);
    mv = new CFGMethodAdapter(classLoader, classNameWithDots, methodAccess, name, descriptor, signature, exceptions, mv);
    return mv;
}
Also used : JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

JSRInlinerAdapter (org.objectweb.asm.commons.JSRInlinerAdapter)12 MethodVisitor (org.objectweb.asm.MethodVisitor)9 ClassReader (org.objectweb.asm.ClassReader)5 ClassVisitor (org.objectweb.asm.ClassVisitor)3 ClassWriter (org.objectweb.asm.ClassWriter)3 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)2 FileInputStream (java.io.FileInputStream)2 PrintWriter (java.io.PrintWriter)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)2 SuspendableType (co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType)1 PrimitiveArrayAnalyzer (edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FieldNode (org.objectweb.asm.tree.FieldNode)1 LabelNode (org.objectweb.asm.tree.LabelNode)1