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.

174 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. EasyCDCreator5.cpp
  5. Abstract:
  6. Clean up the filter drivers on the uninstaller on process termination.
  7. Notes:
  8. This is an app specific shim.
  9. History:
  10. 08/09/2001 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(EasyCDCreator5)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_END
  17. BOOL
  18. StripStringFromValue(HKEY hKey, WCHAR *lpValue, WCHAR *lpStrip)
  19. {
  20. DWORD dwType, dwSize;
  21. LONG lRet;
  22. BOOL bRet = FALSE;
  23. WCHAR *lpString = NULL, *lpNewString = NULL;
  24. WCHAR wzSystem[MAX_PATH];
  25. //
  26. // Build the %systemdir%\drivers\filename.sys to see if it's available
  27. //
  28. if (GetSystemDirectoryW(wzSystem, MAX_PATH) == 0) {
  29. DPFN(eDbgLevelError, "GetSystemDirectory failed");
  30. goto Exit;
  31. }
  32. wcscat(wzSystem, L"\\Drivers\\");
  33. wcscat(wzSystem, lpStrip);
  34. wcscat(wzSystem, L".sys");
  35. //
  36. // Check to see if the file exists - if it does, we don't touch the registry
  37. //
  38. if (GetFileAttributesW(wzSystem) != 0xFFFFFFFF) {
  39. DPFN(eDbgLevelError, "%S found so leave registry value alone", lpStrip);
  40. goto Exit;
  41. }
  42. //
  43. // Checking the registry for the bad state now
  44. //
  45. // Get the size
  46. if (ERROR_SUCCESS != RegQueryValueExW(hKey, lpValue, NULL, &dwType, NULL, &dwSize)) {
  47. DPFN(eDbgLevelError, "%S value not found", lpValue);
  48. goto Exit;
  49. }
  50. // Make sure it's a MULTI_STRING
  51. if (dwType != REG_MULTI_SZ) {
  52. DPFN(eDbgLevelError, "%S not correct type, expecting a multi-string", lpStrip);
  53. goto Exit;
  54. }
  55. // Allocate memory for it and clear it
  56. lpString = (WCHAR *) malloc(dwSize);
  57. if (!lpString) {
  58. DPFN(eDbgLevelError, "Out of memory");
  59. goto Exit;
  60. }
  61. ZeroMemory(lpString, dwSize);
  62. // Get the actual data
  63. if (ERROR_SUCCESS != RegQueryValueExW(hKey, lpValue, NULL, &dwType, (LPBYTE)lpString, &dwSize)) {
  64. DPFN(eDbgLevelError, "%S QueryValue failed unexpectedly", lpStrip);
  65. goto Exit;
  66. }
  67. // Allocate an output buffer
  68. lpNewString = (WCHAR *) malloc(dwSize);
  69. if (!lpNewString) {
  70. DPFN(eDbgLevelError, "Out of memory");
  71. goto Exit;
  72. }
  73. ZeroMemory(lpNewString, dwSize);
  74. // Run the input buffer looking for lpStrip
  75. WCHAR *lpCurr = lpString;
  76. WCHAR *lpCurrOut = lpNewString;
  77. BOOL bStripped = FALSE;
  78. while (*lpCurr) {
  79. if (_wcsicmp(lpCurr, lpStrip) != 0) {
  80. // Keep this entry
  81. wcscpy(lpCurrOut, lpCurr);
  82. lpCurrOut += wcslen(lpCurrOut) + 1;
  83. } else {
  84. // Remove this entry
  85. bStripped = TRUE;
  86. }
  87. lpCurr += wcslen(lpCurr) + 1;
  88. }
  89. if (bStripped) {
  90. //
  91. // Fix up the registry with the new value. If there's nothing left, then kill the
  92. // value.
  93. //
  94. LOGN(eDbgLevelError, "Removing filter driver - Value: %S, Name: %S", lpValue, lpStrip);
  95. dwSize = (lpCurrOut - lpNewString) * sizeof(WCHAR);
  96. if (dwSize == 0) {
  97. RegDeleteValueW(hKey, lpValue);
  98. } else {
  99. RegSetValueExW(hKey, lpValue, NULL, dwType, (LPBYTE) lpNewString, dwSize + sizeof(WCHAR));
  100. }
  101. }
  102. bRet = TRUE;
  103. Exit:
  104. if (lpString) {
  105. free(lpString);
  106. }
  107. if (lpNewString) {
  108. free(lpNewString);
  109. }
  110. return bRet;
  111. }
  112. /*++
  113. Register hooked functions
  114. --*/
  115. BOOL
  116. NOTIFY_FUNCTION(DWORD fdwReason)
  117. {
  118. if (fdwReason == DLL_PROCESS_DETACH) {
  119. HKEY hKey;
  120. if (ERROR_SUCCESS == RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E965-E325-11CE-BFC1-08002BE10318}", &hKey)) {
  121. StripStringFromValue(hKey, L"UpperFilters", L"Cdralw2k");
  122. StripStringFromValue(hKey, L"LowerFilters", L"Cdr4_2K");
  123. RegCloseKey(hKey);
  124. }
  125. }
  126. return TRUE;
  127. }
  128. HOOK_BEGIN
  129. CALL_NOTIFY_FUNCTION
  130. HOOK_END
  131. IMPLEMENT_SHIM_END