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
This commit is contained in:
JesusFreke@JesusFreke.com
2010-02-15 02:00:58 +00:00
parent 2e2a187734
commit 3f7739cd09
3 changed files with 25 additions and 11 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -17,23 +17,23 @@ public class ClassPath {
private final HashMap<String, ClassDef> 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<String, ClassDef>();
}
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.");