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.

191 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. ShimHook.h
  5. Abstract:
  6. Main header for shim DLLs
  7. Notes:
  8. None
  9. History:
  10. 10/29/1999 markder Created
  11. 07/16/2001 clupu Merged multiple headers into ShimHook.h
  12. 08/13/2001 robkenny Cleaned up, readied for publishing.
  13. --*/
  14. #pragma once
  15. #ifndef _SHIM_HOOK_H_
  16. #define _SHIM_HOOK_H_
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <ntldr.h>
  21. #include <ntddscsi.h>
  22. #include <windows.h>
  23. // Disable warning C4201: nonstandard extension used : nameless struct/union
  24. // Allows shims to be compiled at Warning Level 4
  25. #pragma warning ( disable : 4201 )
  26. #include <mmsystem.h>
  27. #pragma warning ( default : 4201 )
  28. #include <WinDef.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #include <shimdb.h>
  33. #ifdef __cplusplus
  34. }
  35. #endif
  36. namespace ShimLib
  37. {
  38. /*++
  39. Globals
  40. --*/
  41. extern HINSTANCE g_hinstDll; // The Shim's dll handle
  42. extern BOOL g_bMultiShim; // Does this dll handle multiple shims?
  43. extern DWORD g_dwShimVersion; //
  44. /*++
  45. Typedefs and enums
  46. --*/
  47. typedef struct tagSHIM_COM_HOOK
  48. {
  49. CLSID* pCLSID;
  50. IID* pIID;
  51. DWORD dwVtblIndex;
  52. PVOID pfnNew;
  53. PVOID pfnOld;
  54. } SHIM_COM_HOOK, *PSHIM_COM_HOOK;
  55. typedef struct tagSHIM_IFACE_FN_MAP
  56. {
  57. PVOID pVtbl;
  58. PVOID pfnNew;
  59. PVOID pfnOld;
  60. PVOID pNext;
  61. } SHIM_IFACE_FN_MAP, *PSHIM_IFACE_FN_MAP;
  62. typedef struct tagSHIM_HOOKED_OBJECT
  63. {
  64. PVOID pThis;
  65. CLSID* pCLSID;
  66. DWORD dwRef;
  67. BOOL bAddRefTrip;
  68. BOOL bClassFactory;
  69. PVOID pNext;
  70. } SHIM_HOOKED_OBJECT, *PSHIM_HOOKED_OBJECT;
  71. /*++
  72. Prototypes
  73. --*/
  74. // These declarations are needed to hook all known exported APIs that return a COM object.
  75. PVOID LookupOriginalCOMFunction( PVOID pVtbl, PVOID pfnNew, BOOL bThrowExceptionIfNull );
  76. void DumpCOMHooks();
  77. void InitializeHooks(DWORD fdwReason);
  78. PHOOKAPI InitializeHooksEx(DWORD, LPWSTR, LPSTR, DWORD*);
  79. VOID HookObject(IN CLSID *pCLSID, IN REFIID riid, OUT LPVOID *ppv, OUT PSHIM_HOOKED_OBJECT pOb, IN BOOL bClassFactory );
  80. VOID HookCOMInterface(REFCLSID rclsid, REFIID riid, LPVOID * ppv, BOOL bClassFactory);
  81. VOID AddComHook(REFCLSID clsid, REFIID iid, PVOID hook, DWORD vtblndx);
  82. }; // end of namespace ShimLib
  83. /*++
  84. Defines
  85. --*/
  86. #define IMPLEMENT_SHIM_BEGIN(shim) \
  87. namespace NS_##shim \
  88. { \
  89. extern const CHAR * g_szModuleName; \
  90. extern CHAR * g_szCommandLine; \
  91. extern PHOOKAPI g_pAPIHooks;
  92. #define IMPLEMENT_SHIM_STANDALONE(shim) \
  93. namespace NS_##shim \
  94. { \
  95. const CHAR * g_szModuleName; \
  96. CHAR * g_szCommandLine = ""; \
  97. PHOOKAPI g_pAPIHooks; \
  98. \
  99. extern PHOOKAPI InitializeHooksMulti( \
  100. DWORD fdwReason, \
  101. LPSTR pszCmdLine, \
  102. DWORD* pdwHookCount \
  103. ); \
  104. } \
  105. \
  106. namespace ShimLib { \
  107. VOID \
  108. InitializeHooks(DWORD fdwReason) \
  109. { \
  110. g_dwShimVersion = 2; \
  111. } \
  112. \
  113. PHOOKAPI \
  114. InitializeHooksEx( \
  115. DWORD fdwReason, \
  116. LPWSTR pwszShim, \
  117. LPSTR pszCmdLine, \
  118. DWORD* pdwHookCount \
  119. ) \
  120. { \
  121. using namespace NS_##shim; \
  122. return InitializeHooksMulti( \
  123. fdwReason, \
  124. pszCmdLine, \
  125. pdwHookCount ); \
  126. } \
  127. } \
  128. namespace NS_##shim \
  129. { \
  130. #define IMPLEMENT_SHIM_END \
  131. };
  132. /*++
  133. ShimLib specific include files
  134. --*/
  135. #include "ShimProto.h"
  136. #include "ShimLib.h"
  137. #endif // _SHIM_HOOK_H_