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.

141 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Canvas6.cpp
  5. Abstract:
  6. This app. deletes HKEY\CLASSES_ROOT \ .HTC key during uninstall. This
  7. breaks the ControlPanel -> Add/Remove programs
  8. Notes:
  9. This is specific to this app.
  10. History:
  11. 11/17/2000 prashkud Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(Canvas6)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(RegOpenKeyA)
  18. APIHOOK_ENUM_ENTRY(RegCloseKey)
  19. APIHOOK_ENUM_ENTRY(RegDeleteKeyA)
  20. APIHOOK_ENUM_END
  21. HKEY g_hOpenKey = 0;
  22. /*++
  23. Store the key for .htc
  24. --*/
  25. LONG
  26. APIHOOK(RegOpenKeyA)(
  27. HKEY hkey,
  28. LPCSTR lpSubKey,
  29. PHKEY phkResult)
  30. {
  31. LONG lRet = 0;
  32. lRet = ORIGINAL_API(RegOpenKeyA)(hkey,lpSubKey,phkResult);
  33. DWORD lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  34. if ((hkey == HKEY_CLASSES_ROOT)
  35. && lpSubKey
  36. && (CompareStringA(lcid, NORM_IGNORECASE, lpSubKey, -1, ".htc", -1) == CSTR_EQUAL))
  37. {
  38. if (phkResult)
  39. {
  40. g_hOpenKey = *(phkResult);
  41. }
  42. }
  43. return lRet;
  44. }
  45. /*++
  46. Ignore the close if required.
  47. --*/
  48. LONG
  49. APIHOOK(RegCloseKey)(
  50. HKEY hkey)
  51. {
  52. if (g_hOpenKey && (g_hOpenKey == hkey))
  53. {
  54. return ERROR_SUCCESS;
  55. }
  56. else
  57. {
  58. return (ORIGINAL_API(RegCloseKey)(hkey));
  59. }
  60. }
  61. /*++
  62. Ignore the delete.
  63. --*/
  64. LONG
  65. APIHOOK(RegDeleteKeyA)(
  66. HKEY hkey,
  67. LPCSTR lpSubKey)
  68. {
  69. LONG lRet = 0;
  70. DWORD lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  71. if ((hkey == HKEY_CLASSES_ROOT)
  72. && lpSubKey
  73. && (CompareStringA(lcid, NORM_IGNORECASE, lpSubKey, -1, ".htc", -1) == CSTR_EQUAL))
  74. {
  75. if (g_hOpenKey)
  76. {
  77. if(RegDeleteValueA(g_hOpenKey,NULL))
  78. {
  79. // Add DPF to indicate an error during deletion of the value installed by the app.
  80. DPFN( eDbgLevelError,
  81. "Could not delete the value in the key= \"%s\".", lpSubKey);
  82. }
  83. RegCloseKey(g_hOpenKey);
  84. g_hOpenKey = 0;
  85. }
  86. lRet = ERROR_SUCCESS;
  87. }
  88. else
  89. {
  90. lRet = ORIGINAL_API(RegDeleteKeyA)(hkey,lpSubKey);
  91. }
  92. return lRet;
  93. }
  94. /*++
  95. Register hooked functions
  96. --*/
  97. HOOK_BEGIN
  98. APIHOOK_ENTRY(ADVAPI32.DLL, RegOpenKeyA)
  99. APIHOOK_ENTRY(ADVAPI32.DLL, RegCloseKey)
  100. APIHOOK_ENTRY(ADVAPI32.DLL, RegDeleteKeyA)
  101. HOOK_END
  102. IMPLEMENT_SHIM_END