Search in sources :

Example 26 with DexFile

use of org.jf.dexlib2.iface.DexFile 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 27 with DexFile

use of org.jf.dexlib2.iface.DexFile 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 28 with DexFile

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

the class ApkDashboard method fillAnalysisPerClassesDexIndex.

public static ClassesDexDataEntry fillAnalysisPerClassesDexIndex(int dexIndex, File classesDex) {
    ClassesDexDataEntry dexData = new ClassesDexDataEntry(dexIndex);
    try {
        InputStream is = new FileInputStream(classesDex);
        ApplicationVisitor av = new ApkNativeMethodsVisitor(dexData);
        ApplicationReader ar = new ApplicationReader(Opcodes.ASM4, is);
        ar.accept(av, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        DexFile dxFile = DexlibLoader.loadDexFile(classesDex);
        DexBackedDexFile dataPack = (DexBackedDexFile) dxFile;
        dexData.allMethods = dataPack.getMethodCount();
    //dexData.syntheticAccessors =
    //        new SyntheticAccessorsInspector(dxFile).getSyntheticAccessors();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("here " + e);
    }
    return dexData;
}
Also used : DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ApplicationVisitor(org.ow2.asmdex.ApplicationVisitor) FileInputStream(java.io.FileInputStream) ApplicationReader(org.ow2.asmdex.ApplicationReader) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) DexFile(org.jf.dexlib2.iface.DexFile)

Example 29 with DexFile

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

the class DexInfoTranslator method apply.

@Override
public void apply() {
    try {
        elements.clear();
        File classesDex = extractClassesDex(dexFileName, apkFile, this);
        DexFile dxFile = DexlibLoader.loadDexFile(classesDex);
        DexBackedDexFile dataPack = (DexBackedDexFile) dxFile;
        ELEMENT element = new ELEMENT("\nclasses: " + dataPack.getClassCount(), TAG.MODIFIER);
        elements.add(element);
        element = new ELEMENT("\nstrings: " + dataPack.getStringCount(), TAG.DOCUMENT);
        elements.add(element);
        element = new ELEMENT("\ntypes: " + dataPack.getTypeCount(), TAG.DOCUMENT);
        elements.add(element);
        element = new ELEMENT("\nprotos: " + dataPack.getProtoCount(), TAG.DOCUMENT);
        elements.add(element);
        element = new ELEMENT("\nfields: " + dataPack.getFieldCount(), TAG.DOCUMENT);
        elements.add(element);
        element = new ELEMENT("\nmethods: " + dataPack.getMethodCount(), TAG.IDENTIFIER);
        elements.add(element);
        element = new ELEMENT("\n\nFile size: " + JarInfoTranslator.readableFileSize(classesDex.length()), TAG.DOCUMENT);
        elements.add(element);
        element = new ELEMENT("\n\nClasses with Native Calls\n", TAG.MODIFIER);
        elements.add(element);
        Set<String> classesWithNativeMethods = getClassesWithNativeMethodsPerDexIndex(index, classesDex);
        for (String classWithNativeMethods : classesWithNativeMethods) {
            element = new ELEMENT(classWithNativeMethods + "\n", TAG.DOCUMENT);
            elements.add(element);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) DexFile(org.jf.dexlib2.iface.DexFile)

Example 30 with DexFile

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

the class DexReader method readClassNamesFromDex.

public static List<String> readClassNamesFromDex(File binaryArchiveFile) throws Exception {
    DexFile dexFile = DexlibLoader.loadDexFile(binaryArchiveFile);
    List<String> result = new ArrayList<>();
    for (ClassDef classDef : dexFile.getClasses()) {
        result.add(classDef.getType().replaceAll("/", ".").substring(1, classDef.getType().length() - 1));
    }
    Collections.sort(result);
    return result;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) ArrayList(java.util.ArrayList) DexFile(org.jf.dexlib2.iface.DexFile)

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