use of org.jf.util.ClassFileNameHandler in project atlas by alibaba.
the class SmaliDiffUtils method buildCode.
public static Set<String> buildCode(File smaliDir, File dexFile, DexDiffInfo info) throws IOException, RecognitionException {
Set<String> classes = new HashSet<String>();
Set<DexBackedClassDef> classDefs = new HashSet<DexBackedClassDef>();
classDefs.addAll(info.getModifiedClasses());
classDefs.addAll(info.getAddedClasses());
final ClassFileNameHandler outFileNameHandler = new ClassFileNameHandler(smaliDir, ".smali");
final ClassFileNameHandler inFileNameHandler = new ClassFileNameHandler(smaliDir, ".smali");
DexBuilder dexBuilder = DexBuilder.makeDexBuilder();
File smaliFile;
String className;
for (DexBackedClassDef classDef : classDefs) {
ApkPatch.currentClassType = classDef.getType();
className = TypeGenUtil.newType(classDef.getType());
AfBakSmali.disassembleClass(classDef, outFileNameHandler, getBuildOption(classDefs, 19), false, false);
smaliFile = inFileNameHandler.getUniqueFilenameForClass(className);
classes.add(className.substring(1, className.length() - 1).replace('/', '.'));
SmaliMod.assembleSmaliFile(smaliFile, dexBuilder, true, true);
}
dexBuilder.writeTo(new FileDataStore(dexFile));
return classes;
}
use of org.jf.util.ClassFileNameHandler in project smali by JesusFreke.
the class Baksmali method disassembleDexFile.
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
//name collisions, then we'll use the same name for each class, if the dex file goes through multiple
//baksmali/smali cycles for some reason. If a class with a colliding name is added or removed, the filenames
//may still change of course
List<? extends ClassDef> classDefs = Ordering.natural().sortedCopy(dexFile.getClasses());
final ClassFileNameHandler fileNameHandler = new ClassFileNameHandler(outputDir, ".smali");
ExecutorService executor = Executors.newFixedThreadPool(jobs);
List<Future<Boolean>> tasks = Lists.newArrayList();
Set<String> classSet = null;
if (classes != null) {
classSet = new HashSet<String>(classes);
}
for (final ClassDef classDef : classDefs) {
if (classSet != null && !classSet.contains(classDef.getType())) {
continue;
}
tasks.add(executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return 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