Add a --classes option for disassemble/deodex commands

This commit is contained in:
Ben Gruver 2016-10-16 13:43:34 -07:00
parent 43669ecc6e
commit 22e85fc3ff
2 changed files with 22 additions and 1 deletions

View File

@ -36,12 +36,20 @@ import org.jf.dexlib2.iface.DexFile;
import org.jf.util.ClassFileNameHandler; import org.jf.util.ClassFileNameHandler;
import org.jf.util.IndentingWriter; import org.jf.util.IndentingWriter;
import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.*; import java.util.concurrent.*;
public class Baksmali { public class Baksmali {
public static boolean disassembleDexFile(DexFile dexFile, File outputDir, int jobs, final BaksmaliOptions options) { public static boolean disassembleDexFile(DexFile dexFile, File outputDir, int jobs, final BaksmaliOptions options) {
return disassembleDexFile(dexFile, outputDir, jobs, options, null);
}
public static boolean disassembleDexFile(DexFile dexFile, File outputDir, int jobs, final BaksmaliOptions options,
@Nullable List<String> classes) {
//sort the classes, so that if we're on a case-insensitive file system and need to handle classes with file //sort the classes, so that if we're on a case-insensitive file system and need to handle classes with file
//name collisions, then we'll use the same name for each class, if the dex file goes through multiple //name collisions, then we'll use the same name for each class, if the dex file goes through multiple
@ -54,7 +62,15 @@ public class Baksmali {
ExecutorService executor = Executors.newFixedThreadPool(jobs); ExecutorService executor = Executors.newFixedThreadPool(jobs);
List<Future<Boolean>> tasks = Lists.newArrayList(); List<Future<Boolean>> tasks = Lists.newArrayList();
Set<String> classSet = null;
if (classes != null) {
classSet = new HashSet<String>(classes);
}
for (final ClassDef classDef: classDefs) { for (final ClassDef classDef: classDefs) {
if (classSet != null && !classSet.contains(classDef.getType())) {
continue;
}
tasks.add(executor.submit(new Callable<Boolean>() { tasks.add(executor.submit(new Callable<Boolean>() {
@Override public Boolean call() throws Exception { @Override public Boolean call() throws Exception {
return disassembleClass(classDef, fileNameHandler, options); return disassembleClass(classDef, fileNameHandler, options);

View File

@ -133,6 +133,11 @@ public class DisassembleCommand extends DexInputCommand {
"fields from the current class.") "fields from the current class.")
private boolean implicitReferences = false; private boolean implicitReferences = false;
@Parameter(names = "--classes",
description = "A comma separated list of classes. Only disassemble these classes")
@ExtendedParameter(argumentNames = "classes")
private List<String> classes = null;
public DisassembleCommand(@Nonnull List<JCommander> commandAncestors) { public DisassembleCommand(@Nonnull List<JCommander> commandAncestors) {
super(commandAncestors); super(commandAncestors);
} }
@ -170,7 +175,7 @@ public class DisassembleCommand extends DexInputCommand {
analysisArguments.classPathDirectories = Lists.newArrayList(inputFile.getAbsoluteFile().getParent()); analysisArguments.classPathDirectories = Lists.newArrayList(inputFile.getAbsoluteFile().getParent());
} }
if (!Baksmali.disassembleDexFile(dexFile, outputDirectoryFile, jobs, getOptions())) { if (!Baksmali.disassembleDexFile(dexFile, outputDirectoryFile, jobs, getOptions(), classes)) {
System.exit(-1); System.exit(-1);
} }
} }