Search in sources :

Example 1 with ClassData

use of com.taobao.android.dex.ClassData 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 ClassData

use of com.taobao.android.dex.ClassData 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 ClassData

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

the class DexMerger method transformClassDef.

/**
     * Reads a class_def_item beginning at {@code in} and writes the index and
     * data.
     */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());
    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);
    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));
    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }
    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustStaticValues(staticValuesOff));
}
Also used : ClassData(com.taobao.android.dex.ClassData)

Aggregations

ClassData (com.taobao.android.dex.ClassData)3 ClassDef (com.taobao.android.dex.ClassDef)2 EncodedValueReader (com.taobao.android.dex.EncodedValueReader)1