use of org.jf.baksmali.baksmaliOptions in project atlas by alibaba.
the class SmaliUtils method disassembleDexFile.
/**
* 将dex文件转换为smali文件
* @param dex
* @param outputDir
* @param includeClasses 需要做过滤的文件
*/
public static boolean disassembleDexFile(File dex, File outputDir, final Set<String> includeClasses) throws IOException {
final BaksmaliOptions options = createBaksmaliOptions();
if (!outputDir.exists()) {
outputDir.mkdirs();
}
DexFile dexFile = DexFileFactory.loadDexFile(dex, Opcodes.getDefault());
List<? extends ClassDef> classDefs = Ordering.natural().sortedCopy(dexFile.getClasses());
final ClassFileNameHandler fileNameHandler = new ClassFileNameHandler(outputDir, ".smali");
ExecutorService executor = Executors.newFixedThreadPool(4);
List<Future<Boolean>> tasks = Lists.newArrayList();
Set<String> classSet = null;
if (includeClasses != null) {
classSet = new HashSet<String>(includeClasses);
}
for (final ClassDef classDef : classDefs) {
String className = getDalvikClassName(classDef.getType());
if (classSet != null && !classSet.contains(className)) {
continue;
}
tasks.add(executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return BakSmali.disassembleClass(classDef, fileNameHandler, options);
}
}));
}
boolean errorOccurred = false;
try {
for (Future<Boolean> task : tasks) {
while (true) {
try {
if (!task.get()) {
errorOccurred = true;
}
} catch (InterruptedException ex) {
continue;
} catch (ExecutionException ex) {
throw new RuntimeException(ex);
}
break;
}
}
} finally {
executor.shutdown();
}
return !errorOccurred;
}
Aggregations