diff --git a/baksmali/src/main/java/org/jf/baksmali/dump.java b/baksmali/src/main/java/org/jf/baksmali/dump.java new file mode 100644 index 00000000..635930f8 --- /dev/null +++ b/baksmali/src/main/java/org/jf/baksmali/dump.java @@ -0,0 +1,76 @@ +/* + * [The "BSD licence"] + * Copyright (c) 2009 Ben Gruver + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.baksmali; + +import org.jf.dexlib.DexFile; +import org.jf.dexlib.util.ByteArrayAnnotatedOutput; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class dump { + + public static void main(String[] args) throws IOException { + + if (args.length < 2) { + throw new UsageException(); + } + + String dexFileName = args[0]; + String outFile = args[1]; + + File dexFileFile = new File(dexFileName); + if (!dexFileFile.exists()) { + System.out.println("Can't find the file " + dexFileFile.toString()); + System.exit(1); + } + + + DexFile dexFile = new DexFile(new File(dexFileName), true); + + ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); + out.enableAnnotations(120, true); + dexFile.writeTo(out); + + out.finishAnnotating(); + + FileWriter writer = null; + try { + writer = new FileWriter(outFile); + out.writeAnnotationsTo(writer); + writer.close(); + }catch (IOException ex) { + if (writer != null) { + writer.close(); + } + throw ex; + } + } +} diff --git a/baksmali/src/main/java/org/jf/baksmali/main.java b/baksmali/src/main/java/org/jf/baksmali/main.java index 17261cc7..bcdfa343 100644 --- a/baksmali/src/main/java/org/jf/baksmali/main.java +++ b/baksmali/src/main/java/org/jf/baksmali/main.java @@ -22,7 +22,7 @@ package org.jf.baksmali; */ public class main { - public static final String VERSION = "0.9"; + public static final String VERSION = "0.91"; private static String USAGE_MESSAGE = @@ -30,6 +30,9 @@ public class main { " java -jar baksmali.jar --disassemble <.dex file> \n" + " disassembles the given dex file into a set of .smali files\n" + " in the given folder\n" + + " java -jar baksmali.jar --dump <.dex file> \n" + + " dumps the given dex file to a single annotated dump file\n" + + " that follows the order and structure of the dex file.\n" + " java -jar baksmali.jar --version\n" + " Print the version of this tool (" + VERSION + ").\n" + @@ -63,6 +66,9 @@ public class main { if (arg.equals("--disassemble")) { baksmali.main(without(args, i)); break; + } else if (arg.equals("--dump")) { + dump.main(without(args, i)); + break; } else if (arg.equals("--version")) { version(); break;