Add AnalysisArguments.loadClassPathForDexFile

This commit is contained in:
Ben Gruver 2016-09-18 11:23:26 -07:00
parent 7e8afc4d8a
commit fb10b5731c
4 changed files with 20 additions and 17 deletions

View File

@ -33,9 +33,13 @@ package org.jf.baksmali;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.iface.DexFile;
import org.jf.util.jcommander.ColonParameterSplitter; import org.jf.util.jcommander.ColonParameterSplitter;
import org.jf.util.jcommander.ExtendedParameter; import org.jf.util.jcommander.ExtendedParameter;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.List; import java.util.List;
public class AnalysisArguments { public class AnalysisArguments {
@ -45,17 +49,17 @@ public class AnalysisArguments {
public int apiLevel = 15; public int apiLevel = 15;
@Parameter(names = {"-b", "--bootclasspath", "--bcp"}, @Parameter(names = {"-b", "--bootclasspath", "--bcp"},
description = "A colon separated list of the jar/oat files to include in the " + description = "A colon separated list of the files to include in the bootclasspath when analyzing the dex " +
"bootclasspath when analyzing the dex file. If not specified, baksmali will attempt to choose an " + "file. If not specified, baksmali will attempt to choose an " +
"appropriate default. This is analogous to Android's BOOTCLASSPATH environment variable.", "appropriate default. When analyzing oat files, this can simply be the path to the device's " +
"boot.oat file. See baksmali help classpath for more information.",
splitter = ColonParameterSplitter.class) splitter = ColonParameterSplitter.class)
@ExtendedParameter(argumentNames = "classpath") @ExtendedParameter(argumentNames = "classpath")
public List<String> bootClassPath = null; public List<String> bootClassPath = null;
@Parameter(names = {"-c", "--classpath", "--cp"}, @Parameter(names = {"-c", "--classpath", "--cp"},
description = "A colon separated list of additional jar/oat files to include in the classpath " + description = "A colon separated list of additional files to include in the classpath when analyzing the " +
"when analyzing the dex file. These will be added to the classpath after any bootclasspath " + "dex file. These will be added to the classpath after any bootclasspath entries.",
"entries.",
splitter = ColonParameterSplitter.class) splitter = ColonParameterSplitter.class)
@ExtendedParameter(argumentNames = "classpath") @ExtendedParameter(argumentNames = "classpath")
public List<String> classPath = Lists.newArrayList(); public List<String> classPath = Lists.newArrayList();
@ -72,4 +76,10 @@ public class AnalysisArguments {
"only be needed for 4.2.0 odexes. It was reverted in 4.2.1.") "only be needed for 4.2.0 odexes. It was reverted in 4.2.1.")
public boolean checkPackagePrivateAccess = false; public boolean checkPackagePrivateAccess = false;
} }
public ClassPath loadClassPathForDexFile(@Nonnull DexFile dexFile, boolean checkPackagePrivateAccess)
throws IOException {
return ClassPath.loadClassPath(classPathDirectories, bootClassPath, classPath, dexFile, apiLevel,
checkPackagePrivateAccess);
}
} }

View File

@ -38,7 +38,6 @@ import com.beust.jcommander.ParametersDelegate;
import com.beust.jcommander.validators.PositiveInteger; import com.beust.jcommander.validators.PositiveInteger;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.dexbacked.DexBackedDexFile; import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.iface.DexFile; import org.jf.dexlib2.iface.DexFile;
import org.jf.dexlib2.util.SyntheticAccessorResolver; import org.jf.dexlib2.util.SyntheticAccessorResolver;
@ -191,9 +190,8 @@ public class DisassembleCommand extends DexInputCommand {
if (needsClassPath()) { if (needsClassPath()) {
try { try {
options.classPath = ClassPath.loadClassPath(analysisArguments.classPathDirectories, options.classPath = analysisArguments.loadClassPathForDexFile(dexFile,
analysisArguments.bootClassPath, analysisArguments.classPath, dexFile, shouldCheckPackagePrivateAccess());
analysisArguments.apiLevel, shouldCheckPackagePrivateAccess());
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("\n\nError occurred while loading class path files. Aborting."); System.err.println("\n\nError occurred while loading class path files. Aborting.");
ex.printStackTrace(System.err); ex.printStackTrace(System.err);

View File

@ -35,7 +35,6 @@ import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate; import com.beust.jcommander.ParametersDelegate;
import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.analysis.ClassProto; import org.jf.dexlib2.analysis.ClassProto;
import org.jf.dexlib2.dexbacked.DexBackedDexFile; import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.iface.ClassDef; import org.jf.dexlib2.iface.ClassDef;
@ -106,9 +105,7 @@ public class ListFieldOffsetsCommand extends DexInputCommand {
options.apiLevel = analysisArguments.apiLevel; options.apiLevel = analysisArguments.apiLevel;
try { try {
options.classPath = ClassPath.loadClassPath(analysisArguments.classPathDirectories, options.classPath = analysisArguments.loadClassPathForDexFile(dexFile, false);
analysisArguments.bootClassPath, analysisArguments.classPath, dexFile, analysisArguments.apiLevel,
false);
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("Error occurred while loading class path files."); System.err.println("Error occurred while loading class path files.");
ex.printStackTrace(System.err); ex.printStackTrace(System.err);

View File

@ -36,7 +36,6 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate; import com.beust.jcommander.ParametersDelegate;
import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument; import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument;
import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.analysis.ClassProto; import org.jf.dexlib2.analysis.ClassProto;
import org.jf.dexlib2.dexbacked.DexBackedDexFile; import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.iface.ClassDef; import org.jf.dexlib2.iface.ClassDef;
@ -134,8 +133,7 @@ public class ListVtablesCommand extends DexInputCommand {
options.apiLevel = analysisArguments.apiLevel; options.apiLevel = analysisArguments.apiLevel;
try { try {
options.classPath = ClassPath.loadClassPath(analysisArguments.classPathDirectories, options.classPath = analysisArguments.loadClassPathForDexFile(dexFile,
analysisArguments.bootClassPath, analysisArguments.classPath, dexFile, analysisArguments.apiLevel,
checkPackagePrivateArgument.checkPackagePrivateAccess); checkPackagePrivateArgument.checkPackagePrivateAccess);
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("Error occurred while loading class path files."); System.err.println("Error occurred while loading class path files.");