Search in sources :

Example 6 with Analyzer

use of org.objectweb.asm.tree.analysis.Analyzer in project dex2jar by pxb1988.

the class AsmVerify method doCommandLine.

@Override
protected void doCommandLine() throws Exception {
    if (remainingArgs.length < 1) {
        usage();
        return;
    }
    List<Path> files = new ArrayList<>();
    for (String fn : remainingArgs) {
        Path file = new File(fn).toPath();
        if (!Files.exists(file)) {
            System.err.println(fn + " is not exists");
            usage();
            return;
        }
        files.add(file);
    }
    for (Path file : files) {
        System.out.println("verify " + file);
        walkJarOrDir(file, new FileVisitorX() {

            @Override
            public void visitFile(Path file, String relative) throws IOException {
                if (file.getFileName().toString().endsWith(".class")) {
                    ClassReader cr = new ClassReader(Files.readAllBytes(file));
                    ClassNode cn = new ClassNode();
                    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES | ClassReader.SKIP_FRAMES);
                    for (MethodNode method : cn.methods) {
                        BasicVerifier verifier = new BasicVerifier();
                        Analyzer<BasicValue> a = new Analyzer<>(verifier);
                        try {
                            a.analyze(cn.name, method);
                        } catch (Exception ex) {
                            System.err.println("Error verify method " + cr.getClassName() + "." + method.name + " " + method.desc);
                            if (detail) {
                                ex.printStackTrace(System.err);
                                printAnalyzerResult(method, a, new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8)));
                            }
                        }
                    }
                }
            }
        });
    }
}
Also used : Path(java.nio.file.Path) BasicVerifier(org.objectweb.asm.tree.analysis.BasicVerifier) ClassNode(org.objectweb.asm.tree.ClassNode) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Analyzer(org.objectweb.asm.tree.analysis.Analyzer) IOException(java.io.IOException) MethodNode(org.objectweb.asm.tree.MethodNode) CheckClassAdapter(org.objectweb.asm.util.CheckClassAdapter) ClassReader(org.objectweb.asm.ClassReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

MethodNode (org.objectweb.asm.tree.MethodNode)6 Analyzer (org.objectweb.asm.tree.analysis.Analyzer)6 ClassNode (org.objectweb.asm.tree.ClassNode)5 IOException (java.io.IOException)4 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)4 List (java.util.List)3 ClassReader (org.objectweb.asm.ClassReader)3 SimpleVerifier (org.objectweb.asm.tree.analysis.SimpleVerifier)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 BuildException (org.apache.tools.ant.BuildException)2 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)2 BasicVerifier (org.objectweb.asm.tree.analysis.BasicVerifier)2 Frame (org.objectweb.asm.tree.analysis.Frame)2 TraceMethodVisitor (org.objectweb.asm.util.TraceMethodVisitor)2 DexException (com.googlecode.d2j.DexException)1 DexClassNode (com.googlecode.d2j.node.DexClassNode)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1