/*
 * Dump the class.
 */
void dumpClass(DexFile* pDexFile, int idx)
{
    const DexTypeList* pInterfaces;
    const DexClassDef* pClassDef;
    DexClassData* pClassData;
    const u1* pEncodedData;
    const char* fileName;
    const char* classDescriptor;
    const char* superclassDescriptor;
    char* accessStr;
    int i;

    pClassDef = dexGetClassDef(pDexFile, idx);
    printf("Class #%d            -\n", idx);

    pEncodedData = dexGetClassData(pDexFile, pClassDef);
    pClassData = dexReadAndVerifyClassData(&pEncodedData, NULL);

    if (pClassData == NULL) {
        printf("Trouble reading class data\n");
        return;
    }
    
    classDescriptor = dexStringByTypeIdx(pDexFile, pClassDef->classIdx);
    printf("  Class descriptor  : '%s'\n", classDescriptor);

    accessStr = createAccessFlagStr(pClassDef->accessFlags, kAccessForClass);
    printf("  Access flags      : 0x%04x (%s)\n",
        pClassDef->accessFlags, accessStr);

    if (pClassDef->superclassIdx == kDexNoIndex)
        superclassDescriptor = "(none)";
    else {
        superclassDescriptor =
            dexStringByTypeIdx(pDexFile, pClassDef->superclassIdx);
        printf("  Superclass        : '%s'\n", superclassDescriptor);
    }

    printf("  Interfaces        -\n");
    pInterfaces = dexGetInterfacesList(pDexFile, pClassDef);
    if (pInterfaces != NULL) {
        for (i = 0; i < (int) pInterfaces->size; i++)
            dumpInterface(pDexFile, dexGetTypeItem(pInterfaces, i), i);
    }

    printf("  Static fields     -\n");
    for (i = 0; i < (int) pClassData->header.staticFieldsSize; i++) {
        dumpSField(pDexFile, &pClassData->staticFields[i], i);
    }

    printf("  Instance fields   -\n");
    for (i = 0; i < (int) pClassData->header.instanceFieldsSize; i++) {
        dumpIField(pDexFile, &pClassData->instanceFields[i], i);
    }

    printf("  Direct methods    -\n");
    for (i = 0; i < (int) pClassData->header.directMethodsSize; i++) {
        dumpMethod(pDexFile, &pClassData->directMethods[i], i);
    }

    printf("  Virtual methods   -\n");
    for (i = 0; i < (int) pClassData->header.virtualMethodsSize; i++) {
        dumpMethod(pDexFile, &pClassData->virtualMethods[i], i);
    }

    // TODO: Annotations.

    if (pClassDef->sourceFileIdx != kDexNoIndex)
        fileName = dexStringById(pDexFile, pClassDef->sourceFileIdx);
    else
        fileName = "unknown";
    printf("  source_file_idx   : %d (%s)\n",
        pClassDef->sourceFileIdx, fileName);

    printf("\n");

    free(pClassData);
    free(accessStr);
}
Beispiel #2
0
/* return the type_idx for the Nth entry in a TypeList */
DEX_INLINE u4 dexTypeListGetIdx(const DexTypeList* pList, u4 idx) {
    const DexTypeItem* pItem = dexGetTypeItem(pList, idx);
    return pItem->typeIdx;
}