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.

118 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PetzForceCritSecRelease.cpp
  5. Abstract:
  6. This DLL takes care of a Thread that is exiting without performing a
  7. LeaveCriticalSection on a critical section it owns.
  8. Notes:
  9. This is a application specific shim.
  10. History:
  11. 04/00/2000 a-chcoff Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(Petz)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(_endthread)
  18. APIHOOK_ENUM_ENTRY(ShellExecuteA)
  19. APIHOOK_ENUM_END
  20. LPCRITICAL_SECTION g_pCritSectToRelease;
  21. HINSTANCE
  22. APIHOOK(ShellExecuteA)(
  23. HWND hwnd,
  24. LPCSTR lpVerb,
  25. LPCSTR lpFile,
  26. LPCSTR lpParameters,
  27. LPCSTR lpDirectory,
  28. INT nShowCmd)
  29. {
  30. CSTRING_TRY
  31. {
  32. CString csFile(lpFile);
  33. csFile.Replace(L"SYSTEM\\PETZ", L"SYSTEM32\\PETZ");
  34. return ORIGINAL_API(ShellExecuteA)(
  35. hwnd,
  36. lpVerb,
  37. csFile.GetAnsi(),
  38. lpParameters,
  39. lpDirectory,
  40. nShowCmd);
  41. }
  42. CSTRING_CATCH
  43. {
  44. // Do nothing
  45. }
  46. return ORIGINAL_API(ShellExecuteA)(
  47. hwnd,
  48. lpVerb,
  49. lpFile,
  50. lpParameters,
  51. lpDirectory,
  52. nShowCmd);
  53. }
  54. VOID
  55. APIHOOK(_endthread)(void)
  56. {
  57. //Don't let the thread orphan a critical section.
  58. LeaveCriticalSection(g_pCritSectToRelease);
  59. ORIGINAL_API(_endthread)();
  60. }
  61. /*++
  62. Register hooked functions
  63. --*/
  64. BOOL
  65. NOTIFY_FUNCTION(
  66. DWORD fdwReason)
  67. {
  68. if (fdwReason == DLL_PROCESS_ATTACH)
  69. {
  70. CSTRING_TRY
  71. {
  72. CString csCl(COMMAND_LINE);
  73. WCHAR *unused;
  74. g_pCritSectToRelease = (LPCRITICAL_SECTION) wcstol(csCl, &unused, 10);
  75. }
  76. CSTRING_CATCH
  77. {
  78. return FALSE;
  79. }
  80. }
  81. return TRUE;
  82. }
  83. HOOK_BEGIN
  84. CALL_NOTIFY_FUNCTION
  85. APIHOOK_ENTRY(MSVCRT.DLL, _endthread)
  86. APIHOOK_ENTRY(SHELL32.DLL, ShellExecuteA)
  87. HOOK_END
  88. IMPLEMENT_SHIM_END