From 8a370dd9336540b8be585272182de0f74aac9241 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Fri, 15 Jul 2016 14:57:46 +0200 Subject: + Fixed workspace for storm_dll + Updated storm.dll from Warcraft 1.27 --- src/SBaseCommon.cpp | 17 ++++++++++++- storm_dll/Storm_dll.sln | 12 +-------- storm_dll/Storm_dll.vcproj | 60 ++++++++++++++++++++++---------------------- storm_dll/storm.dll | Bin 327680 -> 334312 bytes storm_dll/storm.lib | Bin 5238 -> 5238 bytes storm_dll/storm_test.cpp | 12 ++++++--- storm_dll/storm_test.vcproj | 18 ++++++------- test/StormTest.cpp | 9 ++++--- 8 files changed, 71 insertions(+), 57 deletions(-) diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index 02dc124..977664a 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -147,7 +147,6 @@ void StringCatT(TCHAR * dest, const TCHAR * src, size_t nMaxChars) // Storm hashing functions #define STORM_BUFFER_SIZE 0x500 - #define HASH_INDEX_MASK(ha) (ha->pHeader->dwHashTableSize ? (ha->pHeader->dwHashTableSize - 1) : 0) static DWORD StormBuffer[STORM_BUFFER_SIZE]; // Buffer for the decryption engine @@ -192,6 +191,22 @@ void InitializeMpqCryptography() } } +// +// Note: Implementation of this function in WorldEdit.exe and storm.dll +// incorrectly treats the character as signed, which leads to the +// a buffer underflow if the character in the file name >= 0x80: +// The following steps happen when *pbKey == 0xBF and dwHashType == 0x0000 +// (calculating hash index) +// +// 1) Result of AsciiToUpperTable_Slash[*pbKey++] is sign-extended to 0xffffffbf +// 2) The "ch" is added to dwHashType (0xffffffbf + 0x0000 => 0xffffffbf) +// 3) The result is used as index to the StormBuffer table, +// thus dereferences a random value BEFORE the begin of StormBuffer. +// +// As result, MPQs containing files with non-ANSI characters will not work between +// various game versions and localizations. Even WorldEdit, after importing a file +// with Korean characters in the name, cannot open the file back. +// DWORD HashString(const char * szFileName, DWORD dwHashType) { LPBYTE pbKey = (BYTE *)szFileName; diff --git a/storm_dll/Storm_dll.sln b/storm_dll/Storm_dll.sln index 2641f65..4f78087 100644 --- a/storm_dll/Storm_dll.sln +++ b/storm_dll/Storm_dll.sln @@ -1,8 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Storm_dll", "Storm_dll.vcproj", "{BD600973-C6FA-4CE3-8821-67F6418B7F9C}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PhotoSort", "Storm_test.vcproj", "{5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "storm_dll", "storm_dll.vcproj", "{BD600973-C6FA-4CE3-8821-67F6418B7F9C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -20,14 +18,6 @@ Global {BD600973-C6FA-4CE3-8821-67F6418B7F9C}.Release|Win32.Build.0 = Release|Win32 {BD600973-C6FA-4CE3-8821-67F6418B7F9C}.Release|x64.ActiveCfg = Release|x64 {BD600973-C6FA-4CE3-8821-67F6418B7F9C}.Release|x64.Build.0 = Release|x64 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Debug|Win32.ActiveCfg = Debug|Win32 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Debug|Win32.Build.0 = Debug|Win32 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Debug|x64.ActiveCfg = Debug|x64 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Debug|x64.Build.0 = Debug|x64 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Release|Win32.ActiveCfg = Release|Win32 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Release|Win32.Build.0 = Release|Win32 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Release|x64.ActiveCfg = Release|x64 - {5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/storm_dll/Storm_dll.vcproj b/storm_dll/Storm_dll.vcproj index 394d367..da9a11d 100644 --- a/storm_dll/Storm_dll.vcproj +++ b/storm_dll/Storm_dll.vcproj @@ -2,9 +2,9 @@ @@ -44,10 +44,10 @@ diff --git a/storm_dll/storm.dll b/storm_dll/storm.dll index d4daca0..e35fc12 100644 Binary files a/storm_dll/storm.dll and b/storm_dll/storm.dll differ diff --git a/storm_dll/storm.lib b/storm_dll/storm.lib index 299a6d4..64d3561 100644 Binary files a/storm_dll/storm.lib and b/storm_dll/storm.lib differ diff --git a/storm_dll/storm_test.cpp b/storm_dll/storm_test.cpp index 4c69443..5e498b3 100644 --- a/storm_dll/storm_test.cpp +++ b/storm_dll/storm_test.cpp @@ -22,15 +22,21 @@ //----------------------------------------------------------------------------- // Main +unsigned char szKoreanFileName[] = {0x77, 0x61, 0x72, 0x33, 0x6D, 0x61, 0x70, 0x49, 0x6D, 0x70, 0x6F, 0x72, 0x74, 0x65, 0x64, 0x5C, 0xBF, 0xD5, 0xB1, 0xB9, 0x2E, 0x6D, 0x70, 0x33, 0x00}; + int main() { + LPCSTR szArchiveName = "e:\\MPQ_2016_v1_KoreanFile.w3m"; HANDLE hMpq = NULL; HANDLE hFile = NULL; + char szFileName[MAX_PATH]; + + _asm int 3; - if(StormOpenArchive("e:\\Multimedia\\MPQs\\1995 - Test MPQs\\MPQ_2015_v1_MessListFile.mpq", 0, 0, &hMpq)) + if(StormOpenArchive(szArchiveName, 0, 0, &hMpq)) { - _asm int 3; - if(StormOpenFileEx(hMpq, "\\\\\\*¹BTNGoblinPyrotechnician.blp", 0, &hFile)) + memcpy(szFileName, szKoreanFileName, _countof(szKoreanFileName)); + if(StormOpenFileEx(hMpq, szFileName, 0, &hFile)) { StormCloseFile(hFile); } diff --git a/storm_dll/storm_test.vcproj b/storm_dll/storm_test.vcproj index 571ad8e..0af7b89 100644 --- a/storm_dll/storm_test.vcproj +++ b/storm_dll/storm_test.vcproj @@ -2,9 +2,9 @@ @@ -65,11 +65,11 @@ /> diff --git a/test/StormTest.cpp b/test/StormTest.cpp index eb3f665..410dfd4 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4397,7 +4397,7 @@ int main(int argc, char * argv[]) // Open a MPK archive from Longwu online if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPx_2013_v1_LongwuOnline.mpk"); -*/ + // Open a SQP archive from War of the Immortals if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPx_2013_v1_WarOfTheImmortals.sqp", "ListFile_WarOfTheImmortals.txt"); @@ -4470,7 +4470,10 @@ int main(int argc, char * argv[]) if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPQ_2016_v1_ProtectedMap_1.4.w3x"); - +*/ + if(nError == ERROR_SUCCESS) + nError = TestOpenArchive("MPQ_2016_v1_KoreanFile.w3m"); +/* // Open the multi-file archive with wrong prefix to see how StormLib deals with it if(nError == ERROR_SUCCESS) nError = TestOpenArchive_WillFail("flat-file://streaming/model.MPQ.0"); @@ -4673,7 +4676,7 @@ int main(int argc, char * argv[]) // Test replacing a file with zero size file if(nError == ERROR_SUCCESS) nError = TestModifyArchive_ReplaceFile("MPQ_2014_v4_Base.StormReplay", "AddFile-replay.message.events"); - +*/ #ifdef _MSC_VER _CrtDumpMemoryLeaks(); #endif // _MSC_VER -- cgit v1.2.3