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.

104 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. RemoveOverlappedFlagFromCreateFile.cpp
  5. Abstract:
  6. This modified version of kernel32!CreateFile* prevents an app from using
  7. the FILE_FLAG_OVERLAPPED flag if the app doesn't handle it correctly.
  8. Notes:
  9. This is a general shim.
  10. History:
  11. 06/22/2001 linstev Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(RemoveOverlappedFlagFromCreateFile)
  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_OVERLAPPED if we are on a drive
  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. if ((dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED) &&
  35. (GetDriveTypeFromFileNameA(lpFileName) != DRIVE_UNKNOWN))
  36. {
  37. dwFlagsAndAttributes &= ~FILE_FLAG_OVERLAPPED;
  38. LOGN(eDbgLevelInfo, "[CreateFileA] \"%s\": removed OVERLAPPED flag", lpFileName);
  39. }
  40. return ORIGINAL_API(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode,
  41. lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
  42. hTemplateFile);
  43. }
  44. /*++
  45. Take out FILE_FLAG_OVERLAPPED if we are on a drive
  46. --*/
  47. HANDLE
  48. APIHOOK(CreateFileW)(
  49. LPWSTR lpFileName,
  50. DWORD dwDesiredAccess,
  51. DWORD dwShareMode,
  52. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  53. DWORD dwCreationDisposition,
  54. DWORD dwFlagsAndAttributes,
  55. HANDLE hTemplateFile
  56. )
  57. {
  58. if ((dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED) &&
  59. (GetDriveTypeFromFileNameW(lpFileName) != DRIVE_UNKNOWN))
  60. {
  61. dwFlagsAndAttributes &= ~FILE_FLAG_OVERLAPPED;
  62. LOGN(eDbgLevelInfo, "[CreateFileW] \"%S\": removed OVERLAPPED flag", lpFileName);
  63. }
  64. return ORIGINAL_API(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
  65. lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
  66. hTemplateFile);
  67. }
  68. /*++
  69. Register hooked functions
  70. --*/
  71. HOOK_BEGIN
  72. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  73. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileW)
  74. HOOK_END
  75. IMPLEMENT_SHIM_END