Package org.objectweb.asm.util

Examples of org.objectweb.asm.util.CheckClassAdapter


      ClassClassification classification = context.classify(classfileBuffer);
      ClassReader cr = new ClassReader(classfileBuffer);
      ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
      ClassVisitor cv = cw;
      //cv = new TraceClassVisitor(cv, new PrintWriter(System.err));
      cv = new CheckClassAdapter(cv, false);
      switch (classification) {
        case RESOURCE:
          // Transform checked classes
          cv = new ResourceClassVisitor(cv, context);
          break;
View Full Code Here


          ClassClassification classification = context.classify(buffer);
          ClassReader cr = new ClassReader(buffer);
          ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
          ClassVisitor cv = cw;
          //cv = new TraceClassVisitor(cv, new PrintWriter(System.err));
          cv = new CheckClassAdapter(cv, false);
          switch (classification) {
            case RESOURCE:
              // Transform checked classes
              cv = new ResourceClassVisitor(cv, context);
              break;
View Full Code Here

            if (name.startsWith("com.sun.tools.javac.")) {
                final InputStream classStream = getResourceAsStream(name.replace('.', '/') + ".class");

                final ClassWriter renamedCw = new ClassWriter(true, false);
                new ClassReader(classStream).accept(new RenamingVisitor(new CheckClassAdapter(renamedCw), new ResourceRenamer() {
                    public String getNewNameFor(final String pOldName) {
                        if (pOldName.startsWith(FileOutputStream.class.getName())) {
                            return FileOutputStreamProxy.class.getName();
                        }
                        if (pOldName.startsWith(FileInputStream.class.getName())) {
View Full Code Here

    Exception e = null;
    String error = "";

    try {
      ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
      ClassVisitor cv = new CheckClassAdapter(cw, true);
      node.accept(cv);

      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), false, pw);
View Full Code Here


  private static final void check(byte[] b) {
    ClassReader cr = new ClassReader(b);
    ClassWriter cw = writer();
    ClassVisitor cv = new CheckClassAdapter(cw);
    cr.accept(cv, 0);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), false, pw);
View Full Code Here

    }

    private byte[] instrumentClass(String className, ClassReader r) {
        log(LogLevel.INFO, "TRANSFORM: %s %s", className, (db.getClassEntry(className) != null && db.getClassEntry(className).requiresInstrumentation()) ? "request" : "");
        final ClassWriter cw = new DBClassWriter(db, r);
        ClassVisitor cv = (check && EXAMINED_CLASS == null) ? new CheckClassAdapter(cw) : cw;

        if (EXAMINED_CLASS != null && className.startsWith(EXAMINED_CLASS))
            cv = new TraceClassVisitor(cv, new PrintWriter(System.out));

        final InstrumentClass ic = new InstrumentClass(cv, db, false);
        byte[] transformed = null;
        try {
            r.accept(ic, ClassReader.SKIP_FRAMES);
            transformed = cw.toByteArray();
        } catch (Exception e) {
            if (ic.hasSuspendableMethods()) {
                error("Unable to instrument class " + className, e);
                throw e;
            } else {
                if (!MethodDatabase.isProblematicClass(className))
                    log(LogLevel.DEBUG, "Unable to instrument class " + className);
                return null;
            }
        }

        if (EXAMINED_CLASS != null) {
            if (className.startsWith(EXAMINED_CLASS)) {
                try (OutputStream os = new FileOutputStream(className.replace('/', '.') + ".class")) {
                    os.write(transformed);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            if (check) {
                ClassReader r2 = new ClassReader(transformed);
                ClassVisitor cv2 = new CheckClassAdapter(new TraceClassVisitor(null), true);
                r2.accept(cv2, 0);
            }
        }

        return transformed;
View Full Code Here

      ClassClassification classification = context.classify(classfileBuffer);
      ClassReader cr = new ClassReader(classfileBuffer);
      ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
      ClassVisitor cv = cw;
      //cv = new TraceClassVisitor(cv, new PrintWriter(System.err));
      cv = new CheckClassAdapter(cv, false);
      switch (classification) {
        case RESOURCE:
          // Transform checked classes
          cv = new ResourceClassVisitor(cv, context);
          break;
View Full Code Here

          ClassClassification classification = context.classify(buffer);
          ClassReader cr = new ClassReader(buffer);
          ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
          ClassVisitor cv = cw;
          //cv = new TraceClassVisitor(cv, new PrintWriter(System.err));
          cv = new CheckClassAdapter(cv, false);
          switch (classification) {
            case RESOURCE:
              // Transform checked classes
              cv = new ResourceClassVisitor(cv, context);
              break;
View Full Code Here

        ClassNode ca = new ClassNode() {
            public void visitEnd() {
                //accept(cv);
            }
        };
        cr.accept(new CheckClassAdapter(ca), ClassWriter.COMPUTE_MAXS);
        boolean failed = false;

        List methods = ca.methods;
        for (int i = 0; i < methods.size(); ++i) {
            MethodNode method = (MethodNode) methods.get(i);
View Full Code Here

    }

    private byte[] instrumentClass(String className, ClassReader r) {
        log(LogLevel.INFO, "TRANSFORM: %s %s", className, (db.getClassEntry(className) != null && db.getClassEntry(className).requiresInstrumentation()) ? "request" : "");
        final ClassWriter cw = new DBClassWriter(db, r);
        ClassVisitor cv = (check && EXAMINED_CLASS == null) ? new CheckClassAdapter(cw) : cw;

        if (EXAMINED_CLASS != null && className.startsWith(EXAMINED_CLASS))
            cv = new TraceClassVisitor(cv, new PrintWriter(System.out));

        final InstrumentClass ic = new InstrumentClass(cv, db, false);
        byte[] transformed = null;
        try {
            r.accept(ic, ClassReader.SKIP_FRAMES);
            transformed = cw.toByteArray();
        } catch (Exception e) {
            if (ic.hasSuspendableMethods()) {
                error("Unable to instrument class " + className, e);
                throw e;
            } else {
                if (!MethodDatabase.isProblematicClass(className))
                    log(LogLevel.DEBUG, "Unable to instrument class " + className);
                return null;
            }
        }

        if (EXAMINED_CLASS != null) {
            if (className.startsWith(EXAMINED_CLASS)) {
                try (OutputStream os = new FileOutputStream(className.replace('/', '.') + ".class")) {
                    os.write(transformed);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            if (check) {
                ClassReader r2 = new ClassReader(transformed);
                ClassVisitor cv2 = new CheckClassAdapter(new TraceClassVisitor(null), true);
                r2.accept(cv2, 0);
            }
        }

        return transformed;
View Full Code Here

TOP

Related Classes of org.objectweb.asm.util.CheckClassAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.