MCPcopy Create free account
hub / github.com/diasurgical/devilution / HashString

Function HashString

3rdParty/StormLib/src/SBaseCommon.cpp:249–267  ·  view source on GitHub ↗

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 dwHash

Source from the content-addressed store, hash-verified

247// with Korean characters in the name, cannot open the file back.
248//
249DWORD HashString(const char * szFileName, DWORD dwHashType)
250{
251 LPBYTE pbKey = (BYTE *)szFileName;
252 DWORD dwSeed1 = 0x7FED7FED;
253 DWORD dwSeed2 = 0xEEEEEEEE;
254 DWORD ch;
255
256 while(*pbKey != 0)
257 {
258 // Convert the input character to uppercase
259 // Convert slash (0x2F) to backslash (0x5C)
260 ch = AsciiToUpperTable[*pbKey++];
261
262 dwSeed1 = StormBuffer[dwHashType + ch] ^ (dwSeed1 + dwSeed2);
263 dwSeed2 = ch + dwSeed1 + dwSeed2 + (dwSeed2 << 5) + 3;
264 }
265
266 return dwSeed1;
267}
268
269DWORD HashStringSlash(const char * szFileName, DWORD dwHashType)
270{

Callers 1

DecryptFileKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected