private ClassNode loadClass(String name) { return Try.apply(() -> { String cname = name.replace("/", "."); ClassNode node = cache.get(cname); if (node == null) { String rname = cname.replace(".", "/") + ".class"; try (InputStream in = loader.getResourceAsStream(rname)) { if (in == null) { throw new FileNotFoundException(rname + " using " + loader); } ClassReader reader = new ClassReader(ByteStreams.toByteArray(in)); node = new ClassNode(); reader.accept(node, 0); cache.put(cname, node); if (log.isDebugEnabled()) { log.info("Source: {}; Class: {}", node.sourceFile, node.name); reader.accept( new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer(log, name))), 0); } } } return node; }).get(); }
@Override public String toString() { Printer printer = new ASMifier(); TraceMethodVisitor visitor = new TraceMethodVisitor(printer); node.accept(visitor); return printer.getText().toString(); }
protected void printClass(final byte[] bs) { final ClassReader reader = new ClassReader(bs); reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter( System.out)), ClassReader.EXPAND_FRAMES); }
protected void printMutant(final Mutant mutant) { final ClassReader reader = new ClassReader(mutant.getBytes()); reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter( System.out)), ClassReader.EXPAND_FRAMES); }
/** * Constructs a new {@link ASMifier}. * * @param visitorVariableName the name of the visitor variable in the produced code. * @param annotationVisitorId identifier of the annotation visitor variable in the produced code. * @return a new {@link ASMifier}. */ // DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility). protected ASMifier createASMifier( final String visitorVariableName, final int annotationVisitorId) { return new ASMifier(Opcodes.ASM7, visitorVariableName, annotationVisitorId); }
/** * Constructs a new {@link ASMifier}. * * @param visitorVariableName the name of the visitor variable in the produced code. * @param annotationVisitorId identifier of the annotation visitor variable in the produced code. * @return a new {@link ASMifier}. */ // DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility). protected ASMifier createASMifier( final String visitorVariableName, final int annotationVisitorId) { return new ASMifier(Opcodes.ASM7, visitorVariableName, annotationVisitorId); }
protected ASMifier createASMifier(final String name, final int id) { return new ASMifier(Opcodes.ASM5, name, id); }
package bytecodetests; import java.io.IOException; import java.io.PrintWriter; import org.objectweb.asm.ClassReader; import org.objectweb.asm.util.ASMifier; import org.objectweb.asm.util.TraceClassVisitor; public class BytecodeTests { public static void main(String[] args) throws IOException { new ClassReader(BytecodeTests.class.getResourceAsStream("BytecodeTests.class")) .accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), 0); } }
/** * Prints the ASM source code to generate the given class to the standard output. * * <p>Usage: ASMifier [-debug] <binary class name or class file name> * * @param args the command line arguments. * @throws IOException if the class cannot be found, or if an IOException occurs. */ public static void main(final String[] args) throws IOException { String usage = "Prints the ASM code to generate the given class.\n" + "Usage: ASMifier [-debug] <fully qualified class name or class file name>"; main(usage, new ASMifier(), args); }
/** * Prints the ASM source code to generate the given class to the standard output. * * <p>Usage: ASMifier [-debug] <binary class name or class file name> * * @param args the command line arguments. * @throws IOException if the class cannot be found, or if an IOException occurs. */ public static void main(final String[] args) throws IOException { String usage = "Prints the ASM code to generate the given class.\n" + "Usage: ASMifier [-debug] <fully qualified class name or class file name>"; main(usage, new ASMifier(), args); }
package com.cosmic.evaluate.asm; import java.io.FileInputStream; import java.io.PrintWriter; import org.objectweb.asm.ClassReader; import org.objectweb.asm.util.ASMifier; import org.objectweb.asm.util.TraceClassVisitor; public class TetsMain { public static void main(String[] args) throws Exception { String classPath = "./target/classes/com/cosmic/evaluate/asm/TestClass.class"; int flags = ClassReader.SKIP_DEBUG; ClassReader cr; if (classPath.endsWith(".class") || classPath.indexOf('\\') > -1 || classPath.indexOf('/') > -1) { cr = new ClassReader(new FileInputStream(classPath)); } else { cr = new ClassReader(classPath); } cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), flags); } }
cr = new ClassReader(args[i]); cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter( System.out)), flags);
TraceClassVisitor tcv = new TraceClassVisitor(cw, new ASMifier(), new PrintWriter(System.out));