Search in sources :

Example 1 with DexBackedDexFile

use of org.jf.dexlib2.dexbacked.DexBackedDexFile 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 2 with DexBackedDexFile

use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.

the class DexParser method constructMethodRefTreeForDex.

@NotNull
static PackageTreeNode constructMethodRefTreeForDex(@NotNull DexBackedDexFile dexFile) {
    PackageTreeNode root = new PackageTreeNode("", "root", PackageTreeNode.NodeType.PACKAGE, null);
    Set<String> classesWithDefinition = dexFile.getClasses().stream().map(DexBackedClassDef::getType).collect(Collectors.toSet());
    Multimap<String, MethodReference> methodsByClassName = getMethodsByClassName(dexFile);
    for (String className : methodsByClassName.keySet()) {
        Collection<MethodReference> methods = methodsByClassName.get(className);
        for (MethodReference ref : methods) {
            root.insert("", DebuggerUtilsEx.signatureToName(className), ref, classesWithDefinition.contains(className));
        }
    }
    root.sortByCount();
    return root;
}
Also used : MethodReference(org.jf.dexlib2.iface.reference.MethodReference) DexBackedMethodReference(org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DexBackedDexFile

use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.

the class DexParser method getMethodsByClassName.

@NotNull
private static Multimap<String, MethodReference> getMethodsByClassName(@NotNull DexBackedDexFile dexFile) {
    Multimap<String, MethodReference> methodsByClass = ArrayListMultimap.create();
    for (int i = 0, m = dexFile.getMethodCount(); i < m; i++) {
        MethodReference methodRef = new DexBackedMethodReference(dexFile, i);
        methodsByClass.put(methodRef.getDefiningClass(), methodRef);
    }
    return methodsByClass;
}
Also used : DexBackedMethodReference(org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) DexBackedMethodReference(org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DexBackedDexFile

use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project soot by Sable.

the class DexlibWrapper method initialize.

public void initialize() {
    // resolve classes in dex files
    for (DexBackedDexFile dexFile : dexFiles) {
        for (ClassDef defItem : dexFile.getClasses()) {
            String forClassName = Util.dottedClassName(defItem.getType());
            classesToDefItems.put(forClassName, new ClassInformation(dexFile, defItem));
        }
    }
    // produce an error during type resolution.
    for (DexBackedDexFile dexFile : dexFiles) {
        for (int i = 0; i < dexFile.getTypeCount(); i++) {
            String t = dexFile.getType(i);
            Type st = DexType.toSoot(t);
            if (st instanceof ArrayType) {
                st = ((ArrayType) st).baseType;
            }
            String sootTypeName = st.toString();
            if (!Scene.v().containsClass(sootTypeName)) {
                if (st instanceof PrimType || st instanceof VoidType || systemAnnotationNames.contains(sootTypeName)) {
                    /*
						 * dex files contain references to the Type IDs of the
						 * system annotations. They are only visible to the
						 * Dalvik VM (for reflection, see
						 * vm/reflect/Annotations.cpp), and not to the user - so
						 * we do not want them to be resolved.
						 */
                    continue;
                }
                SootResolver.v().makeClassRef(sootTypeName);
            }
            SootResolver.v().resolveClass(sootTypeName, SootClass.SIGNATURES);
        }
    }
}
Also used : ArrayType(soot.ArrayType) VoidType(soot.VoidType) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) ClassDef(org.jf.dexlib2.iface.ClassDef) ArrayType(soot.ArrayType) Type(soot.Type) PrimType(soot.PrimType) VoidType(soot.VoidType) PrimType(soot.PrimType)

Example 5 with DexBackedDexFile

use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project soot by Sable.

the class DexClassProvider method classesOfDex.

public static Set<String> classesOfDex(DexBackedDexFile dexFile) {
    Set<String> classes = new HashSet<String>();
    for (ClassDef c : dexFile.getClasses()) {
        String name = Util.dottedClassName(c.getType());
        classes.add(name);
    }
    return classes;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef)

Aggregations

DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)29 Test (org.junit.Test)10 IOException (java.io.IOException)9 File (java.io.File)7 MemoryDataStore (org.jf.dexlib2.writer.io.MemoryDataStore)6 ClassDef (org.jf.dexlib2.iface.ClassDef)5 DexFile (org.jf.dexlib2.iface.DexFile)5 Nonnull (javax.annotation.Nonnull)4 DexEntryFinder (org.jf.dexlib2.DexFileFactory.DexEntryFinder)4 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)4 DexBuilder (org.jf.dexlib2.writer.builder.DexBuilder)4 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 FileInputStream (java.io.FileInputStream)2 Opcode (org.jf.dexlib2.Opcode)2 Opcodes (org.jf.dexlib2.Opcodes)2 ClassPath (org.jf.dexlib2.analysis.ClassPath)2 ClassPathResolver (org.jf.dexlib2.analysis.ClassPathResolver)2 BuilderInstruction21c (org.jf.dexlib2.builder.instruction.BuilderInstruction21c)2 DexBackedOdexFile (org.jf.dexlib2.dexbacked.DexBackedOdexFile)2