From 819e8b92a060a79b63fcdbd2d614786d758bfefb Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Mon, 22 Feb 2010 07:01:40 +0000 Subject: [PATCH] Allow multiple class path directories to be specified git-svn-id: https://smali.googlecode.com/svn/trunk@639 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../main/java/org/jf/baksmali/baksmali.java | 4 +- .../java/org/jf/baksmali/deodexCheck.java | 21 +++++--- .../src/main/java/org/jf/baksmali/main.java | 14 ++++-- .../jf/dexlib/Code/Analysis/ClassPath.java | 48 ++++++++++--------- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/baksmali.java b/baksmali/src/main/java/org/jf/baksmali/baksmali.java index 06005a29..0a6ea998 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 String bootClassPath; public static void disassembleDexFile(DexFile dexFile, boolean deodex, String outputDirectory, - String bootClassPathDir, String bootClassPath, boolean noParameterRegisters, + String[] classPathDirs, String bootClassPath, boolean noParameterRegisters, boolean useLocalsDirective, boolean useSequentialLabels, boolean outputDebugInfo, boolean addCodeOffsets, int registerInfo) { @@ -65,7 +65,7 @@ public class baksmali { if (registerInfo != 0 || deodex) { try { - ClassPath.InitializeClassPath(bootClassPathDir, bootClassPath==null?null:bootClassPath.split(":"), dexFile); + ClassPath.InitializeClassPath(classPathDirs, bootClassPath==null?null:bootClassPath.split(":"), dexFile); } catch (Exception ex) { System.err.println("\n\nError occured while loading boot class path files. Aborting."); ex.printStackTrace(System.err); diff --git a/baksmali/src/main/java/org/jf/baksmali/deodexCheck.java b/baksmali/src/main/java/org/jf/baksmali/deodexCheck.java index a19a1640..b2a27399 100644 --- a/baksmali/src/main/java/org/jf/baksmali/deodexCheck.java +++ b/baksmali/src/main/java/org/jf/baksmali/deodexCheck.java @@ -3,6 +3,9 @@ package org.jf.baksmali; import org.apache.commons.cli.*; import org.jf.dexlib.Code.Analysis.ClassPath; +import java.util.ArrayList; +import java.util.List; + public class deodexCheck { public static void main(String[] args) { CommandLineParser parser = new PosixParser(); @@ -18,7 +21,8 @@ public class deodexCheck { } String bootClassPath = "core.jar:ext.jar:framework.jar:android.policy.jar:services.jar"; - String bootClassPathDir = "."; + List bootClassPathDirs = new ArrayList(); + bootClassPathDirs.add("."); String deodexerantHost = null; int deodexerantPort = 0; int classStartIndex = 0; @@ -59,8 +63,8 @@ public class deodexCheck { } } - if (commandLine.hasOption("C")) { - bootClassPathDir = commandLine.getOptionValue("C"); + if (commandLine.hasOption("d")) { + bootClassPathDirs.add(commandLine.getOptionValue("d")); } if (commandLine.hasOption("x")) { @@ -83,7 +87,12 @@ public class deodexCheck { } } - ClassPath.InitializeClassPath(bootClassPathDir, bootClassPath==null?null:bootClassPath.split(":"), null); + String[] bootClassPathDirsArray = new String[bootClassPathDirs.size()]; + for (int i=0; i bootClassPathDirs = new ArrayList(); + bootClassPathDirs.add("."); String[] remainingArgs = commandLine.getArgs(); @@ -136,7 +139,7 @@ public class main { outputDebugInfo = false; break; case 'd': - bootClassPathDir = commandLine.getOptionValue("d"); + bootClassPathDirs.add(option.getValue()); break; case 'f': addCodeOffsets = true; @@ -240,7 +243,12 @@ public class main { } if (disassemble) { - baksmali.disassembleDexFile(dexFile, deodex, outputDirectory, bootClassPathDir, bootClassPath, + String[] bootClassPathDirsArray = new String[bootClassPathDirs.size()]; + for (int i=0; i classDefs; protected ClassDef javaLangObjectClassDef; //Ljava/lang/Object; - public static void InitializeClassPath(String bootClassPathDir, String[] bootClassPath, DexFile dexFile) { + public static void InitializeClassPath(String[] classPathDirs, String[] bootClassPath, DexFile dexFile) { if (theClassPath != null) { throw new ExceptionWithContext("Cannot initialize ClassPath multiple times"); } theClassPath = new ClassPath(); - theClassPath.initClassPath(bootClassPathDir, bootClassPath, dexFile); + theClassPath.initClassPath(classPathDirs, bootClassPath, dexFile); } private ClassPath() { classDefs = new HashMap(); } - private void initClassPath(String bootClassPathDir, String[] bootClassPath, DexFile dexFile) { + private void initClassPath(String[] classPathDirs, String[] bootClassPath, DexFile dexFile) { if (bootClassPath != null) { for (String bootClassPathEntry: bootClassPath) { - loadBootClassPath(bootClassPathDir, bootClassPathEntry); + loadBootClassPath(classPathDirs, bootClassPathEntry); } } @@ -47,26 +47,30 @@ public class ClassPath { } } - private void loadBootClassPath(String bootClassPathDir, String bootClassPathEntry) { - File file = new File(bootClassPathDir, bootClassPathEntry); + private void loadBootClassPath(String[] classPathDirs, String bootClassPathEntry) { + for (String classPathDir: classPathDirs) { + File file = new File(classPathDir, bootClassPathEntry); - if (!file.exists()) { - throw new ExceptionWithContext("ClassPath entry \"" + bootClassPathEntry + "\" does not exist."); + if (!file.exists()) { + continue; + } + + if (!file.canRead()) { + throw new ExceptionWithContext("Cannot read ClassPath entry \"" + bootClassPathEntry + "\"."); + } + + DexFile dexFile; + try { + dexFile = new DexFile(file, false, true); + } catch (Exception ex) { + throw ExceptionWithContext.withContext(ex, "Error while reading boot class path entry \"" + + bootClassPathEntry + "\"."); + } + + loadDexFile(dexFile); + return; } - - if (!file.canRead()) { - throw new ExceptionWithContext("Cannot read ClassPath entry \"" + bootClassPathEntry + "\"."); - } - - DexFile dexFile; - try { - dexFile = new DexFile(file, false, true); - } catch (Exception ex) { - throw ExceptionWithContext.withContext(ex, "Error while reading ClassPath entry \"" + - bootClassPathEntry + "\"."); - } - - loadDexFile(dexFile); + throw new ExceptionWithContext(String.format("Cannot locate boot class path file %s", bootClassPathEntry)); } private void loadDexFile(DexFile dexFile) {