Leaked source code of windows server 2003
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.

58 lines
1.7 KiB

  1. #include <nt.h>
  2. #include <windef.h>
  3. #include <malloc.h>
  4. PKEY_NAME_INFORMATION GetRegKeyInfo(HKEY hKey)
  5. {
  6. ULONG nRequiredSize = sizeof(KEY_NAME_INFORMATION) + MAX_PATH;
  7. PKEY_NAME_INFORMATION pKeyInfo =
  8. (PKEY_NAME_INFORMATION)malloc(nRequiredSize);
  9. if (!pKeyInfo) return NULL;
  10. NTSTATUS Status = NtQueryKey(hKey,
  11. KeyNameInformation,
  12. pKeyInfo,
  13. nRequiredSize,
  14. &nRequiredSize);
  15. if (Status == STATUS_BUFFER_OVERFLOW) {
  16. PKEY_NAME_INFORMATION pNewKeyInfo =
  17. (PKEY_NAME_INFORMATION)realloc(pKeyInfo, nRequiredSize);
  18. if (pNewKeyInfo) {
  19. pKeyInfo = pNewKeyInfo;
  20. Status = NtQueryKey(hKey,
  21. KeyNameInformation,
  22. pKeyInfo,
  23. nRequiredSize,
  24. &nRequiredSize);
  25. }
  26. }
  27. if (!NT_SUCCESS(Status)) {
  28. free(pKeyInfo);
  29. pKeyInfo = NULL;
  30. }
  31. return pKeyInfo;
  32. }
  33. bool IsTheSameRegKey(HKEY hKey1, HKEY hKey2)
  34. {
  35. PKEY_NAME_INFORMATION pKeyInfo1 = GetRegKeyInfo(hKey1);
  36. PKEY_NAME_INFORMATION pKeyInfo2 = GetRegKeyInfo(hKey2);
  37. bool bTheSame = pKeyInfo1 && pKeyInfo2 &&
  38. (pKeyInfo1->NameLength == pKeyInfo2->NameLength) &&
  39. !_wcsnicmp(pKeyInfo1->Name,
  40. pKeyInfo2->Name,
  41. pKeyInfo1->NameLength);
  42. free(pKeyInfo1);
  43. free(pKeyInfo2);
  44. return bTheSame;
  45. }