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.

104 lines
2.4 KiB

  1. #include "precomp.h"
  2. // This module has been given an official blessing to use the str routines.
  3. #include "LegalStr.h"
  4. IMPLEMENT_SHIM_BEGIN(Win2kPropagateLayer)
  5. #include "ShimHookMacro.h"
  6. #include <stdarg.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #define APPCOMPAT_KEYW L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager\\AppCompatibility"
  10. BOOL
  11. CleanupRegistryForCurrentExe(
  12. void
  13. )
  14. {
  15. NTSTATUS status;
  16. OBJECT_ATTRIBUTES objA;
  17. HANDLE hkey;
  18. WCHAR wszExeName[MAX_PATH];
  19. WCHAR wszKey[MAX_PATH];
  20. UNICODE_STRING strKey;
  21. UNICODE_STRING strValue;
  22. DWORD dwChars = GetModuleFileNameW(NULL, wszExeName, MAX_PATH);
  23. if (dwChars == 0) {
  24. return FALSE;
  25. }
  26. WCHAR* pwsz = wszExeName + dwChars;
  27. while (pwsz >= wszExeName) {
  28. if (*pwsz == '\\') {
  29. break;
  30. }
  31. pwsz--;
  32. }
  33. pwsz++;
  34. LOGN(
  35. eDbgLevelInfo,
  36. "[CleanupRegistryForCurrentExe] Cleanup for \"%S\"",
  37. pwsz);
  38. swprintf(wszKey, L"%s\\%s", APPCOMPAT_KEYW, pwsz);
  39. RtlInitUnicodeString(&strKey, wszKey);
  40. InitializeObjectAttributes(&objA,
  41. &strKey,
  42. OBJ_CASE_INSENSITIVE,
  43. NULL,
  44. NULL);
  45. status = NtOpenKey(&hkey,
  46. MAXIMUM_ALLOWED,
  47. &objA);
  48. if (!NT_SUCCESS(status)) {
  49. LOGN(
  50. eDbgLevelError,
  51. "[CleanupRegistryForCurrentExe] Failed to open key \"%S\"",
  52. wszKey);
  53. return TRUE;
  54. }
  55. RtlInitUnicodeString(&strValue, L"DllPatch-y");
  56. NtDeleteValueKey(hkey, &strValue);
  57. RtlInitUnicodeString(&strValue, L"y");
  58. NtDeleteValueKey(hkey, &strValue);
  59. //
  60. // Now check to see if there are any more values under this key.
  61. // Delete it if there are no more values.
  62. //
  63. KEY_FULL_INFORMATION keyInfo;
  64. DWORD dwReturnLength = 0;
  65. status = NtQueryKey(hkey,
  66. KeyFullInformation,
  67. &keyInfo,
  68. sizeof(keyInfo),
  69. &dwReturnLength);
  70. if (NT_SUCCESS(status) && keyInfo.Values == 0) {
  71. NtDeleteKey(hkey);
  72. }
  73. NtClose(hkey);
  74. return TRUE;
  75. }
  76. IMPLEMENT_SHIM_END