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.

132 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. HTMLEditor8587.cpp
  5. Abstract:
  6. HTML Editor 8.5/8.7 Call CreateFileA without closing the
  7. handle that was opened with the first call to CreateFileA.
  8. This SHIM hooks CreateFileA and CloseHandle and ensures
  9. that the temporary file is deleted and the handle closed
  10. before the next call to CreateFileA with the same filename.
  11. This is an app specific shim.
  12. History:
  13. 02/06/2001 prashkud Created
  14. --*/
  15. #include "precomp.h"
  16. // This module has been given an official blessing to use the str routines.
  17. #include "strsafe.h"
  18. IMPLEMENT_SHIM_BEGIN(HTMLEditor8587)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(CreateFileA)
  22. APIHOOK_ENUM_ENTRY(CloseHandle)
  23. APIHOOK_ENUM_END
  24. HANDLE g_FileHandle = 0;
  25. /*++
  26. Hook CreateFileA so that we can monitor the filename
  27. and the handle and ensure that the previous handle that
  28. was opened is closed before this call to the same file.
  29. --*/
  30. HANDLE
  31. APIHOOK(CreateFileA)(
  32. LPCSTR lpFileName,
  33. DWORD dwDesiredAccess,
  34. DWORD dwShareMode,
  35. LPSECURITY_ATTRIBUTES lpsa,
  36. DWORD dwCreationDisposition,
  37. DWORD dwFlagsAndAttributes,
  38. HANDLE hTempFile
  39. )
  40. {
  41. if (g_FileHandle && (stristr(lpFileName, "\\working\\~tm") != NULL))
  42. {
  43. DeleteFileA(lpFileName);
  44. CloseHandle(g_FileHandle);
  45. g_FileHandle = 0;
  46. }
  47. if (stristr(lpFileName, "\\working\\~tm") != NULL)
  48. {
  49. g_FileHandle = ORIGINAL_API(CreateFileA)(
  50. lpFileName,
  51. dwDesiredAccess,
  52. dwShareMode,
  53. lpsa,
  54. dwCreationDisposition,
  55. dwFlagsAndAttributes,
  56. hTempFile
  57. );
  58. return g_FileHandle;
  59. }
  60. else
  61. {
  62. return ORIGINAL_API(CreateFileA)(
  63. lpFileName,
  64. dwDesiredAccess,
  65. dwShareMode,
  66. lpsa,
  67. dwCreationDisposition,
  68. dwFlagsAndAttributes,
  69. hTempFile
  70. );
  71. }
  72. }
  73. /*++
  74. Hook CloseHandle to ensure that the global handle that we maintain
  75. is set to '0'.
  76. --*/
  77. BOOL
  78. APIHOOK(CloseHandle)(
  79. HANDLE hObject
  80. )
  81. {
  82. BOOL bRet = FALSE;
  83. bRet = ORIGINAL_API(CloseHandle)(hObject);
  84. if (hObject == g_FileHandle)
  85. {
  86. g_FileHandle = 0;
  87. }
  88. return bRet;
  89. }
  90. /*++
  91. Register hooked functions
  92. --*/
  93. HOOK_BEGIN
  94. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  95. APIHOOK_ENTRY(KERNEL32.DLL, CloseHandle)
  96. HOOK_END
  97. IMPLEMENT_SHIM_END