Beispiel #1
0
/*
Create a DexFile structure for a "partial" DEX.  This is one that is in
the process of being optimized.  The optimization header isn't finished
and we won't have any of the auxillary data tables, so we have to do
the initialization slightly differently.

Returns nonzero on error.

为“部分”DEX创建一个DEX文件结构。这是一个存在于已优化过程中的结构。优化头没有完成
并且我们没有任何的辅助数据表,因此只是初始化略有不同。
*/
int dvmDexFileOpenPartial(const void* addr, int len, DvmDex** ppDvmDex)
{
    DvmDex* pDvmDex;
    DexFile* pDexFile;
    int parseFlags = kDexParseDefault;
    int result = -1;

    /* -- file is incomplete, new checksum has not yet been calculated
    if (gDvm.verifyDexChecksum)
        parseFlags |= kDexParseVerifyChecksum;
    */

    pDexFile = dexFileParse((u1*)addr, len, parseFlags);
    if (pDexFile == NULL) {
        ALOGE("DEX parse failed");
        goto bail;
    }
    pDvmDex = allocateAuxStructures(pDexFile);
    if (pDvmDex == NULL) {
        dexFileFree(pDexFile);
        goto bail;
    }

    pDvmDex->isMappedReadOnly = false;
    *ppDvmDex = pDvmDex;
    result = 0;

bail:
    return result;
}
Beispiel #2
0
/*
 * Given an open optimized DEX file, map it into read-only shared memory and
 * parse the contents.
 *
 * Returns nonzero on error.
 */
int dvmDexFileOpenFromFd(int fd, DvmDex** ppDvmDex)
{
    DvmDex* pDvmDex;
    DexFile* pDexFile;
    MemMapping memMap;
    int parseFlags = kDexParseDefault;
    int result = -1;

    if (gDvm.verifyDexChecksum)
        parseFlags |= kDexParseVerifyChecksum;

    if (lseek(fd, 0, SEEK_SET) < 0) {
        LOGE("lseek rewind failed\n");
        goto bail;
    }

    if (sysMapFileInShmemWritableReadOnly(fd, &memMap) != 0) {
        LOGE("Unable to map file\n");
        goto bail;
    }

    pDexFile = dexFileParse(memMap.addr, memMap.length, parseFlags);
    if (pDexFile == NULL) {
        LOGE("DEX parse failed\n");
        sysReleaseShmem(&memMap);
        goto bail;
    }

    pDvmDex = allocateAuxStructures(pDexFile);
    if (pDvmDex == NULL) {
        dexFileFree(pDexFile);
        sysReleaseShmem(&memMap);
        goto bail;
    }
    
    //This seems like the best place to initialize the DvmDex mutex.
    dvmInitMutex(&pDvmDex->modLock);

    /* tuck this into the DexFile so it gets released later */
    sysCopyMap(&pDvmDex->memMap, &memMap);
    *ppDvmDex = pDvmDex;
    result = 0;

bail:
    return result;
}
Beispiel #3
0
/*
Given an open optimized DEX file, map it into read-only shared memory and
parse the contents.

Returns nonzero on error.

给定一个打开的已优化的DEX文件,映射到只读共享内存并且解析内容。

错误返回非0。
*/
int dvmDexFileOpenFromFd(int fd, DvmDex** ppDvmDex)
{
    DvmDex* pDvmDex;
    DexFile* pDexFile;
    MemMapping memMap;
    int parseFlags = kDexParseDefault;
    int result = -1;

    if (gDvm.verifyDexChecksum)
        parseFlags |= kDexParseVerifyChecksum;

    if (lseek(fd, 0, SEEK_SET) < 0) {
        ALOGE("lseek rewind failed");
        goto bail;
    }

    if (sysMapFileInShmemWritableReadOnly(fd, &memMap) != 0) {
        ALOGE("Unable to map file");
        goto bail;
    }

    pDexFile = dexFileParse((u1*)memMap.addr, memMap.length, parseFlags);
    if (pDexFile == NULL) {
        ALOGE("DEX parse failed");
        sysReleaseShmem(&memMap);
        goto bail;
    }

    pDvmDex = allocateAuxStructures(pDexFile);
    if (pDvmDex == NULL) {
        dexFileFree(pDexFile);
        sysReleaseShmem(&memMap);
        goto bail;
    }

    /* tuck this into the DexFile so it gets released later */
    sysCopyMap(&pDvmDex->memMap, &memMap);
    pDvmDex->isMappedReadOnly = true;
    *ppDvmDex = pDvmDex;
    result = 0;

bail:
    return result;
}
Beispiel #4
0
/*
 * Given an open optimized DEX file, map it into read-only shared memory and
 * parse the contents.
 *
 * Returns nonzero on error.
 */
int dvmDexFileOpenFromFd(int fd, DvmDex** ppDvmDex)
{
    DvmDex* pDvmDex;
    DexFile* pDexFile;
    MemMapping memMap;
    int parseFlags = kDexParseDefault;
    int result = -1;

//    //salma //Success here
    // All the file manipulation moved to the JarFile.cpp

    //DvmConfigFile* pDvmConfigFile;
//    int configFd = -1;
//    __android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: Try to open config.xml");
//    configFd = open("/sdcard/config.xml", O_RDONLY);
//    if(configFd < 0)
//    	__android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: FAIL Try to open config.xml");
//    else{
//    	__android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: SUCCESS Try to open config.xml");
//    	//success
//    	__android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: SUCCESS  Start Parse config.xml");
//    	pDvmConfigFile = dvmConfigFileParse(configFd);
//    	__android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: SUCCESS  Finish Parse config.xml");
//    	dvmConfigFileDebug(pDvmConfigFile);
//    	__android_log_print(ANDROID_LOG_DEBUG, "DVM DEBUG", "DvmDex.cpp: SUCCESS  Finish Debug config.xml");
//    }
////endsalma


    if (gDvm.verifyDexChecksum)
        parseFlags |= kDexParseVerifyChecksum;

    if (lseek(fd, 0, SEEK_SET) < 0) {
        ALOGE("lseek rewind failed");
        goto bail;
    }

    if (sysMapFileInShmemWritableReadOnly(fd, &memMap) != 0) {
        ALOGE("Unable to map file");
        goto bail;
    }

    pDexFile = dexFileParse((u1*)memMap.addr, memMap.length, parseFlags);
    if (pDexFile == NULL) {
        ALOGE("DEX parse failed");
        sysReleaseShmem(&memMap);
        goto bail;
    }

    pDvmDex = allocateAuxStructures(pDexFile);
    if (pDvmDex == NULL) {
        dexFileFree(pDexFile);
        sysReleaseShmem(&memMap);
        goto bail;
    }

    /* tuck this into the DexFile so it gets released later */
    sysCopyMap(&pDvmDex->memMap, &memMap);
    pDvmDex->isMappedReadOnly = true;
    *ppDvmDex = pDvmDex;
    result = 0;

bail:
    return result;
}