diff options
-rw-r--r-- | src/SBaseCommon.cpp | 12 | ||||
-rw-r--r-- | src/SFileVerify.cpp | 6 | ||||
-rw-r--r-- | src/StormCommon.h | 1 | ||||
-rw-r--r-- | test/StormTest.cpp | 5 |
4 files changed, 22 insertions, 2 deletions
diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index ed31a61..23c9833 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -1509,6 +1509,18 @@ bool IsValidMD5(LPBYTE pbMd5) return (Md5[0] | Md5[1] | Md5[2] | Md5[3]) ? true : false; } +bool IsValidSignature(LPBYTE pbSignature) +{ + LPDWORD Signature = (LPDWORD)pbSignature; + DWORD SigValid = 0; + + for(int i = 0; i < MPQ_WEAK_SIGNATURE_SIZE / sizeof(DWORD); i++) + SigValid |= Signature[i]; + + return (SigValid != 0) ? true : false; +} + + bool VerifyDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5) { hash_state md5_state; diff --git a/src/SFileVerify.cpp b/src/SFileVerify.cpp index cff2a81..65bad00 100644 --- a/src/SFileVerify.cpp +++ b/src/SFileVerify.cpp @@ -442,6 +442,10 @@ static DWORD VerifyWeakSignature( int hash_idx = find_hash("md5"); int result = 0; + // The signature might be zeroed out. In that case, we ignore it + if(!IsValidSignature(pSI->Signature)) + return ERROR_WEAK_SIGNATURE_OK; + // Calculate hash of the entire archive, skipping the (signature) file if(!CalculateMpqHashMd5(ha, pSI, Md5Digest)) return ERROR_VERIFY_FAILED; @@ -746,8 +750,8 @@ bool QueryMpqSignatureInfo( if(!FileStream_Read(ha->pStream, &pSI->BeginExclude, pSI->Signature, dwFileSize)) return false; - pSI->cbSignatureSize = dwFileSize; pSI->SignatureTypes |= SIGNATURE_TYPE_WEAK; + pSI->cbSignatureSize = dwFileSize; return true; } } diff --git a/src/StormCommon.h b/src/StormCommon.h index cdca0b0..93193cf 100644 --- a/src/StormCommon.h +++ b/src/StormCommon.h @@ -158,6 +158,7 @@ DWORD DetectFileKeyByContent(void * pvEncryptedData, DWORD dwSectorSize, DWORD d DWORD DecryptFileKey(const char * szFileName, ULONGLONG MpqPos, DWORD dwFileSize, DWORD dwFlags); bool IsValidMD5(LPBYTE pbMd5); +bool IsValidSignature(LPBYTE pbSignature); bool VerifyDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5); void CalculateDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE md5_hash); diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 5031322..48beea5 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4102,7 +4102,7 @@ int main(int argc, char * argv[]) // Open an Warcraft III map locked by the BOBA protector if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPQ_2002_v1_ProtectedMap_BOBA.w3m"); -*/ + // Open an Warcraft III map locked by a protector if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPQ_2015_v1_ProtectedMap_KangTooJee.w3x"); @@ -4198,6 +4198,9 @@ int main(int argc, char * argv[]) // Check archive signature if(nError == ERROR_SUCCESS) nError = TestOpenArchive_VerifySignature("MPQ_1999_v1_WeakSignature.exe", "War2Patch_202.exe"); +*/ + if(nError == ERROR_SUCCESS) + nError = TestOpenArchive_VerifySignature("MPQ_2003_v1_WeakSignatureEmpty.exe", "WoW-1.2.3.4211-enUS-patch.exe"); // Check archive signature if(nError == ERROR_SUCCESS) |