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.

126 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. RemoveNoBufferingFlagFromCreateFile.cpp
  5. Abstract:
  6. This modified version of kernel32!CreateFile* prevents an app from using
  7. the FILE_FLAG_NO_BUFFERING flag if the app doesn't handle it correctly.
  8. Notes:
  9. This is a general shim.
  10. History:
  11. 02/16/2000 clupu Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(RemoveNoBufferingFlagFromCreateFile)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(CreateFileA)
  18. APIHOOK_ENUM_ENTRY(CreateFileW)
  19. APIHOOK_ENUM_END
  20. /*++
  21. Take out FILE_FLAG_NO_BUFFERING
  22. --*/
  23. HANDLE
  24. APIHOOK(CreateFileA)(
  25. LPSTR lpFileName,
  26. DWORD dwDesiredAccess,
  27. DWORD dwShareMode,
  28. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  29. DWORD dwCreationDisposition,
  30. DWORD dwFlagsAndAttributes,
  31. HANDLE hTemplateFile
  32. )
  33. {
  34. //
  35. // Take out FILE_FLAG_NO_BUFFERING.
  36. //
  37. if (dwFlagsAndAttributes & FILE_FLAG_NO_BUFFERING) {
  38. DPFN(
  39. eDbgLevelInfo,
  40. "[CreateFileA] called with FILE_FLAG_NO_BUFFERING set.\n");
  41. }
  42. dwFlagsAndAttributes &= ~FILE_FLAG_NO_BUFFERING;
  43. return ORIGINAL_API(CreateFileA)(
  44. lpFileName,
  45. dwDesiredAccess,
  46. dwShareMode,
  47. lpSecurityAttributes,
  48. dwCreationDisposition,
  49. dwFlagsAndAttributes,
  50. hTemplateFile);
  51. }
  52. /*++
  53. Take out FILE_FLAG_NO_BUFFERING
  54. --*/
  55. HANDLE
  56. APIHOOK(CreateFileW)(
  57. LPWSTR lpFileName,
  58. DWORD dwDesiredAccess,
  59. DWORD dwShareMode,
  60. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  61. DWORD dwCreationDisposition,
  62. DWORD dwFlagsAndAttributes,
  63. HANDLE hTemplateFile
  64. )
  65. {
  66. //
  67. // Take out FILE_FLAG_NO_BUFFERING.
  68. //
  69. if (dwFlagsAndAttributes & FILE_FLAG_NO_BUFFERING) {
  70. DPFN(
  71. eDbgLevelInfo,
  72. "[CreateFileW] called with FILE_FLAG_NO_BUFFERING set.\n");
  73. }
  74. dwFlagsAndAttributes &= ~FILE_FLAG_NO_BUFFERING;
  75. return ORIGINAL_API(CreateFileW)(
  76. lpFileName,
  77. dwDesiredAccess,
  78. dwShareMode,
  79. lpSecurityAttributes,
  80. dwCreationDisposition,
  81. dwFlagsAndAttributes,
  82. hTemplateFile);
  83. }
  84. /*++
  85. Register hooked functions
  86. --*/
  87. HOOK_BEGIN
  88. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  89. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileW)
  90. HOOK_END
  91. IMPLEMENT_SHIM_END