Search in sources :

Example 11 with ClassReader

use of jdk.internal.org.objectweb.asm.ClassReader in project jdk8u_jdk by JetBrains.

the class Textifier method main.

/**
     * Prints a disassembled view of the given class to the standard output.
     * <p>
     * Usage: Textifier [-debug] &lt;binary class name or class file name &gt;
     *
     * @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 {
    int i = 0;
    int flags = ClassReader.SKIP_DEBUG;
    boolean ok = true;
    if (args.length < 1 || args.length > 2) {
        ok = false;
    }
    if (ok && "-debug".equals(args[0])) {
        i = 1;
        flags = 0;
        if (args.length != 2) {
            ok = false;
        }
    }
    if (!ok) {
        System.err.println("Prints a disassembled view of the given class.");
        System.err.println("Usage: Textifier [-debug] " + "<fully qualified class name or class file name>");
        return;
    }
    ClassReader cr;
    if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1 || args[i].indexOf('/') > -1) {
        cr = new ClassReader(new FileInputStream(args[i]));
    } else {
        cr = new ClassReader(args[i]);
    }
    cr.accept(new TraceClassVisitor(new PrintWriter(System.out)), flags);
}
Also used : ClassReader(jdk.internal.org.objectweb.asm.ClassReader) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Example 12 with ClassReader

use of jdk.internal.org.objectweb.asm.ClassReader in project warn-report by saaavsaaa.

the class AddFieldAdapter method main.

public static void main(String[] args) throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, NoSuchFieldException {
    ClassVisitorTest.changeVersion();
    byte[] data = ResourceUtil.loadFile("ClassCode.class");
    ClassReader cr = new ClassReader(data);
    ClassWriter cw = new ClassWriter(0);
    // cw = deleteField(cr, cw);
    cw = addField(cr, cw);
    cw = ClassMethodVisitor.add(cr, cw);
    byte[] b = cw.toByteArray();
    ResourceUtil.write("ClassCode.class", b);
}
Also used : ClassReader(jdk.internal.org.objectweb.asm.ClassReader) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter)

Example 13 with ClassReader

use of jdk.internal.org.objectweb.asm.ClassReader in project warn-report by saaavsaaa.

the class VisitUtil method display.

public static void display(byte[] data) {
    ClassReader reader = new ClassReader(data);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    CheckClassAdapter.verify(reader, true, pw);
    System.out.println(sw.toString());
}
Also used : StringWriter(java.io.StringWriter) ClassReader(jdk.internal.org.objectweb.asm.ClassReader) PrintWriter(java.io.PrintWriter)

Example 14 with ClassReader

use of jdk.internal.org.objectweb.asm.ClassReader in project warn-report by saaavsaaa.

the class DelegageClassAdapter method main.

public static void main(String[] args) throws IOException {
    ClassNode cn = new ClassNode(ASM5);
    ClassReader cr = new ClassReader("...");
    cr.accept(cn, 0);
    // 可以在这里根据需要转换 cn
    ClassWriter cw = new ClassWriter(0);
    cn.accept(cw);
    byte[] b = cw.toByteArray();
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) ClassReader(jdk.internal.org.objectweb.asm.ClassReader) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter)

Example 15 with ClassReader

use of jdk.internal.org.objectweb.asm.ClassReader in project jdk8u_jdk by JetBrains.

the class ASMifier method main.

/**
     * Prints the ASM source code to generate the given class to the standard
     * output.
     * <p>
     * Usage: ASMifier [-debug] &lt;binary class name or class file name&gt;
     *
     * @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 {
    int i = 0;
    int flags = ClassReader.SKIP_DEBUG;
    boolean ok = true;
    if (args.length < 1 || args.length > 2) {
        ok = false;
    }
    if (ok && "-debug".equals(args[0])) {
        i = 1;
        flags = 0;
        if (args.length != 2) {
            ok = false;
        }
    }
    if (!ok) {
        System.err.println("Prints the ASM code to generate the given class.");
        System.err.println("Usage: ASMifier [-debug] " + "<fully qualified class name or class file name>");
        return;
    }
    ClassReader cr;
    if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1 || args[i].indexOf('/') > -1) {
        cr = new ClassReader(new FileInputStream(args[i]));
    } else {
        cr = new ClassReader(args[i]);
    }
    cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), flags);
}
Also used : ClassReader(jdk.internal.org.objectweb.asm.ClassReader) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Aggregations

ClassReader (jdk.internal.org.objectweb.asm.ClassReader)20 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)9 PrintWriter (java.io.PrintWriter)7 FileInputStream (java.io.FileInputStream)6 ClassVisitor (jdk.internal.org.objectweb.asm.ClassVisitor)5 ClassNode (jdk.internal.org.objectweb.asm.tree.ClassNode)3 Attribute (jdk.internal.org.objectweb.asm.Attribute)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 BuiltinClassLoader (jdk.internal.loader.BuiltinClassLoader)1 AnnotationVisitor (jdk.internal.org.objectweb.asm.AnnotationVisitor)1 FieldVisitor (jdk.internal.org.objectweb.asm.FieldVisitor)1 MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)1