Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.8 KiB

  1. #include <windows.h>
  2. #include <shlwapi.h>
  3. #include <idp.h>
  4. #include <idaux.h>
  5. ULONG
  6. FusionpDbgPrintEx(
  7. ULONG Level,
  8. PCSTR Format,
  9. ...
  10. )
  11. {
  12. return 0;
  13. }
  14. int
  15. FusionpCompareStrings(
  16. PCWSTR psz1,
  17. SIZE_T cch1,
  18. PCWSTR psz2,
  19. SIZE_T cch2,
  20. bool fCaseInsensitive
  21. )
  22. {
  23. if (fCaseInsensitive)
  24. return StrCmpI(psz1, psz2);
  25. else
  26. return StrCmp(psz1, psz2);
  27. }
  28. BOOL
  29. FusionpHashUnicodeString(
  30. PCWSTR String,
  31. SIZE_T cch,
  32. PULONG HashValue,
  33. DWORD dwCmpFlags
  34. )
  35. {
  36. BOOL fSuccess = FALSE;
  37. FN_TRACE_WIN32(fSuccess);
  38. ULONG TmpHashValue = 0;
  39. if (HashValue != NULL)
  40. *HashValue = 0;
  41. //PARAMETER_CHECK((dwCmpFlags == 0) || (dwCmpFlags == (NORM_IGNORECASE|SORT_STRINGSORT))); // ?safe
  42. PARAMETER_CHECK((dwCmpFlags == 0) || (dwCmpFlags & NORM_IGNORECASE)); // ?safe
  43. PARAMETER_CHECK(HashValue != NULL);
  44. if (dwCmpFlags & NORM_IGNORECASE)
  45. dwCmpFlags |= SORT_STRINGSORT;
  46. //
  47. // Note that if you change this implementation, you have to have the implementation inside
  48. // ntdll change to match it. Since that's hard and will affect everyone else in the world,
  49. // DON'T CHANGE THIS ALGORITHM NO MATTER HOW GOOD OF AN IDEA IT SEEMS TO BE! This isn't the
  50. // most perfect hashing algorithm, but its stability is critical to being able to match
  51. // previously persisted hash values.
  52. //
  53. if (dwCmpFlags & NORM_IGNORECASE)
  54. {
  55. while (cch-- != 0)
  56. {
  57. WCHAR Char = *String++;
  58. TmpHashValue = (TmpHashValue * 65599) + (WCHAR) ::CharUpperW((PWSTR) Char);
  59. }
  60. }
  61. else
  62. {
  63. while (cch-- != 0)
  64. TmpHashValue = (TmpHashValue * 65599) + *String++;
  65. }
  66. *HashValue = TmpHashValue;
  67. fSuccess = TRUE;
  68. Exit:
  69. return fSuccess;
  70. }