diff options
Diffstat (limited to 'libdex')
-rw-r--r-- | libdex/Android.mk | 36 | ||||
-rw-r--r-- | libdex/CmdUtils.cpp (renamed from libdex/CmdUtils.c) | 4 | ||||
-rw-r--r-- | libdex/DexCatch.cpp (renamed from libdex/DexCatch.c) | 0 | ||||
-rw-r--r-- | libdex/DexClass.cpp (renamed from libdex/DexClass.c) | 4 | ||||
-rw-r--r-- | libdex/DexDataMap.cpp (renamed from libdex/DexDataMap.c) | 2 | ||||
-rw-r--r-- | libdex/DexDebugInfo.cpp (renamed from libdex/DexDebugInfo.c) | 97 | ||||
-rw-r--r-- | libdex/DexDebugInfo.h | 14 | ||||
-rw-r--r-- | libdex/DexFile.cpp (renamed from libdex/DexFile.c) | 0 | ||||
-rw-r--r-- | libdex/DexInlines.cpp (renamed from libdex/DexInlines.c) | 0 | ||||
-rw-r--r-- | libdex/DexOpcodes.cpp (renamed from libdex/DexOpcodes.c) | 0 | ||||
-rw-r--r-- | libdex/DexOptData.cpp (renamed from libdex/DexOptData.c) | 2 | ||||
-rw-r--r-- | libdex/DexProto.cpp (renamed from libdex/DexProto.c) | 2 | ||||
-rw-r--r-- | libdex/DexSwapVerify.cpp (renamed from libdex/DexSwapVerify.c) | 81 | ||||
-rw-r--r-- | libdex/DexUtf.cpp (renamed from libdex/DexUtf.c) | 0 | ||||
-rw-r--r-- | libdex/InstrUtils.cpp (renamed from libdex/InstrUtils.c) | 0 | ||||
-rw-r--r-- | libdex/Leb128.cpp (renamed from libdex/Leb128.c) | 0 | ||||
-rw-r--r-- | libdex/OptInvocation.cpp (renamed from libdex/OptInvocation.c) | 0 | ||||
-rw-r--r-- | libdex/OptInvocation.h | 2 | ||||
-rw-r--r-- | libdex/SysUtil.cpp (renamed from libdex/SysUtil.c) | 0 | ||||
-rw-r--r-- | libdex/ZipArchive.cpp (renamed from libdex/ZipArchive.c) | 52 | ||||
-rw-r--r-- | libdex/sha1.cpp (renamed from libdex/sha1.c) | 0 |
21 files changed, 165 insertions, 131 deletions
diff --git a/libdex/Android.mk b/libdex/Android.mk index 26f84d657..bb8d03b96 100644 --- a/libdex/Android.mk +++ b/libdex/Android.mk @@ -15,24 +15,24 @@ LOCAL_PATH:= $(call my-dir) dex_src_files := \ - CmdUtils.c \ - DexCatch.c \ - DexClass.c \ - DexDataMap.c \ - DexDebugInfo.c \ - DexFile.c \ - DexInlines.c \ - DexOptData.c \ - DexOpcodes.c \ - DexProto.c \ - DexSwapVerify.c \ - DexUtf.c \ - InstrUtils.c \ - Leb128.c \ - OptInvocation.c \ - sha1.c \ - SysUtil.c \ - ZipArchive.c + CmdUtils.cpp \ + DexCatch.cpp \ + DexClass.cpp \ + DexDataMap.cpp \ + DexDebugInfo.cpp \ + DexFile.cpp \ + DexInlines.cpp \ + DexOptData.cpp \ + DexOpcodes.cpp \ + DexProto.cpp \ + DexSwapVerify.cpp \ + DexUtf.cpp \ + InstrUtils.cpp \ + Leb128.cpp \ + OptInvocation.cpp \ + sha1.cpp \ + SysUtil.cpp \ + ZipArchive.cpp dex_include_files := \ dalvik \ diff --git a/libdex/CmdUtils.c b/libdex/CmdUtils.cpp index ecb53e86d..ff737a362 100644 --- a/libdex/CmdUtils.c +++ b/libdex/CmdUtils.cpp @@ -197,7 +197,7 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName, */ sysChangeMapAccess(pMap->addr, pMap->length, true, pMap); - if (dexSwapAndVerifyIfNecessary(pMap->addr, pMap->length)) { + if (dexSwapAndVerifyIfNecessary((u1*) pMap->addr, pMap->length)) { fprintf(stderr, "ERROR: Failed structural verification of '%s'\n", fileName); goto bail; @@ -213,7 +213,7 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName, /* * Success! Close the file and return with the start/length in pMap. */ - result = 0; + result = kUTFRSuccess; bail: if (fd >= 0) diff --git a/libdex/DexCatch.c b/libdex/DexCatch.cpp index ed97e87d9..ed97e87d9 100644 --- a/libdex/DexCatch.c +++ b/libdex/DexCatch.cpp diff --git a/libdex/DexClass.c b/libdex/DexClass.cpp index 8a59e09fd..552229cc4 100644 --- a/libdex/DexClass.c +++ b/libdex/DexClass.cpp @@ -106,7 +106,7 @@ DexClassData* dexReadAndVerifyClassData(const u1** pData, const u1* pLimit) { u4 lastIndex; if (*pData == NULL) { - DexClassData* result = malloc(sizeof(DexClassData)); + DexClassData* result = (DexClassData*) malloc(sizeof(DexClassData)); memset(result, 0, sizeof(*result)); return result; } @@ -121,7 +121,7 @@ DexClassData* dexReadAndVerifyClassData(const u1** pData, const u1* pLimit) { (header.directMethodsSize * sizeof(DexMethod)) + (header.virtualMethodsSize * sizeof(DexMethod)); - DexClassData* result = malloc(resultSize); + DexClassData* result = (DexClassData*) malloc(resultSize); u1* ptr = ((u1*) result) + sizeof(DexClassData); bool okay = true; u4 i; diff --git a/libdex/DexDataMap.c b/libdex/DexDataMap.cpp index a9d429e18..33135ed1c 100644 --- a/libdex/DexDataMap.c +++ b/libdex/DexDataMap.cpp @@ -41,7 +41,7 @@ DexDataMap* dexDataMapAlloc(u4 maxCount) { return NULL; } - map = malloc(size); + map = (DexDataMap*) malloc(size); if (map == NULL) { return NULL; diff --git a/libdex/DexDebugInfo.c b/libdex/DexDebugInfo.cpp index 43765f7db..c33a1e49f 100644 --- a/libdex/DexDebugInfo.c +++ b/libdex/DexDebugInfo.cpp @@ -129,34 +129,32 @@ static void emitLocalCbIfLive(void *cnxt, int reg, u4 endAddress, } } -// TODO optimize localCb == NULL case -void dexDecodeDebugInfo( +static void invalidStream(const char* classDescriptor, const DexProto* proto) { + IF_LOGE() { + char* methodDescriptor = dexProtoCopyMethodDescriptor(proto); + LOGE("Invalid debug info stream. class %s; proto %s", + classDescriptor, methodDescriptor); + free(methodDescriptor); + } +} + +static void dexDecodeDebugInfo0( const DexFile* pDexFile, const DexCode* pCode, const char* classDescriptor, u4 protoIdx, u4 accessFlags, DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb, - void* cnxt) + void* cnxt, + const u1* stream, + LocalInfo* localInReg) { - const u1 *stream = dexGetDebugInfoStream(pDexFile, pCode); - u4 line; - u4 parametersSize; - u4 address = 0; - LocalInfo localInReg[pCode->registersSize]; - u4 insnsSize = pCode->insnsSize; DexProto proto = { pDexFile, protoIdx }; - - memset(localInReg, 0, sizeof(LocalInfo) * pCode->registersSize); - - if (stream == NULL) { - goto end; - } - - line = readUnsignedLeb128(&stream); - parametersSize = readUnsignedLeb128(&stream); - + u4 insnsSize = pCode->insnsSize; + u4 line = readUnsignedLeb128(&stream); + u4 parametersSize = readUnsignedLeb128(&stream); u2 argReg = pCode->registersSize - pCode->insSize; + u4 address = 0; if ((accessFlags & ACC_STATIC) == 0) { /* @@ -184,7 +182,8 @@ void dexDecodeDebugInfo( int reg; if ((argReg >= pCode->registersSize) || (descriptor == NULL)) { - goto invalid_stream; + invalidStream(classDescriptor, &proto); + return; } name = readStringIdx(pDexFile, &stream); @@ -215,7 +214,7 @@ void dexDecodeDebugInfo( switch (opcode) { case DBG_END_SEQUENCE: - goto end; + return; case DBG_ADVANCE_PC: address += readUnsignedLeb128(&stream); @@ -228,10 +227,13 @@ void dexDecodeDebugInfo( case DBG_START_LOCAL: case DBG_START_LOCAL_EXTENDED: reg = readUnsignedLeb128(&stream); - if (reg > pCode->registersSize) goto invalid_stream; + if (reg > pCode->registersSize) { + invalidStream(classDescriptor, &proto); + return; + } // Emit what was previously there, if anything - emitLocalCbIfLive (cnxt, reg, address, + emitLocalCbIfLive(cnxt, reg, address, localInReg, localCb); localInReg[reg].name = readStringIdx(pDexFile, &stream); @@ -248,7 +250,10 @@ void dexDecodeDebugInfo( case DBG_END_LOCAL: reg = readUnsignedLeb128(&stream); - if (reg > pCode->registersSize) goto invalid_stream; + if (reg > pCode->registersSize) { + invalidStream(classDescriptor, &proto); + return; + } emitLocalCbIfLive (cnxt, reg, address, localInReg, localCb); localInReg[reg].live = false; @@ -256,11 +261,15 @@ void dexDecodeDebugInfo( case DBG_RESTART_LOCAL: reg = readUnsignedLeb128(&stream); - if (reg > pCode->registersSize) goto invalid_stream; + if (reg > pCode->registersSize) { + invalidStream(classDescriptor, &proto); + return; + } if (localInReg[reg].name == NULL || localInReg[reg].descriptor == NULL) { - goto invalid_stream; + invalidStream(classDescriptor, &proto); + return; } /* @@ -290,28 +299,36 @@ void dexDecodeDebugInfo( if (done) { // early exit - goto end; + return; } } break; } } } +} -end: - { - int reg; - for (reg = 0; reg < pCode->registersSize; reg++) { - emitLocalCbIfLive (cnxt, reg, insnsSize, localInReg, localCb); - } +// TODO optimize localCb == NULL case +void dexDecodeDebugInfo( + const DexFile* pDexFile, + const DexCode* pCode, + const char* classDescriptor, + u4 protoIdx, + u4 accessFlags, + DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb, + void* cnxt) +{ + const u1* stream = dexGetDebugInfoStream(pDexFile, pCode); + LocalInfo localInReg[pCode->registersSize]; + + memset(localInReg, 0, sizeof(LocalInfo) * pCode->registersSize); + + if (stream != NULL) { + dexDecodeDebugInfo0(pDexFile, pCode, classDescriptor, protoIdx, accessFlags, + posCb, localCb, cnxt, stream, localInReg); } - return; -invalid_stream: - IF_LOGE() { - char* methodDescriptor = dexProtoCopyMethodDescriptor(&proto); - LOGE("Invalid debug info stream. class %s; proto %s", - classDescriptor, methodDescriptor); - free(methodDescriptor); + for (int reg = 0; reg < pCode->registersSize; reg++) { + emitLocalCbIfLive(cnxt, reg, pCode->insnsSize, localInReg, localCb); } } diff --git a/libdex/DexDebugInfo.h b/libdex/DexDebugInfo.h index f23e36568..c510c5745 100644 --- a/libdex/DexDebugInfo.h +++ b/libdex/DexDebugInfo.h @@ -14,15 +14,19 @@ * limitations under the License. */ -#ifndef _LIBDEX_DEXDEBUGINFO -#define _LIBDEX_DEXDEBUGINFO - /* * Handling of method debug info in a .dex file. */ +#ifndef _LIBDEX_DEXDEBUGINFO +#define _LIBDEX_DEXDEBUGINFO + #include "DexFile.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Callback for "new position table entry". * Returning non-0 causes the decoder to stop early. @@ -52,4 +56,8 @@ void dexDecodeDebugInfo( DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb, void* cnxt); +#ifdef __cplusplus +} +#endif + #endif /* def _LIBDEX_DEXDEBUGINFO */ diff --git a/libdex/DexFile.c b/libdex/DexFile.cpp index 4f3bf5630..4f3bf5630 100644 --- a/libdex/DexFile.c +++ b/libdex/DexFile.cpp diff --git a/libdex/DexInlines.c b/libdex/DexInlines.cpp index cbedb6267..cbedb6267 100644 --- a/libdex/DexInlines.c +++ b/libdex/DexInlines.cpp diff --git a/libdex/DexOpcodes.c b/libdex/DexOpcodes.cpp index 50254a7e6..50254a7e6 100644 --- a/libdex/DexOpcodes.c +++ b/libdex/DexOpcodes.cpp diff --git a/libdex/DexOptData.c b/libdex/DexOptData.cpp index 10a4b5d29..131b6566f 100644 --- a/libdex/DexOptData.c +++ b/libdex/DexOptData.cpp @@ -50,7 +50,7 @@ bool dexParseOptData(const u1* data, size_t length, DexFile* pDexFile) { const void* pOptStart = data + pDexFile->pOptHeader->optOffset; const void* pOptEnd = data + length; - const u4* pOpt = pOptStart; + const u4* pOpt = (const u4*) pOptStart; u4 optLength = (const u1*) pOptEnd - (const u1*) pOptStart; /* diff --git a/libdex/DexProto.c b/libdex/DexProto.cpp index 25ab400d1..06c59b37d 100644 --- a/libdex/DexProto.c +++ b/libdex/DexProto.cpp @@ -45,7 +45,7 @@ void dexStringCacheAlloc(DexStringCache* pCache, size_t length) { pCache->value = pCache->buffer; pCache->allocatedSize = 0; } else { - pCache->value = malloc(length); + pCache->value = (char*) malloc(length); pCache->allocatedSize = length; } } diff --git a/libdex/DexSwapVerify.c b/libdex/DexSwapVerify.cpp index 5fd3f0906..13259370d 100644 --- a/libdex/DexSwapVerify.c +++ b/libdex/DexSwapVerify.cpp @@ -131,8 +131,8 @@ static inline bool checkPtrRange(const CheckState* state, * Assumes "const CheckState* state". */ #define CHECK_OFFSET_RANGE(_start, _end) { \ - const u1* _startPtr = filePointer(state, (_start)); \ - const u1* _endPtr = filePointer(state, (_end)); \ + const u1* _startPtr = (const u1*) filePointer(state, (_start)); \ + const u1* _endPtr = (const u1*) filePointer(state, (_end)); \ if (!checkPtrRange(state, _startPtr, _endPtr, \ #_start ".." #_end)) { \ return 0; \ @@ -332,7 +332,7 @@ static bool checkHeaderSection(const CheckState* state, u4 sectionOffset, return false; } - const DexHeader* pHeader = filePointer(state, 0); + const DexHeader* pHeader = (const DexHeader*) filePointer(state, 0); *endOffset = pHeader->headerSize; return true; } @@ -536,7 +536,7 @@ static bool checkMapSection(const CheckState* state, u4 sectionOffset, return false; } - const DexMapList* pMap = filePointer(state, sectionOffset); + const DexMapList* pMap = (const DexMapList*) filePointer(state, sectionOffset); *endOffset = sectionOffset + sizeof(u4) + (pMap->size * sizeof(DexMapItem)); @@ -545,7 +545,7 @@ static bool checkMapSection(const CheckState* state, u4 sectionOffset, /* Perform byte-swapping and intra-item verification on string_id_item. */ static void* swapStringIdItem(const CheckState* state, void* ptr) { - DexStringId* item = ptr; + DexStringId* item = (DexStringId*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_OFFSET4(item->stringDataOff); @@ -555,14 +555,14 @@ static void* swapStringIdItem(const CheckState* state, void* ptr) { /* Perform cross-item verification of string_id_item. */ static void* crossVerifyStringIdItem(const CheckState* state, void* ptr) { - const DexStringId* item = ptr; + const DexStringId* item = (const DexStringId*) ptr; if (!dexDataMapVerify(state->pDataMap, item->stringDataOff, kDexTypeStringDataItem)) { return NULL; } - const DexStringId* item0 = state->previousItem; + const DexStringId* item0 = (const DexStringId*) state->previousItem; if (item0 != NULL) { // Check ordering. const char* s0 = dexGetStringData(state->pDexFile, item0); @@ -578,7 +578,7 @@ static void* crossVerifyStringIdItem(const CheckState* state, void* ptr) { /* Perform byte-swapping and intra-item verification on type_id_item. */ static void* swapTypeIdItem(const CheckState* state, void* ptr) { - DexTypeId* item = ptr; + DexTypeId* item = (DexTypeId*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_INDEX4(item->descriptorIdx, state->pHeader->stringIdsSize); @@ -588,7 +588,7 @@ static void* swapTypeIdItem(const CheckState* state, void* ptr) { /* Perform cross-item verification of type_id_item. */ static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) { - const DexTypeId* item = ptr; + const DexTypeId* item = (const DexTypeId*) ptr; const char* descriptor = dexStringById(state->pDexFile, item->descriptorIdx); @@ -597,7 +597,7 @@ static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) { return NULL; } - const DexTypeId* item0 = state->previousItem; + const DexTypeId* item0 = (const DexTypeId*) state->previousItem; if (item0 != NULL) { // Check ordering. This relies on string_ids being in order. if (item0->descriptorIdx >= item->descriptorIdx) { @@ -612,7 +612,7 @@ static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) { /* Perform byte-swapping and intra-item verification on proto_id_item. */ static void* swapProtoIdItem(const CheckState* state, void* ptr) { - DexProtoId* item = ptr; + DexProtoId* item = (DexProtoId*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_INDEX4(item->shortyIdx, state->pHeader->stringIdsSize); @@ -669,7 +669,7 @@ static bool shortyDescMatch(char shorty, const char* descriptor, bool /* Perform cross-item verification of proto_id_item. */ static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) { - const DexProtoId* item = ptr; + const DexProtoId* item = (const DexProtoId*) ptr; const char* shorty = dexStringById(state->pDexFile, item->shortyIdx); @@ -715,7 +715,7 @@ static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) { return NULL; } - const DexProtoId* item0 = state->previousItem; + const DexProtoId* item0 = (const DexProtoId*) state->previousItem; if (item0 != NULL) { // Check ordering. This relies on type_ids being in order. if (item0->returnTypeIdx > item->returnTypeIdx) { @@ -762,7 +762,7 @@ static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) { /* Perform byte-swapping and intra-item verification on field_id_item. */ static void* swapFieldIdItem(const CheckState* state, void* ptr) { - DexFieldId* item = ptr; + DexFieldId* item = (DexFieldId*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_INDEX2(item->classIdx, state->pHeader->typeIdsSize); @@ -774,7 +774,7 @@ static void* swapFieldIdItem(const CheckState* state, void* ptr) { /* Perform cross-item verification of field_id_item. */ static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) { - const DexFieldId* item = ptr; + const DexFieldId* item = (const DexFieldId*) ptr; const char* s; s = dexStringByTypeIdx(state->pDexFile, item->classIdx); @@ -795,7 +795,7 @@ static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) { return NULL; } - const DexFieldId* item0 = state->previousItem; + const DexFieldId* item0 = (const DexFieldId*) state->previousItem; if (item0 != NULL) { // Check ordering. This relies on the other sections being in order. bool done = false; @@ -834,7 +834,7 @@ static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) { /* Perform byte-swapping and intra-item verification on method_id_item. */ static void* swapMethodIdItem(const CheckState* state, void* ptr) { - DexMethodId* item = ptr; + DexMethodId* item = (DexMethodId*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_INDEX2(item->classIdx, state->pHeader->typeIdsSize); @@ -846,7 +846,7 @@ static void* swapMethodIdItem(const CheckState* state, void* ptr) { /* Perform cross-item verification of method_id_item. */ static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) { - const DexMethodId* item = ptr; + const DexMethodId* item = (const DexMethodId*) ptr; const char* s; s = dexStringByTypeIdx(state->pDexFile, item->classIdx); @@ -861,7 +861,7 @@ static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) { return NULL; } - const DexMethodId* item0 = state->previousItem; + const DexMethodId* item0 = (const DexMethodId*) state->previousItem; if (item0 != NULL) { // Check ordering. This relies on the other sections being in order. bool done = false; @@ -900,7 +900,7 @@ static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) { /* Perform byte-swapping and intra-item verification on class_def_item. */ static void* swapClassDefItem(const CheckState* state, void* ptr) { - DexClassDef* item = ptr; + DexClassDef* item = (DexClassDef*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_INDEX4(item->classIdx, state->pHeader->typeIdsSize); @@ -928,7 +928,7 @@ static bool verifyClassDataIsForDef(const CheckState* state, u4 offset, return true; } - const u1* data = filePointer(state, offset); + const u1* data = (const u1*) filePointer(state, offset); DexClassData* classData = dexReadAndVerifyClassData(&data, NULL); if (classData == NULL) { @@ -957,7 +957,8 @@ static bool verifyAnnotationsDirectoryIsForDef(const CheckState* state, return true; } - const DexAnnotationsDirectoryItem* dir = filePointer(state, offset); + const DexAnnotationsDirectoryItem* dir = + (const DexAnnotationsDirectoryItem*) filePointer(state, offset); u4 annoDefiner = findFirstAnnotationsDirectoryDefiner(state, dir); return (annoDefiner == definerIdx) || (annoDefiner == kDexNoIndex); @@ -965,7 +966,7 @@ static bool verifyAnnotationsDirectoryIsForDef(const CheckState* state, /* Perform cross-item verification of class_def_item. */ static void* crossVerifyClassDefItem(const CheckState* state, void* ptr) { - const DexClassDef* item = ptr; + const DexClassDef* item = (const DexClassDef*) ptr; u4 classIdx = item->classIdx; const char* descriptor = dexStringByTypeIdx(state->pDexFile, classIdx); @@ -1146,7 +1147,7 @@ static u1* swapParameterAnnotations(const CheckState* state, u4 count, /* Perform byte-swapping and intra-item verification on * annotations_directory_item. */ static void* swapAnnotationsDirectoryItem(const CheckState* state, void* ptr) { - DexAnnotationsDirectoryItem* item = ptr; + DexAnnotationsDirectoryItem* item = (DexAnnotationsDirectoryItem*) ptr; CHECK_PTR_RANGE(item, item + 1); SWAP_OFFSET4(item->classAnnotationsOff); @@ -1276,7 +1277,7 @@ static u4 findFirstAnnotationsDirectoryDefiner(const CheckState* state, /* Perform cross-item verification of annotations_directory_item. */ static void* crossVerifyAnnotationsDirectoryItem(const CheckState* state, void* ptr) { - const DexAnnotationsDirectoryItem* item = ptr; + const DexAnnotationsDirectoryItem* item = (const DexAnnotationsDirectoryItem*) ptr; u4 definingClass = findFirstAnnotationsDirectoryDefiner(state, item); if (!dexDataMapVerify0Ok(state->pDataMap, @@ -1316,7 +1317,7 @@ static void* crossVerifyAnnotationsDirectoryItem(const CheckState* state, /* Perform byte-swapping and intra-item verification on type_list. */ static void* swapTypeList(const CheckState* state, void* ptr) { - DexTypeList* pTypeList = ptr; + DexTypeList* pTypeList = (DexTypeList*) ptr; DexTypeItem* pType; u4 count; @@ -1337,7 +1338,7 @@ static void* swapTypeList(const CheckState* state, void* ptr) /* Perform byte-swapping and intra-item verification on * annotation_set_ref_list. */ static void* swapAnnotationSetRefList(const CheckState* state, void* ptr) { - DexAnnotationSetRefList* list = ptr; + DexAnnotationSetRefList* list = (DexAnnotationSetRefList*) ptr; DexAnnotationSetRefItem* item; u4 count; @@ -1358,7 +1359,7 @@ static void* swapAnnotationSetRefList(const CheckState* state, void* ptr) { /* Perform cross-item verification of annotation_set_ref_list. */ static void* crossVerifyAnnotationSetRefList(const CheckState* state, void* ptr) { - const DexAnnotationSetRefList* list = ptr; + const DexAnnotationSetRefList* list = (const DexAnnotationSetRefList*) ptr; const DexAnnotationSetRefItem* item = list->list; int count = list->size; @@ -1376,7 +1377,7 @@ static void* crossVerifyAnnotationSetRefList(const CheckState* state, /* Perform byte-swapping and intra-item verification on * annotation_set_item. */ static void* swapAnnotationSetItem(const CheckState* state, void* ptr) { - DexAnnotationSetItem* set = ptr; + DexAnnotationSetItem* set = (DexAnnotationSetItem*) ptr; u4* item; u4 count; @@ -1403,7 +1404,7 @@ static u4 annotationItemTypeIdx(const DexAnnotationItem* item) { /* Perform cross-item verification of annotation_set_item. */ static void* crossVerifyAnnotationSetItem(const CheckState* state, void* ptr) { - const DexAnnotationSetItem* set = ptr; + const DexAnnotationSetItem* set = (const DexAnnotationSetItem*) ptr; int count = set->size; u4 lastIdx = 0; bool first = true; @@ -1545,7 +1546,7 @@ static bool verifyClassDataItem0(const CheckState* state, /* Perform intra-item verification on class_data_item. */ static void* intraVerifyClassDataItem(const CheckState* state, void* ptr) { - const u1* data = ptr; + const u1* data = (const u1*) ptr; DexClassData* classData = dexReadAndVerifyClassData(&data, state->fileEnd); if (classData == NULL) { @@ -1598,7 +1599,7 @@ static u4 findFirstClassDataDefiner(const CheckState* state, /* Perform cross-item verification of class_data_item. */ static void* crossVerifyClassDataItem(const CheckState* state, void* ptr) { - const u1* data = ptr; + const u1* data = (const u1*) ptr; DexClassData* classData = dexReadAndVerifyClassData(&data, state->fileEnd); u4 definingClass = findFirstClassDataDefiner(state, classData); bool okay = true; @@ -1798,7 +1799,7 @@ static void* swapTriesAndCatches(const CheckState* state, DexCode* code) { /* Perform byte-swapping and intra-item verification on code_item. */ static void* swapCodeItem(const CheckState* state, void* ptr) { - DexCode* item = ptr; + DexCode* item = (DexCode*) ptr; u2* insns; u4 count; @@ -1858,7 +1859,7 @@ static void* swapCodeItem(const CheckState* state, void* ptr) { /* Perform intra-item verification on string_data_item. */ static void* intraVerifyStringDataItem(const CheckState* state, void* ptr) { const u1* fileEnd = state->fileEnd; - const u1* data = ptr; + const u1* data = (const u1*) ptr; bool okay = true; u4 utf16Size = readAndVerifyUnsignedLeb128(&data, fileEnd, &okay); u4 i; @@ -1959,7 +1960,7 @@ static void* intraVerifyStringDataItem(const CheckState* state, void* ptr) { /* Perform intra-item verification on debug_info_item. */ static void* intraVerifyDebugInfoItem(const CheckState* state, void* ptr) { const u1* fileEnd = state->fileEnd; - const u1* data = ptr; + const u1* data = (const u1*) ptr; bool okay = true; u4 i; @@ -2341,7 +2342,7 @@ static void* intraVerifyEncodedArrayItem(const CheckState* state, void* ptr) { /* Perform intra-item verification on annotation_item. */ static void* intraVerifyAnnotationItem(const CheckState* state, void* ptr) { - const u1* data = ptr; + const u1* data = (const u1*) ptr; CHECK_PTR_RANGE(data, data + 1); @@ -2362,7 +2363,7 @@ static void* intraVerifyAnnotationItem(const CheckState* state, void* ptr) { /* Perform cross-item verification on annotation_item. */ static void* crossVerifyAnnotationItem(const CheckState* state, void* ptr) { - const u1* data = ptr; + const u1* data = (const u1*) ptr; // Skip the visibility byte. data++; @@ -2393,10 +2394,10 @@ static bool iterateSectionWithOptionalUpdate(CheckState* state, for (i = 0; i < count; i++) { u4 newOffset = (offset + alignmentMask) & ~alignmentMask; - u1* ptr = filePointer(state, newOffset); + u1* ptr = (u1*) filePointer(state, newOffset); if (offset < newOffset) { - ptr = filePointer(state, offset); + ptr = (u1*) filePointer(state, offset); if (offset < newOffset) { CHECK_OFFSET_RANGE(offset, newOffset); while (offset < newOffset) { @@ -2523,7 +2524,7 @@ static bool swapEverythingButHeaderAndMap(CheckState* state, if (lastOffset < sectionOffset) { CHECK_OFFSET_RANGE(lastOffset, sectionOffset); - const u1* ptr = filePointer(state, lastOffset); + const u1* ptr = (const u1*) filePointer(state, lastOffset); while (lastOffset < sectionOffset) { if (*ptr != '\0') { LOGE("Non-zero padding 0x%02x before section start @ %x\n", diff --git a/libdex/DexUtf.c b/libdex/DexUtf.cpp index df49d1831..df49d1831 100644 --- a/libdex/DexUtf.c +++ b/libdex/DexUtf.cpp diff --git a/libdex/InstrUtils.c b/libdex/InstrUtils.cpp index 3770c6da0..3770c6da0 100644 --- a/libdex/InstrUtils.c +++ b/libdex/InstrUtils.cpp diff --git a/libdex/Leb128.c b/libdex/Leb128.cpp index ed09e19aa..ed09e19aa 100644 --- a/libdex/Leb128.c +++ b/libdex/Leb128.cpp diff --git a/libdex/OptInvocation.c b/libdex/OptInvocation.cpp index df5f8d99f..df5f8d99f 100644 --- a/libdex/OptInvocation.c +++ b/libdex/OptInvocation.cpp diff --git a/libdex/OptInvocation.h b/libdex/OptInvocation.h index 0352eb423..151b1872e 100644 --- a/libdex/OptInvocation.h +++ b/libdex/OptInvocation.h @@ -32,7 +32,7 @@ char* dexOptGenerateCacheFileName(const char* fileName, int dexOptCreateEmptyHeader(int fd); #ifdef __cplusplus -}; +} #endif #endif /*_LIBDEX_OPTINVOCATION*/ diff --git a/libdex/SysUtil.c b/libdex/SysUtil.cpp index 951ca1d8a..951ca1d8a 100644 --- a/libdex/SysUtil.c +++ b/libdex/SysUtil.cpp diff --git a/libdex/ZipArchive.c b/libdex/ZipArchive.cpp index dd9dce4c2..29b665ed7 100644 --- a/libdex/ZipArchive.c +++ b/libdex/ZipArchive.cpp @@ -141,27 +141,16 @@ static u4 get4LE(unsigned char const* pSrc) return result; } -/* - * Find the zip Central Directory and memory-map it. - * - * On success, returns 0 after populating fields from the EOCD area: - * mDirectoryOffset - * mDirectoryMap - * mNumEntries - */ -static int mapCentralDirectory(int fd, const char* debugFileName, - ZipArchive* pArchive) +static int mapCentralDirectory0(int fd, const char* debugFileName, + ZipArchive* pArchive, u1* scanBuf) { - u1* scanBuf = NULL; - int result = -1; - /* * Get and test file length. */ off_t fileLength = lseek(fd, 0, SEEK_END); if (fileLength < kEOCDLen) { LOGV("Zip: length %ld is too small to be zip\n", (long) fileLength); - goto bail; + return -1; } /* @@ -184,12 +173,12 @@ static int mapCentralDirectory(int fd, const char* debugFileName, scanBuf = (u1*) malloc(readAmount); if (lseek(fd, searchStart, SEEK_SET) != searchStart) { LOGW("Zip: seek %ld failed: %s\n", (long) searchStart, strerror(errno)); - goto bail; + return -1; } ssize_t actual = TEMP_FAILURE_RETRY(read(fd, scanBuf, readAmount)); if (actual != (ssize_t) readAmount) { LOGW("Zip: read %zd failed: %s\n", readAmount, strerror(errno)); - goto bail; + return -1; } /* @@ -207,7 +196,7 @@ static int mapCentralDirectory(int fd, const char* debugFileName, } if (i < 0) { LOGD("Zip: EOCD not found, %s is not zip\n", debugFileName); - goto bail; + return -1; } off_t eocdOffset = searchStart + i; @@ -226,11 +215,11 @@ static int mapCentralDirectory(int fd, const char* debugFileName, if ((long long) dirOffset + (long long) dirSize > (long long) eocdOffset) { LOGW("Zip: bad offsets (dir %ld, size %u, eocd %ld)\n", (long) dirOffset, dirSize, (long) eocdOffset); - goto bail; + return -1; } if (numEntries == 0) { LOGW("Zip: empty archive?\n"); - goto bail; + return -1; } LOGV("+++ numEntries=%d dirSize=%d dirOffset=%d\n", @@ -244,15 +233,34 @@ static int mapCentralDirectory(int fd, const char* debugFileName, &pArchive->mDirectoryMap) != 0) { LOGW("Zip: cd map failed\n"); - goto bail; + return -1; } pArchive->mNumEntries = numEntries; pArchive->mDirectoryOffset = dirOffset; - result = 0; + return 0; +} + +/* + * Find the zip Central Directory and memory-map it. + * + * On success, returns 0 after populating fields from the EOCD area: + * mDirectoryOffset + * mDirectoryMap + * mNumEntries + */ +static int mapCentralDirectory(int fd, const char* debugFileName, + ZipArchive* pArchive) +{ + u1* scanBuf = (u1*) malloc(kMaxEOCDSearch); + + if (scanBuf == NULL) { + return -1; + } + + int result = mapCentralDirectory0(fd, debugFileName, pArchive, scanBuf); -bail: free(scanBuf); return result; } diff --git a/libdex/sha1.c b/libdex/sha1.cpp index dc7e30ae7..dc7e30ae7 100644 --- a/libdex/sha1.c +++ b/libdex/sha1.cpp |