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.

125 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ShimHookMacro.h
  5. Abstract:
  6. Shim hooking macros
  7. Notes:
  8. None
  9. History:
  10. 11/01/1999 markder Created
  11. 01/10/2000 linstev Format to new style
  12. --*/
  13. #ifndef _SHIMHOOKMACRO_H_
  14. #define _SHIMHOOKMACRO_H_
  15. #include <ShimDebug.h>
  16. enum
  17. {
  18. APIHOOK_DllGetClassObject = 0,
  19. APIHOOK_DirectDrawCreate,
  20. APIHOOK_DirectDrawCreateEx,
  21. USERAPIHOOKSTART
  22. };
  23. enum
  24. {
  25. USERCOMHOOKSTART = 0
  26. };
  27. typedef struct tagSHIM_COM_HOOK
  28. {
  29. CLSID* pCLSID;
  30. IID* pIID;
  31. DWORD dwVtblIndex;
  32. PVOID pfnNew;
  33. PVOID pfnOld;
  34. } SHIM_COM_HOOK, *PSHIM_COM_HOOK;
  35. typedef struct tagSHIM_IFACE_FN_MAP
  36. {
  37. PVOID pVtbl;
  38. PVOID pfnNew;
  39. PVOID pfnOld;
  40. PVOID pNext;
  41. } SHIM_IFACE_FN_MAP, *PSHIM_IFACE_FN_MAP;
  42. typedef struct tagSHIM_HOOKED_OBJECT
  43. {
  44. PVOID pThis;
  45. CLSID* pCLSID;
  46. DWORD dwRef;
  47. BOOL bAddRefTrip;
  48. BOOL bClassFactory;
  49. PVOID pNext;
  50. } SHIM_HOOKED_OBJECT, *PSHIM_HOOKED_OBJECT;
  51. // These declarations are needed to hook all known exported APIs that return a COM object.
  52. PVOID LookupOldCOMIntf( PVOID pVtbl, PVOID pfnNew, BOOL bThrowExceptionIfNull );
  53. void DumpCOMHooks();
  54. void InitializeHooks(DWORD fdwReason);
  55. VOID HookObject(IN CLSID *pCLSID, IN REFIID riid, OUT LPVOID *ppv, OUT PSHIM_HOOKED_OBJECT pOb, IN BOOL bClassFactory );
  56. extern void InitHooks(DWORD dwCount);
  57. extern void InitComHooks(DWORD dwCount);
  58. extern HRESULT APIHook_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
  59. #ifndef LIB_BUILD_FLAG
  60. extern BOOL g_bAPIHooksInited;
  61. extern BOOL g_bHasCOMHooks;
  62. extern PHOOKAPI g_pAPIHooks;
  63. extern PSHIM_COM_HOOK g_pCOMHooks;
  64. extern DWORD g_dwAPIHookCount;
  65. extern DWORD g_dwCOMHookCount;
  66. #else
  67. BOOL g_bAPIHooksInited;
  68. BOOL g_bHasCOMHooks;
  69. PHOOKAPI g_pAPIHooks;
  70. PSHIM_COM_HOOK g_pCOMHooks;
  71. DWORD g_dwAPIHookCount;
  72. DWORD g_dwCOMHookCount;
  73. #endif // LIB_BUILD_FLAG
  74. // Macros for user shims
  75. #define INIT_HOOKS InitHooks
  76. #define INIT_COMHOOKS(module, count) \
  77. ASSERT(g_bAPIHooksInited,"INVALID COMHOOK, INIT_HOOK MACRO MUST BE FIRST!!"); \
  78. DECLARE_APIHOOK(module, DllGetClassObject); \
  79. InitComHooks(count);
  80. #define DECLARE_APIHOOK(module, fn) \
  81. g_pAPIHooks[APIHOOK_##fn].pszModule = #module; \
  82. g_pAPIHooks[APIHOOK_##fn].pszFunctionName = #fn; \
  83. g_pAPIHooks[APIHOOK_##fn].pfnNew = APIHook_##fn; \
  84. DPF(eDbgLevelInfo, "[declare apihook] " #fn "\n");
  85. #define DECLARE_COMHOOK(clsid, iid, intf, vtblndx) \
  86. g_pCOMHooks[COMHOOK_##intf ].pCLSID = (CLSID*) &clsid; \
  87. g_pCOMHooks[COMHOOK_##intf ].pIID = (IID*) &iid; \
  88. g_pCOMHooks[COMHOOK_##intf ].dwVtblIndex = vtblndx; \
  89. g_pCOMHooks[COMHOOK_##intf ].pfnNew = COMHook_##intf; \
  90. DPF(eDbgLevelInfo, "[declarecomhook] " #intf "\n");
  91. #define LOOKUP_APIHOOK(fn) \
  92. (*(_pfn_##fn)(g_pAPIHooks[APIHOOK_##fn].pfnOld))
  93. #define LOOKUP_COMHOOK(pThis, fn, bThrowException) \
  94. (*(_pfn_##fn)(LookupOldCOMIntf(*((PVOID *) pThis), COMHook_##fn, bThrowException )))
  95. #endif // _SHIMHOOKMACRO_H_