Search in sources :

Example 1 with ClassDef

use of com.taobao.android.dex.ClassDef in project atlas by alibaba.

the class Grep method grep.

/**
     * Prints usages to out. Returns the number of matches found.
     */
public int grep() {
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;
        if (classDef.getClassDataOffset() == 0) {
            continue;
        }
        ClassData classData = dex.readClassData(classDef);
        // find the strings in encoded constants
        int staticValuesOffset = classDef.getStaticValuesOffset();
        if (staticValuesOffset != 0) {
            readArray(new EncodedValueReader(dex.open(staticValuesOffset)));
        }
        // find the strings in method bodies
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }
    currentClass = null;
    currentMethod = null;
    return count;
}
Also used : ClassDef(com.taobao.android.dex.ClassDef) EncodedValueReader(com.taobao.android.dex.EncodedValueReader) ClassData(com.taobao.android.dex.ClassData)

Example 2 with ClassDef

use of com.taobao.android.dex.ClassDef in project atlas by alibaba.

the class FindUsages method findUsages.

/**
     * Prints usages to out.
     */
public void findUsages() {
    if (fieldIds == null || methodIds == null) {
        return;
    }
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;
        if (classDef.getClassDataOffset() == 0) {
            continue;
        }
        ClassData classData = dex.readClassData(classDef);
        for (ClassData.Field field : classData.allFields()) {
            int fieldIndex = field.getFieldIndex();
            if (fieldIds.contains(fieldIndex)) {
                out.println(location() + " field declared " + dex.fieldIds().get(fieldIndex));
            }
        }
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            int methodIndex = method.getMethodIndex();
            if (methodIds.contains(methodIndex)) {
                out.println(location() + " method declared " + dex.methodIds().get(methodIndex));
            }
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }
    currentClass = null;
    currentMethod = null;
}
Also used : ClassDef(com.taobao.android.dex.ClassDef) ClassData(com.taobao.android.dex.ClassData)

Example 3 with ClassDef

use of com.taobao.android.dex.ClassDef in project atlas by alibaba.

the class FindUsages method findAssignableTypes.

/**
     * Returns the set of types that can be assigned to {@code typeIndex}.
     */
private Set<Integer> findAssignableTypes(Dex dex, int typeIndex) {
    Set<Integer> assignableTypes = new HashSet<Integer>();
    assignableTypes.add(typeIndex);
    for (ClassDef classDef : dex.classDefs()) {
        if (assignableTypes.contains(classDef.getSupertypeIndex())) {
            assignableTypes.add(classDef.getTypeIndex());
            continue;
        }
        for (int implemented : classDef.getInterfaces()) {
            if (assignableTypes.contains(implemented)) {
                assignableTypes.add(classDef.getTypeIndex());
                break;
            }
        }
    }
    return assignableTypes;
}
Also used : ClassDef(com.taobao.android.dex.ClassDef) HashSet(java.util.HashSet)

Example 4 with ClassDef

use of com.taobao.android.dex.ClassDef in project atlas by alibaba.

the class DexIndexPrinter method printClassDefs.

private void printClassDefs() {
    int index = 0;
    for (ClassDef classDef : dex.classDefs()) {
        System.out.println("class def " + index + ": " + classDef);
        index++;
    }
}
Also used : ClassDef(com.taobao.android.dex.ClassDef)

Example 5 with ClassDef

use of com.taobao.android.dex.ClassDef in project atlas by alibaba.

the class DexMerger method readSortableTypes.

/**
     * Reads just enough data on each class so that we can sort it and then find
     * it later.
     */
private void readSortableTypes(SortableType[] sortableTypes, Dex buffer, IndexMap indexMap) {
    for (ClassDef classDef : buffer.classDefs()) {
        SortableType sortableType = indexMap.adjust(new SortableType(buffer, classDef));
        int t = sortableType.getTypeIndex();
        if (sortableTypes[t] == null) {
            sortableTypes[t] = sortableType;
        } else if (collisionPolicy != CollisionPolicy.KEEP_FIRST) {
            throw new DexException("Multiple dex files define " + buffer.typeNames().get(classDef.getTypeIndex()));
        }
    }
}
Also used : DexException(com.taobao.android.dex.DexException) ClassDef(com.taobao.android.dex.ClassDef)

Aggregations

ClassDef (com.taobao.android.dex.ClassDef)5 ClassData (com.taobao.android.dex.ClassData)2 DexException (com.taobao.android.dex.DexException)1 EncodedValueReader (com.taobao.android.dex.EncodedValueReader)1 HashSet (java.util.HashSet)1