diff options
-rw-r--r-- | src/SBaseCommon.cpp | 17 | ||||
-rw-r--r-- | storm_dll/Storm_dll.sln | 12 | ||||
-rw-r--r-- | storm_dll/Storm_dll.vcproj | 60 | ||||
-rw-r--r-- | storm_dll/storm.dll | bin | 327680 -> 334312 bytes | |||
-rw-r--r-- | storm_dll/storm.lib | bin | 5238 -> 5238 bytes | |||
-rw-r--r-- | storm_dll/storm_test.cpp | 12 | ||||
-rw-r--r-- | storm_dll/storm_test.vcproj | 18 | ||||
-rw-r--r-- | 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 @@ <VisualStudioProject ProjectType="Visual C++" Version="9,00" - Name="Storm_dll" + Name="storm_dll" ProjectGUID="{BD600973-C6FA-4CE3-8821-67F6418B7F9C}" - RootNamespace="Storm_dll" + RootNamespace="storm_dll" Keyword="Win32Proj" TargetFrameworkVersion="131072" > @@ -44,10 +44,10 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;Storm_dll_EXPORTS" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;storm_dll_EXPORTS" MinimalRebuild="true" BasicRuntimeChecks="3" - RuntimeLibrary="3" + RuntimeLibrary="0" UsePrecompiledHeader="0" WarningLevel="3" DebugInformationFormat="4" @@ -66,7 +66,7 @@ OutputFile="$(OutDir)\storm.dll" LinkIncremental="2" GenerateManifest="false" - ModuleDefinitionFile=".\Storm_dll.def" + ModuleDefinitionFile=".\storm_dll.def" GenerateDebugInformation="true" SubSystem="2" BaseAddress="0x15000000" @@ -94,16 +94,15 @@ /> <Tool Name="VCPostBuildEventTool" - CommandLine="Storm_dll.bat $(PlatformName) $(ConfigurationName)" + CommandLine="" /> </Configuration> <Configuration - Name="Release|Win32" + Name="Debug|x64" OutputDirectory=".\bin\$(PlatformName)\$(ConfigurationName)" IntermediateDirectory=".\bin\$(PlatformName)\$(ConfigurationName)" ConfigurationType="2" CharacterSet="1" - WholeProgramOptimization="1" > <Tool Name="VCPreBuildEventTool" @@ -119,11 +118,15 @@ /> <Tool Name="VCMIDLTool" + TargetEnvironment="3" /> <Tool Name="VCCLCompilerTool" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;Storm_dll_EXPORTS" - RuntimeLibrary="2" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;storm_dll_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" UsePrecompiledHeader="0" WarningLevel="3" DebugInformationFormat="3" @@ -140,17 +143,15 @@ <Tool Name="VCLinkerTool" OutputFile="$(OutDir)\storm.dll" - LinkIncremental="1" + LinkIncremental="2" GenerateManifest="false" - ModuleDefinitionFile=".\Storm_dll.def" + ModuleDefinitionFile=".\storm_dll.def" GenerateDebugInformation="true" SubSystem="2" - OptimizeReferences="2" - EnableCOMDATFolding="2" BaseAddress="0x15000000" RandomizedBaseAddress="1" DataExecutionPrevention="0" - TargetMachine="1" + TargetMachine="17" /> <Tool Name="VCALinkTool" @@ -172,15 +173,16 @@ /> <Tool Name="VCPostBuildEventTool" - CommandLine="Storm_dll.bat $(PlatformName) $(ConfigurationName)" + CommandLine="storm_dll.bat $(PlatformName) $(ConfigurationName)" /> </Configuration> <Configuration - Name="Debug|x64" + Name="Release|Win32" OutputDirectory=".\bin\$(PlatformName)\$(ConfigurationName)" IntermediateDirectory=".\bin\$(PlatformName)\$(ConfigurationName)" ConfigurationType="2" CharacterSet="1" + WholeProgramOptimization="1" > <Tool Name="VCPreBuildEventTool" @@ -196,15 +198,11 @@ /> <Tool Name="VCMIDLTool" - TargetEnvironment="3" /> <Tool Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;Storm_dll_EXPORTS" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;storm_dll_EXPORTS" + RuntimeLibrary="0" UsePrecompiledHeader="0" WarningLevel="3" DebugInformationFormat="3" @@ -221,15 +219,17 @@ <Tool Name="VCLinkerTool" OutputFile="$(OutDir)\storm.dll" - LinkIncremental="2" + LinkIncremental="1" GenerateManifest="false" - ModuleDefinitionFile=".\Storm_dll.def" + ModuleDefinitionFile=".\storm_dll.def" GenerateDebugInformation="true" SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" BaseAddress="0x15000000" RandomizedBaseAddress="1" DataExecutionPrevention="0" - TargetMachine="17" + TargetMachine="1" /> <Tool Name="VCALinkTool" @@ -251,7 +251,7 @@ /> <Tool Name="VCPostBuildEventTool" - CommandLine="Storm_dll.bat $(PlatformName) $(ConfigurationName)" + CommandLine="" /> </Configuration> <Configuration @@ -280,7 +280,7 @@ /> <Tool Name="VCCLCompilerTool" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;Storm_dll_EXPORTS" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;storm_dll_EXPORTS" RuntimeLibrary="2" UsePrecompiledHeader="0" WarningLevel="3" @@ -300,7 +300,7 @@ OutputFile="$(OutDir)\storm.dll" LinkIncremental="1" GenerateManifest="false" - ModuleDefinitionFile=".\Storm_dll.def" + ModuleDefinitionFile=".\storm_dll.def" GenerateDebugInformation="true" SubSystem="2" OptimizeReferences="2" @@ -330,7 +330,7 @@ /> <Tool Name="VCPostBuildEventTool" - CommandLine="Storm_dll.bat $(PlatformName) $(ConfigurationName)" + CommandLine="storm_dll.bat $(PlatformName) $(ConfigurationName)" /> </Configuration> </Configurations> diff --git a/storm_dll/storm.dll b/storm_dll/storm.dll Binary files differindex d4daca0..e35fc12 100644 --- a/storm_dll/storm.dll +++ b/storm_dll/storm.dll diff --git a/storm_dll/storm.lib b/storm_dll/storm.lib Binary files differindex 299a6d4..64d3561 100644 --- a/storm_dll/storm.lib +++ b/storm_dll/storm.lib 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 @@ <VisualStudioProject ProjectType="Visual C++" Version="9,00" - Name="Storm_test" + Name="storm_test" ProjectGUID="{5B0E680A-EC4E-402E-AE0D-18ADD2DC6EBE}" - RootNamespace="Storm_test" + RootNamespace="storm_test" Keyword="Win32Proj" TargetFrameworkVersion="131072" > @@ -65,11 +65,11 @@ /> <Tool Name="VCLinkerTool" - OutputFile="$(OutDir)/Storm_test.exe" + OutputFile="$(OutDir)/storm_test.exe" LinkIncremental="2" AdditionalLibraryDirectories="../aaa/lib32" GenerateDebugInformation="true" - ProgramDatabaseFile="$(OutDir)/Storm_test.pdb" + ProgramDatabaseFile="$(OutDir)/storm_test.pdb" SubSystem="1" RandomizedBaseAddress="1" DataExecutionPrevention="0" @@ -144,11 +144,11 @@ /> <Tool Name="VCLinkerTool" - OutputFile="$(OutDir)/Storm_test.exe" + OutputFile="$(OutDir)/storm_test.exe" LinkIncremental="2" AdditionalLibraryDirectories="../aaa/lib64" GenerateDebugInformation="true" - ProgramDatabaseFile="$(OutDir)/Storm_test.pdb" + ProgramDatabaseFile="$(OutDir)/storm_test.pdb" SubSystem="1" RandomizedBaseAddress="1" DataExecutionPrevention="0" @@ -219,7 +219,7 @@ /> <Tool Name="VCLinkerTool" - OutputFile="$(OutDir)/Storm_test.exe" + OutputFile="$(OutDir)/storm_test.exe" LinkIncremental="1" AdditionalLibraryDirectories="../aaa/lib32" GenerateDebugInformation="true" @@ -297,7 +297,7 @@ /> <Tool Name="VCLinkerTool" - OutputFile="$(OutDir)/Storm_test.exe" + OutputFile="$(OutDir)/storm_test.exe" LinkIncremental="1" AdditionalLibraryDirectories="../aaa/lib64" GenerateDebugInformation="true" @@ -341,7 +341,7 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File - RelativePath=".\Storm_test.cpp" + RelativePath=".\storm_test.cpp" > </File> </Filter> 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
|