예제 #1
0
void dumpStructs(FILE *fp, DNA *dna)
{
    typedef std::list<StructName> StructList;
    StructList structs;

    for (int i=0; i<dna->getNumStructs(); i++)
    {
        short *sp = dna->getStruct(i);
        hgString type = dna->getType(sp[0]);

        int len = sp[1];
        sp+=2;

        size_t max = 0, max2 = 0;

        bool hasDeps = false;
        for (short el = 0; el <len; el++, sp+=2)
        {
            hgString dt = dna->getType(sp[0]);
            hgString dn = dna->getName(sp[1]);
            if (dn[0] != '*' && sp[0] >=  dna->getStruct(0)[0])
                hasDeps = true;

            if (max < dt.size())
                max = dt.size();
            if (max2 < dn.size())
                max2 = dn.size();
        }


        StructName sn = {dna, type, findStruct(type.c_str(), dna), hasDeps ? 1 : 0, max, max2};
        structs.push_back(sn);
    }

    dumpForwards(fp, dna);
    structs.sort(sortCmp);

    StructList::iterator it = structs.begin();

    int index = 0;
    while (it != structs.end())
    {
        StructName &sp = (*it);
        dumpClass(fp, dna, sp.strc, sp.max, sp.max2, index++);
        ++it;
    }
}
/*
 * Dump the requested sections of the file.
 */
void processDexFile(const char* fileName, DexFile* pDexFile)
{
    int i;

    printf("Opened '%s', DEX version '%.3s'\n", fileName,
        pDexFile->pHeader->magic +4);

    if (gOptions.showFileHeaders)
        dumpFileHeader(pDexFile);

    for (i = 0; i < (int) pDexFile->pHeader->classDefsSize; i++) {
        if (gOptions.showSectionHeaders)
            dumpClassDef(pDexFile, i);

        dumpClass(pDexFile, i);
    }
}
예제 #3
0
파일: DexList.cpp 프로젝트: handgod/soma
/*
 * Process a file.
 *
 * Returns 0 on success.
 */
int process(const char* fileName)
{
    DexFile* pDexFile = NULL;
    MemMapping map;
    bool mapped = false;
    int result = -1;
    UnzipToFileResult utfr;

    utfr = dexOpenAndMap(fileName, NULL, &map, true);
    if (utfr != kUTFRSuccess) {
        if (utfr == kUTFRNoClassesDex) {
            /* no classes.dex in the APK; pretend we succeeded */
            result = 0;
            goto bail;
        }
        fprintf(stderr, "Unable to process '%s'\n", fileName);
        goto bail;
    }
    mapped = true;

    pDexFile = dexFileParse((u1*)map.addr, map.length, kDexParseDefault);
    if (pDexFile == NULL) {
        fprintf(stderr, "Warning: DEX parse failed for '%s'\n", fileName);
        goto bail;
    }

    printf("#%s\n", fileName);

    int i;
    for (i = 0; i < (int) pDexFile->pHeader->classDefsSize; i++) {
        dumpClass(pDexFile, i);
    }

    result = 0;

bail:
    if (mapped)
        sysReleaseShmem(&map);
    if (pDexFile != NULL)
        dexFileFree(pDexFile);
    return result;
}