Search in sources :

Example 6 with ClassFileNameHandler

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;
}
Also used : ClassFileNameHandler(org.jf.util.ClassFileNameHandler) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) File(java.io.File) FileDataStore(org.jf.dexlib2.writer.io.FileDataStore) HashSet(java.util.HashSet) DexBuilder(org.jf.dexlib2.writer.builder.DexBuilder)

Example 7 with ClassFileNameHandler

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;
}
Also used : ClassFileNameHandler(org.jf.util.ClassFileNameHandler) ClassDef(org.jf.dexlib2.iface.ClassDef)

Aggregations

ClassFileNameHandler (org.jf.util.ClassFileNameHandler)7 File (java.io.File)5 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)4 IOException (java.io.IOException)3 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)3 ClassDef (org.jf.dexlib2.iface.ClassDef)3 PatchException (com.taobao.android.differ.dex.PatchException)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParser (javax.xml.parsers.SAXParser)2 RecognitionException (org.antlr.runtime.RecognitionException)2 CustomInlineMethodResolver (org.jf.dexlib2.analysis.CustomInlineMethodResolver)2 DexFile (org.jf.dexlib2.iface.DexFile)2 SyntheticAccessorResolver (org.jf.dexlib2.util.SyntheticAccessorResolver)2 Attributes (org.xml.sax.Attributes)2 SAXException (org.xml.sax.SAXException)2 DefaultHandler (org.xml.sax.helpers.DefaultHandler)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1