use of org.jf.dexlib2.writer.io.FileDataStore in project smali by JesusFreke.
the class Smali method assemble.
/**
* Assemble the specified files, using the given options
*
* @param options a SmaliOptions object with the options to run smali with
* @param input The files/directories to process
* @return true if assembly completed with no errors, or false if errors were encountered
*/
public static boolean assemble(final SmaliOptions options, List<String> input) throws IOException {
LinkedHashSet<File> filesToProcessSet = new LinkedHashSet<File>();
for (String fileToProcess : input) {
File argFile = new File(fileToProcess);
if (!argFile.exists()) {
throw new IllegalArgumentException("Cannot find file or directory \"" + fileToProcess + "\"");
}
if (argFile.isDirectory()) {
getSmaliFilesInDir(argFile, filesToProcessSet);
} else if (argFile.isFile()) {
filesToProcessSet.add(argFile);
}
}
boolean errors = false;
final DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(options.apiLevel));
ExecutorService executor = Executors.newFixedThreadPool(options.jobs);
List<Future<Boolean>> tasks = Lists.newArrayList();
for (final File file : filesToProcessSet) {
tasks.add(executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return assembleSmaliFile(file, dexBuilder, options);
}
}));
}
for (Future<Boolean> task : tasks) {
while (true) {
try {
try {
if (!task.get()) {
errors = true;
}
} catch (ExecutionException ex) {
throw new RuntimeException(ex);
}
} catch (InterruptedException ex) {
continue;
}
break;
}
}
executor.shutdown();
if (errors) {
return false;
}
dexBuilder.writeTo(new FileDataStore(new File(options.outputDexFile)));
return true;
}
use of org.jf.dexlib2.writer.io.FileDataStore in project Apktool by iBotPeaches.
the class SmaliBuilder method build.
private void build() throws AndrolibException {
try {
DexBuilder dexBuilder;
if (mApiLevel > 0) {
dexBuilder = DexBuilder.makeDexBuilder(Opcodes.forApi(mApiLevel));
} else {
dexBuilder = DexBuilder.makeDexBuilder();
}
for (String fileName : mSmaliDir.getDirectory().getFiles(true)) {
buildFile(fileName, dexBuilder);
}
dexBuilder.writeTo(new FileDataStore(new File(mDexFile.getAbsolutePath())));
} catch (IOException | DirectoryException ex) {
throw new AndrolibException(ex);
}
}
use of org.jf.dexlib2.writer.io.FileDataStore in project atlas by alibaba.
the class SmaliUtils method assembleSmaliFile.
/**
* 将smali文件夹转换为dex文件
* @param smaliFolder
* @param outDexFile
* @return
*/
public static boolean assembleSmaliFile(File smaliFolder, File outDexFile) throws IOException, RecognitionException {
Collection<File> smaliFiles = FileUtils.listFiles(smaliFolder, new String[] { "smali" }, true);
if (null != smaliFiles && smaliFiles.size() > 0) {
DexBuilder dexBuilder = DexBuilder.makeDexBuilder();
for (File smaliFile : smaliFiles) {
SmaliMod.assembleSmaliFile(smaliFile, dexBuilder, true, true);
}
dexBuilder.writeTo(new FileDataStore(outDexFile));
return true;
} else {
return false;
}
}
use of org.jf.dexlib2.writer.io.FileDataStore 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.dexlib2.writer.io.FileDataStore in project smali by JesusFreke.
the class DexPool method writeTo.
public static void writeTo(@Nonnull String path, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException {
DexPool dexPool = new DexPool(input.getOpcodes());
for (ClassDef classDef : input.getClasses()) {
dexPool.internClass(classDef);
}
dexPool.writeTo(new FileDataStore(new File(path)));
}
Aggregations