Search in sources :

Example 1 with DexFile

use of org.jf.dexlib2.iface.DexFile in project atlas by alibaba.

the class PatchFieldTool method addField.

public static void addField(String inFile, String outFile, DexBackedClassDef dexBackedClassDef, ImmutableField immutableField) throws IOException {
    DexFile dexFile = readDexFile(inFile);
    for (ClassDef classDef : dexFile.getClasses()) {
        if (dexBackedClassDef != null && dexBackedClassDef.getType().equals(classDef.getType())) {
            dexFile = addField(dexFile, classDef.getType(), immutableField);
        } else if (dexBackedClassDef == null) {
            dexFile = addField(dexFile, classDef.getType(), immutableField);
        }
    }
    reDexFile(dexFile);
    DexFileFactory.writeDexFile(outFile, new DexFile() {

        @Nonnull
        @Override
        public Set<? extends ClassDef> getClasses() {
            return new AbstractSet<ClassDef>() {

                @Nonnull
                @Override
                public Iterator<ClassDef> iterator() {
                    return classes.iterator();
                }

                @Override
                public int size() {
                    return classes.size();
                }
            };
        }
    });
}
Also used : DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) Nonnull(javax.annotation.Nonnull)

Example 2 with DexFile

use of org.jf.dexlib2.iface.DexFile in project atlas by alibaba.

the class PatchUtils method getBundleClassDef.

private static Map<String, ClassDef> getBundleClassDef(File file) throws IOException {
    HashMap<String, ClassDef> classDefMap = new HashMap<String, ClassDef>();
    File[] dexFiles = getDexFiles(file);
    HashSet<ClassDef> classDefs = new HashSet<ClassDef>();
    for (File dexFile : dexFiles) {
        classDefs.addAll(DexFileFactory.loadDexFile(dexFile, 19, true).getClasses());
    }
    for (ClassDef classDef : classDefs) {
        classDefMap.put(classDef.getType(), classDef);
    }
    return classDefMap;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) HashMap(java.util.HashMap) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with DexFile

use of org.jf.dexlib2.iface.DexFile in project Apktool by iBotPeaches.

the class SmaliDecoder method decode.

private void decode() throws AndrolibException {
    try {
        baksmaliOptions options = new baksmaliOptions();
        // options
        options.deodex = false;
        options.outputDirectory = mOutDir.toString();
        options.noParameterRegisters = false;
        options.useLocalsDirective = true;
        options.useSequentialLabels = true;
        options.outputDebugInfo = mBakDeb;
        options.addCodeOffsets = false;
        options.jobs = -1;
        options.noAccessorComments = false;
        options.registerInfo = 0;
        options.ignoreErrors = false;
        options.inlineResolver = null;
        options.checkPackagePrivateAccess = false;
        // set jobs automatically
        options.jobs = Runtime.getRuntime().availableProcessors();
        if (options.jobs > 6) {
            options.jobs = 6;
        }
        // create the dex
        DexBackedDexFile dexFile = DexFileFactory.loadDexFile(mApkFile, mDexFile, mApi, false);
        if (dexFile.isOdexFile()) {
            throw new AndrolibException("Warning: You are disassembling an odex file without deodexing it.");
        }
        if (dexFile instanceof DexBackedOdexFile) {
            options.inlineResolver = InlineMethodResolver.createInlineMethodResolver(((DexBackedOdexFile) dexFile).getOdexVersion());
        }
        baksmali.disassembleDexFile(dexFile, options);
    } catch (IOException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : org.jf.baksmali.baksmaliOptions(org.jf.baksmali.baksmaliOptions) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) AndrolibException(brut.androlib.AndrolibException) DexBackedOdexFile(org.jf.dexlib2.dexbacked.DexBackedOdexFile) IOException(java.io.IOException)

Example 4 with DexFile

use of org.jf.dexlib2.iface.DexFile in project android-classyshark by google.

the class StressTest method runAllClassesInDex.

public static void runAllClassesInDex(String jarCanonicalPath) throws Exception {
    DexFile dexFile = DexlibLoader.loadDexFile(new File(jarCanonicalPath));
    Set<? extends ClassDef> allClassesInDex = dexFile.getClasses();
    for (ClassDef currentClass : allClassesInDex) {
        String normType = DexlibAdapter.getClassStringFromDex(currentClass.getType());
        Translator sourceGenerator = TranslatorFactory.createTranslator(normType, new File(jarCanonicalPath));
        sourceGenerator.apply();
        System.out.println(sourceGenerator.toString());
    }
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) Translator(com.google.classyshark.silverghost.translator.Translator) DexFile(org.jf.dexlib2.iface.DexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile)

Example 5 with DexFile

use of org.jf.dexlib2.iface.DexFile in project android-classyshark by google.

the class DexlibAdapter method getClassDefByName.

public static ClassDef getClassDefByName(String className, DexFile dexFile) throws Exception {
    ClassDef result = null;
    String dexName;
    for (ClassDef currentClassDef : dexFile.getClasses()) {
        dexName = currentClassDef.getType();
        if (isMatchFromDex(className, dexName)) {
            result = currentClassDef;
            break;
        }
    }
    return result;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef)

Aggregations

DexFile (org.jf.dexlib2.iface.DexFile)28 ClassDef (org.jf.dexlib2.iface.ClassDef)26 Test (org.junit.Test)17 Nonnull (javax.annotation.Nonnull)15 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)15 ImmutableClassDef (org.jf.dexlib2.immutable.ImmutableClassDef)13 File (java.io.File)12 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)12 IOException (java.io.IOException)10 Method (org.jf.dexlib2.iface.Method)10 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)10 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)8 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)8 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)7 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)7 BuilderInstruction21t (org.jf.dexlib2.builder.instruction.BuilderInstruction21t)6 BuilderInstruction22c (org.jf.dexlib2.builder.instruction.BuilderInstruction22c)6 Instruction (org.jf.dexlib2.iface.instruction.Instruction)6 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)6 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)5