diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-11-25 09:24:01 +0100 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-11-25 09:24:01 +0100 |
commit | 495b2ab3d42db3f0d484e76eba15c7da9148d53a (patch) | |
tree | 0b479f6faf26ae3846328a25beabfff5dae6718f | |
parent | eec75473b71cba0363dcb4c6985e92b266144ce5 (diff) |
+ Fixed bug in processing HET table
-rw-r--r-- | doc/History.txt | 4 | ||||
-rw-r--r-- | src/SBaseFileTable.cpp | 10 | ||||
-rw-r--r-- | src/StormLib.h | 5 | ||||
-rw-r--r-- | test/StormTest.cpp | 50 |
4 files changed, 61 insertions, 8 deletions
diff --git a/doc/History.txt b/doc/History.txt index 6c20d2b..b6a098c 100644 --- a/doc/History.txt +++ b/doc/History.txt @@ -2,6 +2,10 @@ StormLib history ================ + Version 9.11 + + - Fixed bug in processing HET table. + Version 9.10 - Support for weak-signing diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index 906edce..2d6249f 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -1115,7 +1115,7 @@ static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWOR BYTE NameHash1; // Get the start index and the high 8 bits of the name hash - StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwEntryCount); + StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwTotalCount); NameHash1 = (BYTE)(FileNameHash >> (pHetTable->dwNameHashBitSize - 8)); // Find a place where to put it @@ -1137,7 +1137,7 @@ static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWOR // Move to the next entry in the HET table // If we came to the start index again, we are done - Index = (Index + 1) % pHetTable->dwEntryCount; + Index = (Index + 1) % pHetTable->dwTotalCount; if(Index == StartIndex) break; } @@ -1257,7 +1257,7 @@ DWORD GetFileIndex_Het(TMPQArchive * ha, const char * szFileName) NameHash1 = (BYTE)(FileNameHash >> (pHetTable->dwNameHashBitSize - 8)); // Calculate the starting index to the hash table - StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwEntryCount); + StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwTotalCount); // Go through HET table until we find a terminator while(pHetTable->pNameHashes[Index] != HET_ENTRY_FREE) @@ -1286,7 +1286,7 @@ DWORD GetFileIndex_Het(TMPQArchive * ha, const char * szFileName) // Move to the next entry in the HET table // If we came to the start index again, we are done - Index = (Index + 1) % pHetTable->dwEntryCount; + Index = (Index + 1) % pHetTable->dwTotalCount; if(Index == StartIndex) break; } @@ -2438,7 +2438,7 @@ int BuildFileTable_HetBet( return ERROR_FILE_CORRUPT; // Step one: Fill the name indexes - for(i = 0; i < pHetTable->dwEntryCount; i++) + for(i = 0; i < pHetTable->dwTotalCount; i++) { DWORD dwFileIndex = 0; diff --git a/src/StormLib.h b/src/StormLib.h index 3ea3e19..c543563 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -69,6 +69,7 @@ /* 14.01.13 8.21 Lad ADPCM and Huffmann (de)compression refactored */ /* 04.12.13 9.00 Lad Unit tests, bug fixes */ /* 27.08.14 9.10 Lad Signing archives with weak digital signature */ +/* 25.11.14 9.11 Lad Fixed bug reading & creating HET table */ /*****************************************************************************/ #ifndef __STORMLIB_H__ @@ -133,8 +134,8 @@ extern "C" { //----------------------------------------------------------------------------- // Defines -#define STORMLIB_VERSION 0x090A // Current version of StormLib (9.1) -#define STORMLIB_VERSION_STRING "9.10" // String version of StormLib version +#define STORMLIB_VERSION 0x090B // Current version of StormLib (9.11) +#define STORMLIB_VERSION_STRING "9.11" // String version of StormLib version #define ID_MPQ 0x1A51504D // MPQ archive header ID ('MPQ\x1A') #define ID_MPQ_USERDATA 0x1B51504D // MPQ userdata entry ('MPQ\x1B') diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 66adcf5..a489ecc 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -3754,6 +3754,50 @@ static int TestCreateArchive_BigArchive(const char * szPlainName) return nError; } +// "MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events" +static int TestModifyArchive_ReplaceFile(const char * szPlainName, const char * szFileName) +{ + TLogHelper Logger("ModifyTest"); + HANDLE hMpq = NULL; + HANDLE hFile = NULL; + const char * szArchivedName; + char szLocalFileName[MAX_PATH]; + size_t nOffset = 0; + int nError; + + // Open an existing archive + nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq); + + // Add the given file + if(nError == ERROR_SUCCESS) + { + // Get the name of archived file + if(!_strnicmp(szFileName, "AddFile-", 8)) + nOffset = 8; + szArchivedName = szFileName + nOffset; + + // Just for test - try to open the file in the archive + if(SFileOpenFileEx(hMpq, szArchivedName, 0, &hFile)) + SFileCloseFile(hFile); + + // Create the local file name + CreateFullPathName(szLocalFileName, szMpqSubDir, szFileName); + + // Add the file to MPQ + nError = AddLocalFileToMpq(&Logger, hMpq, + szArchivedName, + szLocalFileName, + MPQ_FILE_REPLACEEXISTING | MPQ_FILE_COMPRESS | MPQ_FILE_SINGLE_UNIT, + MPQ_COMPRESSION_ZLIB, + true); + } + + // Close the MPQ + if(hMpq != NULL) + SFileCloseArchive(hMpq); + return nError; +} + //----------------------------------------------------------------------------- // Comparing two directories, creating links @@ -4005,7 +4049,7 @@ int main(int argc, char * argv[]) // Open a patched archive. if(nError == ERROR_SUCCESS) nError = TestOpenArchive_Patched(PatchList_WoW_16965, "DBFilesClient\\BattlePetNPCTeamMember.db2", 0); -*/ + // Open a patched archive. if(nError == ERROR_SUCCESS) nError = TestOpenArchive_Patched(PatchList_SC2_32283, "TriggerLibs\\natives.galaxy", 6); @@ -4144,6 +4188,10 @@ int main(int argc, char * argv[]) // Open a MPQ (add custom user data to it) if(nError == ERROR_SUCCESS) nError = TestCreateArchive_BigArchive("StormLibTest_BigArchive_v4.mpq"); +*/ + // Test modifying a replay file from Heroes of the Storm + if(nError == ERROR_SUCCESS) + nError = TestModifyArchive_ReplaceFile("MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events"); return nError; } |