Search in sources :

Example 11 with TraceMethodVisitor

use of org.objectweb.asm.util.TraceMethodVisitor in project dex2jar by pxb1988.

the class AsmVerify method printAnalyzerResult.

static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException {
    Frame[] frames = a.getFrames();
    Textifier t = new Textifier();
    TraceMethodVisitor mv = new TraceMethodVisitor(t);
    String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
    for (int j = 0; j < method.instructions.size(); ++j) {
        method.instructions.get(j).accept(mv);
        StringBuffer s = new StringBuffer();
        Frame f = frames[j];
        if (f == null) {
            s.append('?');
        } else {
            for (int k = 0; k < f.getLocals(); ++k) {
                s.append(getShortName(f.getLocal(k).toString()));
            }
            s.append(" : ");
            for (int k = 0; k < f.getStackSize(); ++k) {
                s.append(getShortName(f.getStack(k).toString()));
            }
        }
        try {
            // mv.text.get(j));
            pw.printf(format, j, s, buf.get(t));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    for (TryCatchBlockNode tryCatchBlockNode : method.tryCatchBlocks) {
        tryCatchBlockNode.accept(mv);
        try {
            pw.print(" " + buf.get(t));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    pw.println();
    pw.flush();
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) Frame(org.objectweb.asm.tree.analysis.Frame) Textifier(org.objectweb.asm.util.Textifier) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor)

Aggregations

TraceMethodVisitor (org.objectweb.asm.util.TraceMethodVisitor)11 Textifier (org.objectweb.asm.util.Textifier)8 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)4 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)4 IOException (java.io.IOException)3 ClassReader (org.objectweb.asm.ClassReader)3 ClassNode (org.objectweb.asm.tree.ClassNode)3 MethodNode (org.objectweb.asm.tree.MethodNode)3 Frame (org.objectweb.asm.tree.analysis.Frame)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BuildException (org.apache.tools.ant.BuildException)2 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)2 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1