Search in sources :

Example 1 with ClassNode

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

the class DelegageClassAdapter method visitEnd.

@Override
public void visitEnd() {
    ClassNode cn = (ClassNode) cv;
    // 将转换代码放在这里
    cn.accept(next);
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode)

Example 2 with ClassNode

use of jdk.internal.org.objectweb.asm.tree.ClassNode in project Bytecoder by mirkosertic.

the class CheckClassAdapter method verify.

/**
 * Checks a given class.
 *
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @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 ClassLoader loader, final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
    Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;
    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext(); ) {
        interfaces.add(Type.getObjectType(i.next()));
    }
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name), syperType, interfaces, (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) SimpleVerifier(jdk.internal.org.objectweb.asm.tree.analysis.SimpleVerifier) ArrayList(java.util.ArrayList) Analyzer(jdk.internal.org.objectweb.asm.tree.analysis.Analyzer) BasicValue(jdk.internal.org.objectweb.asm.tree.analysis.BasicValue) Type(jdk.internal.org.objectweb.asm.Type) MethodNode(jdk.internal.org.objectweb.asm.tree.MethodNode)

Example 3 with ClassNode

use of jdk.internal.org.objectweb.asm.tree.ClassNode in project CorfuDB by CorfuDB.

the class Utils method printByteCode.

public static String printByteCode(byte[] bytes) {
    ClassReader cr = new ClassReader(bytes);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);
    final List<MethodNode> methods = cn.methods;
    StringBuilder sb = new StringBuilder();
    for (MethodNode m : methods) {
        InsnList inList = m.instructions;
        sb.append(m.name);
        for (int i = 0; i < inList.size(); i++) {
            sb.append(insnToString(inList.get(i)));
        }
    }
    return sb.toString();
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) MethodNode(jdk.internal.org.objectweb.asm.tree.MethodNode) ClassReader(jdk.internal.org.objectweb.asm.ClassReader) InsnList(jdk.internal.org.objectweb.asm.tree.InsnList)

Example 4 with ClassNode

use of jdk.internal.org.objectweb.asm.tree.ClassNode 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 5 with ClassNode

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

the class CheckClassAdapter method verify.

/**
     * Checks a given class.
     *
     * @param cr
     *            a <code>ClassReader</code> that contains bytecode for the
     *            analysis.
     * @param loader
     *            a <code>ClassLoader</code> which will be used to load
     *            referenced classes. This is useful if you are verifiying
     *            multiple interdependent classes.
     * @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 ClassLoader loader, final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
    Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;
    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext(); ) {
        interfaces.add(Type.getObjectType(i.next()));
    }
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name), syperType, interfaces, (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) SimpleVerifier(jdk.internal.org.objectweb.asm.tree.analysis.SimpleVerifier) ArrayList(java.util.ArrayList) Analyzer(jdk.internal.org.objectweb.asm.tree.analysis.Analyzer) BasicValue(jdk.internal.org.objectweb.asm.tree.analysis.BasicValue) Type(jdk.internal.org.objectweb.asm.Type) MethodNode(jdk.internal.org.objectweb.asm.tree.MethodNode)

Aggregations

ClassNode (jdk.internal.org.objectweb.asm.tree.ClassNode)7 ClassReader (jdk.internal.org.objectweb.asm.ClassReader)3 MethodNode (jdk.internal.org.objectweb.asm.tree.MethodNode)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 JarEntry (java.util.jar.JarEntry)2 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)2 Type (jdk.internal.org.objectweb.asm.Type)2 Analyzer (jdk.internal.org.objectweb.asm.tree.analysis.Analyzer)2 BasicValue (jdk.internal.org.objectweb.asm.tree.analysis.BasicValue)2 SimpleVerifier (jdk.internal.org.objectweb.asm.tree.analysis.SimpleVerifier)2 URL (java.net.URL)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 JarFile (java.util.jar.JarFile)1 JarOutputStream (java.util.jar.JarOutputStream)1 InsnList (jdk.internal.org.objectweb.asm.tree.InsnList)1 CanvasInjector (os.rs.paint.CanvasInjector)1