protected void checkTrace(String expected) throws IOException { org.objectweb.asm.ClassReader cr = new org.objectweb.asm.ClassReader(traceCode); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(cr, false, pw); if (sw.toString().contains("AnalyzerException")) { System.err.println(sw.toString()); fail(); } }
StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(cr, true, pw); if (sw.toString().contains("AnalyzerException")) { System.err.println(sw.toString());
private void verifyMutant(final Mutant mutant) { // printMutant(mutant); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(mutant.getBytes()), false, pw); assertTrue(sw.toString(), sw.toString().length() == 0); }
private void assertValidClass(final Class<?> clazz) throws IllegalClassFormatException { final byte[] bs = transform(clazz); // printClass(bs); final StringWriter sw = new StringWriter(); CheckClassAdapter.verify(new ClassReader(bs), false, new PrintWriter(sw)); assertTrue(sw.toString(), sw.toString().length() == 0); }
/** * Checks the given class. * * @param classReader the class to be checked. * @param printResults whether to print the results of the bytecode verification. * @param printWriter where the results (or the stack trace in case of error) must be printed. */ public static void verify( final ClassReader classReader, final boolean printResults, final PrintWriter printWriter) { verify(classReader, null, printResults, printWriter); }
/** * Checks the given class. * * @param classReader the class to be checked. * @param printResults whether to print the results of the bytecode verification. * @param printWriter where the results (or the stack trace in case of error) must be printed. */ public static void verify( final ClassReader classReader, final boolean printResults, final PrintWriter printWriter) { verify(classReader, null, printResults, printWriter); }
/** * Checks a given class * * @param cr * a <code>ClassReader</code> that contains bytecode for the * analysis. * @param dump * true if bytecode should be printed out not only when errors * are found. * @param pw * write where results going to be printed */ public static void verify(final ClassReader cr, final boolean dump, final PrintWriter pw) { verify(cr, null, dump, pw); }
public static String verifyClass(ClassWriter writer) { StringWriter sw = new StringWriter(); PrintWriter printer = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(writer.toByteArray()), false, printer); return sw.toString(); }
public static String verifyClass(ClassWriter writer) { StringWriter sw = new StringWriter(); PrintWriter printer = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(writer.toByteArray()), false, printer); return sw.toString(); }
public static String verifyClass(ClassWriter writer) { StringWriter sw = new StringWriter(); PrintWriter printer = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(writer.toByteArray()), false, printer); return sw.toString(); }
private boolean verifyClass(String className, byte[] transformed) { boolean result = true; if (configuration.isVerifyClasses()) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(transformed), false, pw); if (sw.toString().length() != 0) { result = false; LOG.error(" Failed to transform class: " + className); LOG.error(sw.toString()); } } return result; } }
private void validateClass(ClassReader reader, ClassLoader loader) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); Exception error = null; try { CheckClassAdapter.verify(reader, loader, false, printWriter); } catch (Exception e) { error = e; } String contents = writer.toString(); if (error != null || contents.length() > 0) { reader.accept(new TraceClassVisitor(printWriter), 0); throw new IllegalStateException(writer.toString(), error); } }
/** * Checks the given class. * * <p>Usage: CheckClassAdapter <binary class name or class file name> * * @param args the command line arguments. * @throws IOException if the class cannot be found, or if an IO exception occurs. */ public static void main(final String[] args) throws IOException { if (args.length != 1) { System.err.println( "Verifies the given class.\n" + "Usage: CheckClassAdapter <fully qualified class name or class file name>"); return; } ClassReader classReader; if (args[0].endsWith(".class")) { InputStream inputStream = new FileInputStream(args[0]); // NOPMD(AvoidFileStream): can't fix for 1.5 compatibility classReader = new ClassReader(inputStream); } else { classReader = new ClassReader(args[0]); } verify(classReader, false, new PrintWriter(System.err)); }
/** * Checks the given class. * * <p>Usage: CheckClassAdapter <binary class name or class file name> * * @param args the command line arguments. * @throws IOException if the class cannot be found, or if an IO exception occurs. */ public static void main(final String[] args) throws IOException { if (args.length != 1) { System.err.println( "Verifies the given class.\n" + "Usage: CheckClassAdapter <fully qualified class name or class file name>"); return; } ClassReader classReader; if (args[0].endsWith(".class")) { InputStream inputStream = new FileInputStream(args[0]); // NOPMD(AvoidFileStream): can't fix for 1.5 compatibility classReader = new ClassReader(inputStream); } else { classReader = new ClassReader(args[0]); } verify(classReader, false, new PrintWriter(System.err)); }
/** * See {@link org.objectweb.asm.util.CheckClassAdapter#verify(ClassReader, boolean, PrintWriter)}. */ public static void verify(final ClassReader cr, final boolean dump, final PrintWriter pw) { /* * For plain verification, we don't need to restore the original access * bytes the way we do when the check adapter is used as part of a chain, so * we can just strip it and use the ASM version directly. */ final ClassWriter classWriter = new ClassWriter(0); cr.accept(new InnerClassAccessStripper(CompilationConfig.ASM_API_VERSION, classWriter), ClassReader.SKIP_DEBUG); final ClassReader strippedCr = new ClassReader(classWriter.toByteArray()); CheckClassAdapter.verify(strippedCr, dump, pw); } }
private void writeClass(String classname, File destination, ClassWriter writer) throws IOException { String fullname = classname + ".class"; String filename = null; String path = null; // verify the class byte[] bytecode = writer.toByteArray(); CheckClassAdapter.verify(new ClassReader(bytecode), false, new PrintWriter(System.err)); if (fullname.lastIndexOf("/") == -1) { filename = fullname; path = ""; } else { filename = fullname.substring(fullname.lastIndexOf("/") + 1); path = fullname.substring(0, fullname.lastIndexOf("/")); } // create dir if necessary File pathfile = new File(destination, path); pathfile.mkdirs(); FileOutputStream out = new FileOutputStream(new File(pathfile, filename)); out.write(bytecode); out.close(); }
/** * Checks a given class. * <p> * Usage: CheckClassAdapter <binary class name or class file name> * * @param args * the command line arguments. * * @throws Exception * if the class cannot be found, or if an IO exception occurs. */ public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Verifies the given class."); System.err.println("Usage: CheckClassAdapter " + "<fully qualified class name or class file name>"); return; } ClassReader cr; if (args[0].endsWith(".class")) { cr = new ClassReader(new FileInputStream(args[0])); } else { cr = new ClassReader(args[0]); } verify(cr, false, new PrintWriter(System.err)); }
public byte[] treeAPITransform(ClassReader cr) { ClassNode cn = new ClassNode(); cr.accept(cn, ClassReader.SKIP_FRAMES); transformClassNode(cn); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cn.accept(cw); if (do_verify) { //note that it will affect the class loading StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), false, pw); TestCase.assertTrue(sw.toString(), sw.toString().length() == 0); } return cw.toByteArray(); }
/** * Verify the given bytecode (in the form of a byte array) using ASM's * {@link CheckClassAdapter#verify(ClassReader, boolean, PrintWriter)} * method. * * @param bytecode * the bytecode to verify * @throws BytecodeGenerationException * if the bytecode verification fails */ public static void verify(byte[] bytecode) { if(Boolean.getBoolean("org.objectweb.fractal.bf.proxies.verify-bytecode")) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); CheckClassAdapter.verify(new ClassReader(bytecode), false, pw); String cause = sw.toString(); if (cause.length() > 0) { throw new BytecodeGenerationException( "The generated bytecode is not valid: \n" + cause); } } } }
CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), false, pw); System.err.println(sw.toString());