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.

141 lines
4.2 KiB

  1. // KernelTraceProvider.h : Declaration of the CKernelTraceProvider
  2. #ifndef __KERNELTRACEPROVIDER_H_
  3. #define __KERNELTRACEPROVIDER_H_
  4. #include "resource.h" // main symbols
  5. #include "ObjAccess.h"
  6. #include <Sync.h>
  7. _COM_SMARTPTR_TYPEDEF(IWbemEventSink, __uuidof(IWbemEventSink));
  8. _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
  9. struct EVENT_TRACE_PROPERTIES_EX : public EVENT_TRACE_PROPERTIES
  10. {
  11. EVENT_TRACE_PROPERTIES_EX()
  12. {
  13. ZeroMemory(this, sizeof(*this));
  14. Wnode.BufferSize = sizeof(*this);
  15. Wnode.Flags = WNODE_FLAG_TRACED_GUID;
  16. LogFileNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
  17. LogFileNameOffset = (DWORD) ((LPBYTE) szLogFileName - (LPBYTE) this);
  18. LoggerNameOffset = (DWORD) ((LPBYTE) szLoggerName - (LPBYTE) this);
  19. }
  20. TCHAR szLogFileName[MAX_PATH];
  21. TCHAR szLoggerName[MAX_PATH];
  22. };
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CKernelTraceProvider
  25. class ATL_NO_VTABLE CKernelTraceProvider :
  26. public CComObjectRootEx<CComMultiThreadModel>,
  27. public CComCoClass<CKernelTraceProvider, &CLSID_KernelTraceProvider>,
  28. public IWbemProviderInit,
  29. public IWbemEventProvider,
  30. public IWbemEventProviderSecurity
  31. {
  32. public:
  33. CKernelTraceProvider();
  34. void FinalRelease();
  35. DECLARE_REGISTRY_RESOURCEID(IDR_KERNELTRACEPROVIDER)
  36. DECLARE_NOT_AGGREGATABLE(CKernelTraceProvider)
  37. DECLARE_PROTECT_FINAL_CONSTRUCT()
  38. BEGIN_COM_MAP(CKernelTraceProvider)
  39. COM_INTERFACE_ENTRY(IWbemProviderInit)
  40. COM_INTERFACE_ENTRY(IWbemEventProvider)
  41. COM_INTERFACE_ENTRY(IWbemEventProviderSecurity)
  42. END_COM_MAP()
  43. // IWbemProviderInit
  44. public:
  45. HRESULT STDMETHODCALLTYPE Initialize(
  46. /* [in] */ LPWSTR pszUser,
  47. /* [in] */ LONG lFlags,
  48. /* [in] */ LPWSTR pszNamespace,
  49. /* [in] */ LPWSTR pszLocale,
  50. /* [in] */ IWbemServices __RPC_FAR *pNamespace,
  51. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  52. /* [in] */ IWbemProviderInitSink __RPC_FAR *pInitSink);
  53. // IWbemEventProvider
  54. public:
  55. HRESULT STDMETHODCALLTYPE ProvideEvents(
  56. /* [in] */ IWbemObjectSink __RPC_FAR *pSink,
  57. /* [in] */ long lFlags);
  58. enum SINK_TYPE
  59. {
  60. //SINK_PROCESS_CREATION,
  61. //SINK_PROCESS_DELETION,
  62. SINK_PROCESS_START,
  63. SINK_PROCESS_STOP,
  64. //SINK_THREAD_CREATION,
  65. //SINK_THREAD_DELETION,
  66. SINK_THREAD_START,
  67. SINK_THREAD_STOP,
  68. SINK_MODULE_LOAD,
  69. SINK_COUNT
  70. };
  71. // IWbemEventProviderSecurity
  72. public:
  73. HRESULT STDMETHODCALLTYPE AccessCheck(
  74. /* [in] */ WBEM_CWSTR wszQueryLanguage,
  75. /* [in] */ WBEM_CWSTR wszQuery,
  76. /* [in] */ long lSidLength,
  77. /* [unique][size_is][in] */ const BYTE __RPC_FAR *pSid);
  78. // Implementation
  79. protected:
  80. IWbemEventSinkPtr m_pSinks[SINK_COUNT];
  81. IWbemServicesPtr m_pNamespace;
  82. EVENT_TRACE_PROPERTIES_EX
  83. m_properties;
  84. TRACEHANDLE m_hSession,
  85. m_hTrace;
  86. BOOL m_bDone;
  87. HANDLE m_hProcessTraceThread;
  88. CCritSec m_cs;
  89. // Process events
  90. CObjAccess //m_eventProcessInstCreation,
  91. //m_eventProcessInstDeletion,
  92. //m_objProcessCreated,
  93. //m_objProcessDeleted,
  94. m_eventProcessStart,
  95. m_eventProcessStop;
  96. // Thread events
  97. CObjAccess //m_eventThreadInstCreation,
  98. //m_eventThreadInstDeletion,
  99. //m_objThread,
  100. m_eventThreadStart,
  101. m_eventThreadStop;
  102. // Module load
  103. CObjAccess m_eventModuleLoad;
  104. HRESULT InitEvents();
  105. HRESULT InitTracing();
  106. void StopTracing();
  107. static DWORD WINAPI DoProcessTrace(CKernelTraceProvider *pThis);
  108. static void WINAPI OnProcessEvent(PEVENT_TRACE pEvent);
  109. static void WINAPI OnThreadEvent(PEVENT_TRACE pEvent);
  110. static void WINAPI OnImageEvent(PEVENT_TRACE pEvent);
  111. };
  112. #endif //__KERNELTRACEPROVIDER_H_