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.

229 lines
5.9 KiB

  1. /*****************************************************************************\
  2. Author: Corey Morgan (coreym)
  3. Copyright (c) 1998-2000 Microsoft Corporation
  4. \*****************************************************************************/
  5. #include <FWcommon.h>
  6. #include <objbase.h>
  7. #include <initguid.h>
  8. HMODULE ghModule;
  9. WCHAR *EVENTTRACE_GUIDSTRING = L"{9a5dd473-d410-11d1-b829-00c04f94c7c3}";
  10. WCHAR *SYSMONLOG_GUIDSTRING = L"{f95e1664-7979-44f2-a040-496e7f500043}";
  11. CLSID CLSID_CIM_EVENTTRACE;
  12. CLSID CLSID_CIM_SYSMONLOG;
  13. long g_cLock=0;
  14. EXTERN_C BOOL LibMain32(HINSTANCE hInstance, ULONG ulReason
  15. , LPVOID pvReserved)
  16. {
  17. if (DLL_PROCESS_ATTACH==ulReason)
  18. ghModule = hInstance;
  19. return TRUE;
  20. }
  21. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv)
  22. {
  23. HRESULT hr;
  24. CWbemGlueFactory *pObj;
  25. CLSIDFromString(EVENTTRACE_GUIDSTRING, &CLSID_CIM_EVENTTRACE );
  26. CLSIDFromString(SYSMONLOG_GUIDSTRING, &CLSID_CIM_SYSMONLOG );
  27. if( CLSID_CIM_EVENTTRACE != rclsid && CLSID_CIM_SYSMONLOG != rclsid ){
  28. return E_FAIL;
  29. }
  30. pObj= new CWbemGlueFactory();
  31. if( NULL==pObj ){
  32. return E_OUTOFMEMORY;
  33. }
  34. hr=pObj->QueryInterface(riid, ppv);
  35. if( FAILED(hr) ){
  36. delete pObj;
  37. }
  38. return hr;
  39. }
  40. STDAPI DllCanUnloadNow(void)
  41. {
  42. SCODE sc;
  43. if( (0L==g_cLock) &&
  44. CWbemProviderGlue::FrameworkLogoffDLL(L"EventTraceProv") &&
  45. CWbemProviderGlue::FrameworkLogoffDLL(L"SmonLogProv")){
  46. sc = S_OK;
  47. }else{
  48. sc = S_FALSE;
  49. }
  50. return sc;
  51. }
  52. BOOL Is4OrMore(void)
  53. {
  54. OSVERSIONINFO os;
  55. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  56. if(!GetVersionEx(&os)){
  57. return FALSE;
  58. }
  59. return os.dwMajorVersion >= 4;
  60. }
  61. STDAPI DllRegisterServer(void)
  62. {
  63. WCHAR szCLSID[512];
  64. WCHAR szModule[MAX_PATH];
  65. LPWSTR pName;
  66. LPWSTR pModel = L"Both";
  67. HKEY hKey1, hKey2;
  68. // Compile Mof
  69. /* HRESULT hr;
  70. hr = CoInitialize(NULL);
  71. if( SUCCEEDED(hr) ){
  72. WCHAR drive[_MAX_DRIVE];
  73. WCHAR dir[_MAX_DIR];
  74. WCHAR fname[_MAX_FNAME];
  75. WCHAR ext[_MAX_EXT];
  76. WBEM_COMPILE_STATUS_INFO stat;
  77. IMofCompiler *pMof = NULL;
  78. hr = CoCreateInstance( CLSID_MofCompiler, NULL, CLSCTX_INPROC_SERVER, IID_IMofCompiler, (void **)&pMof );
  79. GetModuleFileNameW( ghModule, szModule, MAX_PATH);
  80. _wsplitpath( szModule, drive, dir, fname, ext );
  81. _wmakepath( szModule, drive, dir, L"evntrprv.mof", L"" );
  82. pMof->CompileFile( szModule, NULL,NULL,NULL,NULL, 0,0,0, &stat );
  83. pMof->Release();
  84. CoUninitialize();
  85. }
  86. */
  87. GetModuleFileNameW(ghModule, szModule, MAX_PATH);
  88. // Event Trace Provider
  89. pName = L"Event Trace Logger Provider";
  90. wcscpy(szCLSID, L"SOFTWARE\\CLASSES\\CLSID\\" );
  91. wcscat(szCLSID, EVENTTRACE_GUIDSTRING );
  92. RegCreateKeyW(HKEY_LOCAL_MACHINE, szCLSID, &hKey1);
  93. RegSetValueExW(hKey1, NULL, 0, REG_SZ, (BYTE *)pName, (wcslen(pName)+1)*sizeof(WCHAR));
  94. RegCreateKeyW(hKey1, L"InprocServer32", &hKey2 );
  95. RegSetValueExW(hKey2, NULL, 0, REG_SZ, (BYTE *)szModule, (wcslen(szModule)+1)*sizeof(WCHAR));
  96. RegSetValueExW(hKey2, L"ThreadingModel", 0, REG_SZ, (BYTE *)pModel, (wcslen(pModel)+1)*sizeof(WCHAR));
  97. CloseHandle(hKey1);
  98. CloseHandle(hKey2);
  99. // Sysmon Log Provider
  100. pName = L"System Log Provider";
  101. wcscpy(szCLSID, L"SOFTWARE\\CLASSES\\CLSID\\" );
  102. wcscat(szCLSID, SYSMONLOG_GUIDSTRING );
  103. RegCreateKeyW(HKEY_LOCAL_MACHINE, szCLSID, &hKey1);
  104. RegSetValueExW(hKey1, NULL, 0, REG_SZ, (BYTE *)pName, (wcslen(pName)+1)*sizeof(WCHAR));
  105. RegCreateKeyW(hKey1, L"InprocServer32", &hKey2 );
  106. RegSetValueExW(hKey2, NULL, 0, REG_SZ, (BYTE *)szModule, (wcslen(szModule)+1)*sizeof(WCHAR));
  107. RegSetValueExW(hKey2, L"ThreadingModel", 0, REG_SZ, (BYTE *)pModel, (wcslen(pModel)+1)*sizeof(WCHAR));
  108. CloseHandle(hKey1);
  109. CloseHandle(hKey2);
  110. return NOERROR;
  111. }
  112. STDAPI DllUnregisterServer(void)
  113. {
  114. WCHAR wcID[128];
  115. WCHAR szCLSID[128];
  116. HKEY hKey;
  117. // Event Trace Provider
  118. CLSIDFromString(EVENTTRACE_GUIDSTRING, &CLSID_CIM_EVENTTRACE);
  119. StringFromGUID2(CLSID_CIM_EVENTTRACE, wcID, 128);
  120. wcscpy( szCLSID, L"SOFTWARE\\CLASSES\\CLSID\\");
  121. wcscpy( szCLSID, wcID);
  122. DWORD dwRet = RegOpenKeyW(HKEY_LOCAL_MACHINE, szCLSID, &hKey);
  123. if( dwRet == NO_ERROR ){
  124. RegDeleteKeyW(hKey, L"InProcServer32" );
  125. CloseHandle(hKey);
  126. }
  127. dwRet = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\CLASSES\\CLSID\\", &hKey);
  128. if(dwRet == NO_ERROR){
  129. RegDeleteKeyW(hKey,wcID);
  130. CloseHandle(hKey);
  131. }
  132. // System Log Provider
  133. CLSIDFromString(SYSMONLOG_GUIDSTRING, &CLSID_CIM_SYSMONLOG);
  134. StringFromGUID2(CLSID_CIM_SYSMONLOG, wcID, 128);
  135. wcscpy( szCLSID, L"SOFTWARE\\CLASSES\\CLSID\\");
  136. wcscpy( szCLSID, wcID);
  137. dwRet = RegOpenKeyW(HKEY_LOCAL_MACHINE, szCLSID, &hKey);
  138. if( dwRet == NO_ERROR ){
  139. RegDeleteKeyW(hKey, L"InProcServer32" );
  140. CloseHandle(hKey);
  141. }
  142. dwRet = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\CLASSES\\CLSID\\", &hKey);
  143. if(dwRet == NO_ERROR){
  144. RegDeleteKeyW(hKey,wcID);
  145. CloseHandle(hKey);
  146. }
  147. return NOERROR;
  148. }
  149. BOOL APIENTRY DllMain ( HINSTANCE hInstDLL,
  150. DWORD fdwReason,
  151. LPVOID lpReserved )
  152. {
  153. BOOL bRet = TRUE;
  154. switch( fdwReason ){
  155. case DLL_PROCESS_ATTACH:
  156. DisableThreadLibraryCalls(hInstDLL);
  157. ghModule = hInstDLL;
  158. bRet = CWbemProviderGlue::FrameworkLoginDLL(L"EventTraceProv");
  159. break;
  160. case DLL_THREAD_ATTACH:
  161. // Do thread-specific initialization.
  162. break;
  163. case DLL_THREAD_DETACH:
  164. // Do thread-specific cleanup.
  165. break;
  166. case DLL_PROCESS_DETACH:
  167. // Perform any necessary cleanup.
  168. break;
  169. }
  170. return bRet;
  171. }