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.

128 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. BoeingFix.cpp
  5. Abstract:
  6. This modified version of kernel32!CreateFile* adds the
  7. FILE_FLAG_NO_BUFFERING flag if the app is openning a specific name that is
  8. a UNIX pipe advertised as a file.
  9. Notes:
  10. This is an app specific shim.
  11. History:
  12. 10/16/2000 garretb Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(BoeingFix)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(CreateFileA)
  19. APIHOOK_ENUM_ENTRY(CreateFileW)
  20. APIHOOK_ENUM_END
  21. static const WCHAR g_lpszPipeName[] = L"msg_in\\message.pip";
  22. static const int g_lpszPipeNameLen = (sizeof(g_lpszPipeName) / sizeof(g_lpszPipeName[0])) - sizeof(g_lpszPipeName[0]);
  23. // Return FILE_FLAG_NO_BUFFERING if this filename is the special pipe.
  24. DWORD NoBufferFlag(const CString & csFileName)
  25. {
  26. if (csFileName.GetLength() >= g_lpszPipeNameLen)
  27. {
  28. CString csRight;
  29. csFileName.Right(g_lpszPipeNameLen, csRight);
  30. if (csRight.CompareNoCase(g_lpszPipeName))
  31. {
  32. return FILE_FLAG_NO_BUFFERING;
  33. }
  34. }
  35. return 0;
  36. }
  37. /*++
  38. Conditionally add FILE_FLAG_NO_BUFFERING
  39. --*/
  40. HANDLE
  41. APIHOOK(CreateFileA)(
  42. LPSTR lpFileName,
  43. DWORD dwDesiredAccess,
  44. DWORD dwShareMode,
  45. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  46. DWORD dwCreationDisposition,
  47. DWORD dwFlagsAndAttributes,
  48. HANDLE hTemplateFile
  49. )
  50. {
  51. CString csFileName(lpFileName);
  52. dwFlagsAndAttributes |= NoBufferFlag(csFileName);
  53. return ORIGINAL_API(CreateFileA)(
  54. lpFileName,
  55. dwDesiredAccess,
  56. dwShareMode,
  57. lpSecurityAttributes,
  58. dwCreationDisposition,
  59. dwFlagsAndAttributes,
  60. hTemplateFile);
  61. }
  62. /*++
  63. Conditionally add FILE_FLAG_NO_BUFFERING
  64. --*/
  65. HANDLE
  66. APIHOOK(CreateFileW)(
  67. LPWSTR lpFileName,
  68. DWORD dwDesiredAccess,
  69. DWORD dwShareMode,
  70. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  71. DWORD dwCreationDisposition,
  72. DWORD dwFlagsAndAttributes,
  73. HANDLE hTemplateFile
  74. )
  75. {
  76. CString csFileName(lpFileName);
  77. dwFlagsAndAttributes |= NoBufferFlag(csFileName);
  78. return ORIGINAL_API(CreateFileW)(
  79. lpFileName,
  80. dwDesiredAccess,
  81. dwShareMode,
  82. lpSecurityAttributes,
  83. dwCreationDisposition,
  84. dwFlagsAndAttributes,
  85. hTemplateFile);
  86. }
  87. /*++
  88. Register hooked functions
  89. --*/
  90. HOOK_BEGIN
  91. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  92. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileW)
  93. HOOK_END
  94. IMPLEMENT_SHIM_END