Mercurial > hg > icedrobot > daneel
changeset 116:8ae57ade33c4
Add a new tool VerifierTheWorld that takes a dex and verifies each method of each class
author | forax |
---|---|
date | Mon, 04 Apr 2011 18:57:42 +0200 |
parents | b880d6db5210 |
children | b375045a6197 |
files | src/main/java/org/icedrobot/daneel/loader/Verifier.java src/main/java/org/icedrobot/daneel/tools/VerifyTheWorld.java |
diffstat | 2 files changed, 48 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/icedrobot/daneel/loader/Verifier.java Mon Apr 04 18:54:11 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/loader/Verifier.java Mon Apr 04 18:57:42 2011 +0200 @@ -72,7 +72,6 @@ import java.io.PrintWriter; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -97,11 +96,10 @@ import org.objectweb.asm.tree.analysis.Analyzer; import org.objectweb.asm.tree.analysis.BasicVerifier; import org.objectweb.asm.tree.analysis.Frame; -import org.objectweb.asm.tree.analysis.SimpleVerifier; import org.objectweb.asm.util.CheckClassAdapter; import org.objectweb.asm.util.TraceMethodVisitor; -class Verifier { +public class Verifier { public static void verify(ClassLoader classloader, DexFile dexFile, String className, byte[] bytecode, PrintWriter writer) { ClassReader reader = new ClassReader(bytecode); ClassNode node = new ClassNode();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/icedrobot/daneel/tools/VerifyTheWorld.java Mon Apr 04 18:57:42 2011 +0200 @@ -0,0 +1,47 @@ +package org.icedrobot.daneel.tools; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + +import org.icedrobot.daneel.dex.DexClassVisitor; +import org.icedrobot.daneel.dex.DexFile; +import org.icedrobot.daneel.dex.DexFileVisitor; +import org.icedrobot.daneel.dex.DexReader; +import org.icedrobot.daneel.loader.Verifier; +import org.icedrobot.daneel.rewriter.DexRewriter; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; + +public class VerifyTheWorld { + // java org.icedrobot.daneel.loader.VerifyTheWorld myfile.dex + public static void main(String[] args) throws IOException { + final PrintWriter printWriter = new PrintWriter(System.err); + final ClassLoader classloader = VerifyTheWorld.class.getClassLoader(); + + final DexFile dexFile = DexFile.parse(new File(args[0])); + + dexFile.accept(new DexFileVisitor() { + @Override + public DexClassVisitor visitClass(final String name) { + final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); + + return new DexRewriter(writer) { + @Override + public void visitEnd() { + super.visitEnd(); + + byte[] byteArray = writer.toByteArray(); + final String className = Type.getType(name).getInternalName().replace('/', '.'); + Verifier.verify(classloader, dexFile, className, byteArray, printWriter); + } + }; + } + + @Override + public void visitEnd() { + // do nothing + } + }, DexReader.SKIP_NONE); + } +}