BTW, The Microsoft Dictionary from the scrrun.dll uses next hashing algorithm for strings:
I make an analog for testing it in VB6:Code:INT CalcHashFromStringItem (BSTR bstrKey) { INT iResult = 0; for (INT i = 0; i < SysStringLen(bstrKey); i++) iResult = iResult * 17 + bstrKey[i]; iResult %= 1201; return iResult; }
Also i attached the project that allows make some tricks with MS Dictionary (sorting/get key/etc.). This knowledge had been obtained during reversing scrrun.dll code on Windows 7 x64 therefore it can distinct on the different platforms.Code:Option Explicit Private Declare Function GetMem4 Lib "msvbvm60" ( _ ByRef src As Any, _ ByRef Dst As Any) As Long Private Sub Form_Load() Dim sKey As String Dim pDic As Dictionary Dim index As Long Set pDic = New Dictionary For index = 0 To 10 sKey = MakeRandomString() Debug.Print pDic.HashVal(sKey), Dictionaty_HashVal(sKey) Next End Sub Private Function MakeRandomString() As String Dim l As Long: Dim i As Long l = Int(Rnd * 10) + 5 Do While l i = Int(Rnd * 62) Select Case i Case Is < 10 i = i + 48 Case Is < 36 i = i - 10 + 65 Case Else i = i - 36 + 97 End Select MakeRandomString = MakeRandomString & Chr$(i) l = l - 1 Loop End Function Private Function Dictionaty_HashVal( _ ByRef sValue As String) As Long Dim index As Long Dim result As Long #If COMPILED Then ' // We can't use unsigned arithmetic without overflow in IDE For index = 0 To Len(sValue) - 1 result = result * 17 + AscW(Mid$(sValue, index + 1, 1)) Next result = result Mod 1201 #Else ' // In order to bypass overflow error, we use currency 64-bit numbers Dim cResult As Currency For index = 0 To Len(sValue) - 1 cResult = cResult * 17 + AscW(Mid$(sValue, index + 1, 1)) / 10000@ ' // Zero high dword If cResult > 429496.7295@ Then GetMem4 0&, ByVal VarPtr(cResult) + 4 End If Next cResult = cResult * 10000@ result = cResult - Int(cResult / 1201@) * 1201@ #End If Dictionaty_HashVal = result End Function
![]()




Reply With Quote