From 3f7739cd09932129a51badaca9e172aaa47f50f4 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Mon, 15 Feb 2010 02:00:58 +0000 Subject: [PATCH] Add support for specifying a base dir for the BOOTCLASSPATH files git-svn-id: https://smali.googlecode.com/svn/trunk@629 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../main/java/org/jf/baksmali/baksmali.java | 4 ++-- .../src/main/java/org/jf/baksmali/main.java | 20 ++++++++++++++++--- .../jf/dexlib/Code/Analysis/ClassPath.java | 12 +++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/baksmali.java b/baksmali/src/main/java/org/jf/baksmali/baksmali.java index 4cab033c..4db32b0a 100644 --- a/baksmali/src/main/java/org/jf/baksmali/baksmali.java +++ b/baksmali/src/main/java/org/jf/baksmali/baksmali.java @@ -50,7 +50,7 @@ public class baksmali { public static DeodexUtil deodexUtil = null; public static void disassembleDexFile(DexFile dexFile, Deodexerant deodexerant, String outputDirectory, - String bootClassPath, boolean noParameterRegisters, + String bootClassPathDir, String bootClassPath, boolean noParameterRegisters, boolean useLocalsDirective, boolean useSequentialLabels, boolean outputDebugInfo, int registerInfo) { @@ -62,7 +62,7 @@ public class baksmali { baksmali.bootClassPath = bootClassPath; if (registerInfo != 0) { - ClassPath.InitializeClassPath(bootClassPath==null?null:bootClassPath.split(":"), dexFile); + ClassPath.InitializeClassPath(bootClassPathDir, bootClassPath==null?null:bootClassPath.split(":"), dexFile); } if (deodexerant != null) { diff --git a/baksmali/src/main/java/org/jf/baksmali/main.java b/baksmali/src/main/java/org/jf/baksmali/main.java index 1a19f1ba..7ed2a1cd 100644 --- a/baksmali/src/main/java/org/jf/baksmali/main.java +++ b/baksmali/src/main/java/org/jf/baksmali/main.java @@ -92,6 +92,7 @@ public class main { String inputDexFileName = null; String deodexerantHost = null; String bootClassPath = "core.jar:ext.jar:framework.jar:android.policy.jar:services.jar"; + String bootClassPathDir = "."; int deodexerantPort = 0; String[] remainingArgs = commandLine.getArgs(); @@ -192,6 +193,10 @@ public class main { bootClassPath = commandLine.getOptionValue("c"); } + if (commandLine.hasOption("C")) { + bootClassPathDir = commandLine.getOptionValue("C"); + } + if (commandLine.hasOption("x")) { String deodexerantAddress = commandLine.getOptionValue("x"); String[] parts = deodexerantAddress.split(":"); @@ -247,8 +252,8 @@ public class main { } if (disassemble) { - baksmali.disassembleDexFile(dexFile, deodexerant, outputDirectory, bootClassPath, noParameterRegisters, - useLocalsDirective, useSequentialLabels, outputDebugInfo, registerInfo); + baksmali.disassembleDexFile(dexFile, deodexerant, outputDirectory, bootClassPathDir, bootClassPath, + noParameterRegisters, useLocalsDirective, useSequentialLabels, outputDebugInfo, registerInfo); } if ((doDump || write) && !dexFile.isOdex()) { @@ -373,11 +378,19 @@ public class main { .create("r"); Option classPathOption = OptionBuilder.withLongOpt("bootclasspath") - .withDescription("the bootclasspath jars to use, for analysis") + .withDescription("the bootclasspath jars to use, for analysis. Defaults to " + + "core.jar:ext.jar:framework.jar:android.policy.jar:services.jar") .hasOptionalArg() .withArgName("BOOTCLASSPATH") .create("c"); + Option classPathDirOption = OptionBuilder.withLongOpt("bootclasspath-dir") + .withDescription("the base folder to look for the bootclasspath files in. Defaults to the current " + + "directory") + .hasArg() + .withArgName("DIR") + .create("C"); + options.addOption(versionOption); options.addOption(helpOption); options.addOption(dumpOption); @@ -393,5 +406,6 @@ public class main { options.addOption(noDebugInfoOption); options.addOption(registerInfoOption); options.addOption(classPathOption); + options.addOption(classPathDirOption); } } \ No newline at end of file diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java index f73e0957..2228c40a 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java @@ -17,23 +17,23 @@ public class ClassPath { private final HashMap classDefs; protected ClassDef javaLangObjectClassDef; //Ljava/lang/Object; - public static void InitializeClassPath(String[] bootClassPath, DexFile dexFile) { + public static void InitializeClassPath(String bootClassPathDir, String[] bootClassPath, DexFile dexFile) { if (theClassPath != null) { throw new ExceptionWithContext("Cannot initialize ClassPath multiple times"); } theClassPath = new ClassPath(); - theClassPath.initClassPath(bootClassPath, dexFile); + theClassPath.initClassPath(bootClassPathDir, bootClassPath, dexFile); } private ClassPath() { classDefs = new HashMap(); } - private void initClassPath(String[] bootClassPath, DexFile dexFile) { + private void initClassPath(String bootClassPathDir, String[] bootClassPath, DexFile dexFile) { if (bootClassPath != null) { for (String bootClassPathEntry: bootClassPath) { - loadBootClassPath(bootClassPathEntry); + loadBootClassPath(bootClassPathDir, bootClassPathEntry); } } @@ -45,8 +45,8 @@ public class ClassPath { } } - private void loadBootClassPath(String bootClassPathEntry) { - File file = new File(bootClassPathEntry); + private void loadBootClassPath(String bootClassPathDir, String bootClassPathEntry) { + File file = new File(bootClassPathDir, bootClassPathEntry); if (!file.exists()) { throw new ExceptionWithContext("ClassPath entry \"" + bootClassPathEntry + "\" does not exist.");