From e2816e93b4656f1a05f1f663fe9beeb3275ddd7b Mon Sep 17 00:00:00 2001 From: Ladislav Date: Sat, 16 Mar 2013 19:02:34 +0100 Subject: + Test --- test/Test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Test.cpp b/test/Test.cpp index a4eb851..2932ee4 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -2157,7 +2157,7 @@ int main(void) // Mix the random number generator // srand(GetTickCount()); - FileStream_OpenFile(_T("e:\\Hry\\StarCraft II\\Updates\\SC2_HotS_20_BGDL\\SC2_HotS_20_BGDL_deDE.MPQE"), STREAM_PROVIDER_ENCRYPTED | BASE_PROVIDER_FILE); +// FileStream_OpenFile(_T("e:\\Hry\\StarCraft II\\Updates\\SC2_HotS_20_BGDL\\SC2_HotS_20_BGDL_deDE.MPQE"), STREAM_PROVIDER_ENCRYPTED | BASE_PROVIDER_FILE); // Test structure sizes // if(nError == ERROR_SUCCESS) -- cgit v1.2.3 From 34dc0f6a1ca3a44e2eefb215296cf60e64747137 Mon Sep 17 00:00:00 2001 From: Ladislav Date: Sat, 16 Mar 2013 19:05:54 +0100 Subject: + Test --- test/Test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Test.cpp b/test/Test.cpp index 2932ee4..20b225f 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -2157,6 +2157,7 @@ int main(void) // Mix the random number generator // srand(GetTickCount()); + // Test for encrypted streams // FileStream_OpenFile(_T("e:\\Hry\\StarCraft II\\Updates\\SC2_HotS_20_BGDL\\SC2_HotS_20_BGDL_deDE.MPQE"), STREAM_PROVIDER_ENCRYPTED | BASE_PROVIDER_FILE); // Test structure sizes -- cgit v1.2.3 From d5841d7438045215864a886de960b75bf0fb5e24 Mon Sep 17 00:00:00 2001 From: Ladislav Date: Sat, 23 Mar 2013 09:02:36 +0100 Subject: + When creating new MPQ, sector CRC is no longer omited if MPQ_FILE_SECTOR_CRC is present --- src/SBaseCommon.cpp | 54 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index b73a213..dfb60d4 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -1158,35 +1158,43 @@ int AllocateSectorChecksums(TMPQFile * hf, bool bLoadFromFile) // Does the size of the file table match with the CRC32-based checksums? dwExpectedSize = (hf->dwSectorCount + 2) * sizeof(DWORD); - if(hf->SectorOffsets[0] == dwExpectedSize) + if(hf->SectorOffsets[0] != 0 && hf->SectorOffsets[0] == dwExpectedSize) { - // Is there valid size of the sector checksums? - if(hf->SectorOffsets[hf->dwSectorCount + 1] >= hf->SectorOffsets[hf->dwSectorCount]) - dwCompressedSize = hf->SectorOffsets[hf->dwSectorCount + 1] - hf->SectorOffsets[hf->dwSectorCount]; - - // Ignore cases when the length is too small or too big. - if(dwCompressedSize < sizeof(DWORD) || dwCompressedSize > hf->dwSectorSize) - return ERROR_SUCCESS; - - // Allocate the array for the sector checksums - hf->SectorChksums = STORM_ALLOC(DWORD, hf->dwSectorCount); - if(hf->SectorChksums == NULL) - return ERROR_NOT_ENOUGH_MEMORY; - - // If we are not supposed to load it from the file, allocate empty buffer + // If we are not loading from the MPQ file, we just allocate the sector table + // In that case, do not check any sizes if(bLoadFromFile == false) { + hf->SectorChksums = STORM_ALLOC(DWORD, hf->dwSectorCount); + if(hf->SectorChksums == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + + // Fill the checksum table with zeros memset(hf->SectorChksums, 0, hf->dwSectorCount * sizeof(DWORD)); return ERROR_SUCCESS; } - - // Calculate offset of the CRC table - dwCrcSize = hf->dwSectorCount * sizeof(DWORD); - dwCrcOffset = hf->SectorOffsets[hf->dwSectorCount]; - CalculateRawSectorOffset(RawFilePos, hf, dwCrcOffset); - - // Now read the table from the MPQ - return LoadMpqTable(ha, RawFilePos, hf->SectorChksums, dwCompressedSize, dwCrcSize, 0); + else + { + // Is there valid size of the sector checksums? + if(hf->SectorOffsets[hf->dwSectorCount + 1] >= hf->SectorOffsets[hf->dwSectorCount]) + dwCompressedSize = hf->SectorOffsets[hf->dwSectorCount + 1] - hf->SectorOffsets[hf->dwSectorCount]; + + // Ignore cases when the length is too small or too big. + if(dwCompressedSize < sizeof(DWORD) || dwCompressedSize > hf->dwSectorSize) + return ERROR_SUCCESS; + + // Allocate the array for the sector checksums + hf->SectorChksums = STORM_ALLOC(DWORD, hf->dwSectorCount); + if(hf->SectorChksums == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + + // Calculate offset of the CRC table + dwCrcSize = hf->dwSectorCount * sizeof(DWORD); + dwCrcOffset = hf->SectorOffsets[hf->dwSectorCount]; + CalculateRawSectorOffset(RawFilePos, hf, dwCrcOffset); + + // Now read the table from the MPQ + return LoadMpqTable(ha, RawFilePos, hf->SectorChksums, dwCompressedSize, dwCrcSize, 0); + } } // If the size doesn't match, we ignore sector checksums -- cgit v1.2.3