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.

401 lines
15 KiB

  1. #include <wmiexts.h>
  2. #include <malloc.h>
  3. #include <wbemint.h>
  4. #ifdef SetContext
  5. #undef SetContext
  6. #endif
  7. #ifdef GetContext
  8. #undef GetContext
  9. #endif
  10. #ifdef GetExpression
  11. #undef GetExpression
  12. #endif
  13. #include <utilfun.h>
  14. #define COREPROX_POLARITY
  15. #include <esssink.h>
  16. #include <ess.h>
  17. #include <nsrep.h>
  18. #include <equeue.h>
  19. DWORD
  20. CallBackDequeTurns(void * pLocationTurn_OOP,void * pLocationTurn_IP)
  21. {
  22. CExecLine::CTurn * pTurn_OOP = (CExecLine::CTurn *)(*(void **)pLocationTurn_IP);
  23. DEFINE_CPP_VAR(CExecLine::CTurn,varCTurn);
  24. CExecLine::CTurn * pTurn = GET_CPP_VAR_PTR(CExecLine::CTurn,varCTurn);
  25. if (ReadMemory((ULONG_PTR)pTurn_OOP,pTurn,sizeof(CExecLine::CTurn),NULL))
  26. {
  27. dprintf(" m_lRef %x m_hEvent %x m_dwOwningThreadId %x\n",pTurn->m_lRef,pTurn->m_hEvent,pTurn->m_dwOwningThreadId);
  28. }
  29. else
  30. {
  31. dprintf("RM %p\n",pTurn_OOP);
  32. }
  33. return 0;
  34. }
  35. void Dump_EventProvRecord(MEMORY_ADDRESS pRecord_OOP)
  36. {
  37. DEFINE_CPP_VAR(CEventProviderCache::CRecord,varCRecord);
  38. CEventProviderCache::CRecord * pRecord = GET_CPP_VAR_PTR(CEventProviderCache::CRecord,varCRecord);
  39. if (ReadMemory((ULONG_PTR)pRecord_OOP,pRecord,sizeof(CEventProviderCache::CRecord),NULL))
  40. {
  41. WCHAR pString[64];
  42. pString[0] = 0;
  43. pString[63] = 0;
  44. if (ReadMemory((ULONG_PTR)pRecord->m_strName,pString,sizeof(pString)-2,0))
  45. {
  46. dprintf(" m_strName %S\n",pString);
  47. }
  48. else
  49. {
  50. dprintf("RM %p\n",pRecord->m_strName);
  51. }
  52. dprintf(" m_pProvider %p\n",pRecord->m_pProvider);
  53. dprintf(" m_pQuerySink %p\n",pRecord->m_pQuerySink);
  54. dprintf(" m_pSecurity %p\n",pRecord->m_pSecurity);
  55. dprintf(" m_pMainSink %p\n",pRecord->m_pMainSink);
  56. dprintf(" m_ExecLine %p\n",pRecord_OOP + FIELD_OFFSET(CEventProviderCache::CRecord,m_Line));
  57. PrintDequeCB(pRecord_OOP + FIELD_OFFSET(CEventProviderCache::CRecord,m_Line)+FIELD_OFFSET(CExecLine,m_qTurns),CallBackDequeTurns);
  58. }
  59. else
  60. {
  61. dprintf("RM %p\n",pRecord_OOP);
  62. }
  63. }
  64. DWORD
  65. CallBackFilter(void * pKey, void * pValue)
  66. {
  67. MEMORY_ADDRESS pVTable;
  68. if (ReadMemory((ULONG_PTR)pKey,&pVTable,sizeof(pVTable),0))
  69. {
  70. BYTE pString[256];
  71. pString[0]=0;
  72. #ifdef KDEXT_64BIT
  73. ULONG64 Displ;
  74. #else
  75. ULONG Displ;
  76. #endif
  77. GetSymbol(pVTable,(PCHAR)pString,&Displ);
  78. if (lstrlenA((CHAR *)pString))
  79. {
  80. dprintf(" %s+%x\n",pString,Displ);
  81. if (strstr((const CHAR *)pString,"CTempFilter"))
  82. {
  83. ULONG_PTR pStrLoc = (ULONG_PTR)pKey + FIELD_OFFSET(CTempFilter,m_wszQuery);
  84. ULONG_PTR pStr_OOP;
  85. if (ReadMemory(pStrLoc,&pStr_OOP,sizeof(pStr_OOP),0))
  86. {
  87. WCHAR pStringQuery[256];
  88. pStringQuery[0] = 0;
  89. ULONG lRead = 0;
  90. ReadMemory(pStr_OOP,pStringQuery,sizeof(pStringQuery),&lRead);
  91. if (lRead)
  92. {
  93. dprintf(" QUERY: %S\n",pStringQuery);
  94. }
  95. else
  96. {
  97. dprintf("RM %p\n",pStr_OOP);
  98. }
  99. }
  100. else
  101. {
  102. dprintf("RM %p\n",pStrLoc);
  103. }
  104. }
  105. else if (strstr((const CHAR *)pString,"CPermanentFilter"))
  106. {
  107. ULONG_PTR pStrLoc = (ULONG_PTR)pKey + FIELD_OFFSET(CPermanentFilter,m_pcsQuery);
  108. ULONG_PTR pStr_OOP;
  109. if (ReadMemory(pStrLoc,&pStr_OOP,sizeof(pStr_OOP),0))
  110. {
  111. struct CompressedString_
  112. {
  113. BYTE Flag;
  114. CHAR pStringQuery[256];
  115. } CompStr;
  116. CompStr.pStringQuery[0] = 0;
  117. ULONG lRead = 0;
  118. ReadMemory(pStr_OOP,&CompStr,sizeof(CompStr),&lRead);
  119. if (lRead)
  120. {
  121. if (CompStr.Flag)
  122. dprintf(" QUERY: %S\n",CompStr.pStringQuery);
  123. else
  124. dprintf(" QUERY: %s\n",CompStr.pStringQuery);
  125. }
  126. else
  127. {
  128. dprintf("RM %p\n",pStr_OOP);
  129. }
  130. }
  131. else
  132. {
  133. dprintf("RM %p\n",pStrLoc);
  134. }
  135. }
  136. else
  137. {
  138. dprintf(" UNKNOWN\n");
  139. }
  140. }
  141. }
  142. else
  143. {
  144. dprintf("RM %p\n",pKey);
  145. }
  146. return 0;
  147. }
  148. DWORD
  149. CallBackEssNamespace(void * pKey, void * pValue)
  150. {
  151. WCHAR pName[MAX_PATH+1];
  152. pName[MAX_PATH] = 0;
  153. if (pKey && ReadMemory((ULONG_PTR)pKey,pName,MAX_PATH*sizeof(WCHAR),NULL))
  154. {
  155. dprintf(" %S\n",pName);
  156. }
  157. DEFINE_CPP_VAR(CEssNamespace,varCEssNamespace);
  158. CEssNamespace * pEssNameSpace = GET_CPP_VAR_PTR(CEssNamespace,varCEssNamespace);
  159. if (pValue && ReadMemory((ULONG_PTR)pValue,pEssNameSpace,sizeof(CEssNamespace),NULL))
  160. {
  161. dprintf(" %p\n",pValue);
  162. dprintf(" m_csLevel2: owner %x event %x\n",pEssNameSpace->m_csLevel2.m_dwThreadId,pEssNameSpace->m_csLevel2.m_hEvent);
  163. dprintf(" m_aDeferredEvents size %x %p\n",pEssNameSpace->m_aDeferredEvents.m_Array.m_nSize,pEssNameSpace->m_aDeferredEvents.m_Array.m_pArray);
  164. dprintf(" m_wszName %p\n",pEssNameSpace->m_wszName);
  165. dprintf(" m_pProviderFactory %p\n",pEssNameSpace->m_pProviderFactory);
  166. dprintf(" m_pCoreSvc %p\n",pEssNameSpace->m_pCoreSvc);
  167. dprintf(" m_pFullSvc %p\n",pEssNameSpace->m_pFullSvc);
  168. dprintf(" m_pInternalCoreSvc %p\n",pEssNameSpace->m_pInternalCoreSvc);
  169. dprintf(" m_pInternalFullSvc %p\n",pEssNameSpace->m_pInternalFullSvc);
  170. //
  171. CBindingTable * pBinding = &pEssNameSpace->m_Bindings;
  172. dprintf(" m_Binding\n");
  173. dprintf(" wbemess!CEventFilter\n");
  174. _Map * pMapF = (_Map *)((BYTE*)pValue+FIELD_OFFSET(CEssNamespace,m_Bindings)+FIELD_OFFSET(CBindingTable,m_apFilters)+FIELD_OFFSET(CSortedRefedKeyedPointerArray<CEventFilter>,m_t));
  175. //&pBinding->m_apFilters.m_t;
  176. PrintMapCB(pMapF,TRUE,CallBackFilter);
  177. dprintf(" wbemess!CEventConsumer\n");
  178. _Map * pMapC = (_Map *)((BYTE*)pValue+FIELD_OFFSET(CEssNamespace,m_Bindings)+FIELD_OFFSET(CBindingTable,m_apConsumers)+FIELD_OFFSET(CSortedRefedKeyedPointerArray<CEventConsumer>,m_t));
  179. PrintMapCB(pMapC,TRUE,CallBackObj);
  180. DWORD NumElCons = pEssNameSpace->m_ConsumerProviderCache.m_apRecords.m_Array.m_nSize;
  181. VOID * pVoid = pEssNameSpace->m_ConsumerProviderCache.m_apRecords.m_Array.m_pArray;
  182. VOID **ppPointers = (VOID **)_alloca(NumElCons * sizeof(VOID *));
  183. dprintf(" wbemess!CConsumerProviderCache %x - %p\n",NumElCons,pVoid);
  184. if (ReadMemory((ULONG_PTR)pVoid,ppPointers,NumElCons * sizeof(VOID *),NULL))
  185. {
  186. for (DWORD i=0;i<NumElCons;i++)
  187. {
  188. dprintf(" %x - %p\n",i,ppPointers[i]);
  189. }
  190. }
  191. //m_EventProviderCache
  192. DWORD NumElProv = pEssNameSpace->m_EventProviderCache.m_aRecords.m_Array.m_nSize;
  193. pVoid = pEssNameSpace->m_EventProviderCache.m_aRecords.m_Array.m_pArray;
  194. if (NumElProv > NumElCons)
  195. ppPointers = (VOID **)_alloca(NumElProv * sizeof(VOID *));
  196. dprintf(" wbemess!CEventProviderCache %x - %p\n",NumElProv,pVoid);
  197. if (ReadMemory((ULONG_PTR)pVoid,ppPointers,NumElProv * sizeof(VOID *),NULL))
  198. {
  199. for (DWORD i=0;i<NumElProv;i++)
  200. {
  201. dprintf(" %x - %p\n",i,ppPointers[i]);
  202. Dump_EventProvRecord((MEMORY_ADDRESS)ppPointers[i]);
  203. }
  204. }
  205. dprintf(" ----------------------- End of Namespace\n");
  206. }
  207. return 0;
  208. }
  209. //
  210. // prototype declaration
  211. //
  212. void DumpRecord(ULONG_PTR pRecord_OOP,
  213. HANDLE hSourceProcess,
  214. pfnDumpRequest DumpRequest);
  215. DWORD DumpCExecRequest(ULONG_PTR pExecReq_OOP)
  216. {
  217. DEFINE_CPP_VAR(CEventQueue::CDeliverRequest,varCExecRequest);
  218. CEventQueue::CDeliverRequest * pExecReq = GET_CPP_VAR_PTR(CEventQueue::CDeliverRequest,varCExecRequest);
  219. ReadMemory((ULONG_PTR)pExecReq_OOP,pExecReq,sizeof(CEventQueue::CDeliverRequest),NULL);
  220. GetVTable((MEMORY_ADDRESS)pExecReq_OOP);
  221. dprintf(" %p m_hWhenDone\n",pExecReq->m_hWhenDone); // Ptr32 to Void
  222. dprintf(" %p m_pNext\n",pExecReq->m_pNext); // Ptr32 CCoreExecReq
  223. dprintf(" %08x m_lPriority\n",pExecReq->m_lPriority); // Int 4B
  224. dprintf(" %d m_fOk\n",pExecReq->m_fOk); // Char
  225. dprintf(" %p m_pConsumer ",pExecReq->m_pConsumer); // Ptr32 _IWmiCoreHandle
  226. if (pExecReq->m_pConsumer){
  227. GetVTable((MEMORY_ADDRESS)pExecReq->m_pConsumer);
  228. }
  229. return 0;
  230. }
  231. void
  232. Print_CEventQueue(ULONG_PTR pEventQueue_OOP, HANDLE hCurrentProcess)
  233. {
  234. DEFINE_CPP_VAR(CEventQueue,varCEventQueue);
  235. CEventQueue * pEventQueue = GET_CPP_VAR_PTR(CEventQueue,varCEventQueue);
  236. if (ReadMemory(pEventQueue_OOP,pEventQueue,sizeof(CEventQueue),NULL))
  237. {
  238. dprintf(" CEventQueue @ %p\n",pEventQueue);
  239. //m_aThreads : CFlexArray
  240. dprintf(" elems %d pointer %p\n",pEventQueue->m_aThreads.m_nSize,pEventQueue->m_aThreads.m_pArray);
  241. CExecQueue::CThreadRecord ** pRecord_OOP = (CExecQueue::CThreadRecord **)_alloca(sizeof(void*)*pEventQueue->m_aThreads.m_nSize);
  242. if (ReadMemory((ULONG_PTR)pEventQueue->m_aThreads.m_pArray,pRecord_OOP,sizeof(void*)*pEventQueue->m_aThreads.m_nSize,0))
  243. {
  244. DWORD i;
  245. for (i=0;i<pEventQueue->m_aThreads.m_nSize;i++)
  246. {
  247. dprintf(" -- CThreadRecord %d\n",i);
  248. DumpRecord((ULONG_PTR)pRecord_OOP[i],
  249. hCurrentProcess,
  250. DumpCExecRequest);
  251. }
  252. }
  253. dprintf(" m_pHead %p\n",pEventQueue->m_pHead);
  254. dprintf(" m_pTail %p\n",pEventQueue->m_pTail);
  255. // here code for the list
  256. CEventQueue::CDeliverRequest * pReq = (CEventQueue::CDeliverRequest *)pEventQueue->m_pHead;
  257. DWORD i = 0;
  258. while (pReq)
  259. {
  260. dprintf(" ---- list - %d\n",i++);
  261. DEFINE_CPP_VAR(CEventQueue::CDeliverRequest,MyAsyncReq);
  262. CEventQueue::CDeliverRequest * pReqHERE = GET_CPP_VAR_PTR(CEventQueue::CDeliverRequest,MyAsyncReq);
  263. ReadMemory((ULONG_PTR)pReq,pReqHERE,sizeof(CEventQueue::CDeliverRequest),NULL);
  264. //dprintf(" %p %p\n",pReq,pReqHERE->m_pNext);
  265. DumpCExecRequest((ULONG_PTR)pReq);
  266. if (pReq == pEventQueue->m_pTail)
  267. break;
  268. pReq = (CEventQueue::CDeliverRequest *)pReqHERE->m_pNext;
  269. if (CheckControlC())
  270. break;
  271. }
  272. //
  273. dprintf(" m_lNumThreads %d \n",pEventQueue->m_lNumThreads);
  274. dprintf(" m_lNumIdle %d\n",pEventQueue->m_lNumIdle);
  275. dprintf(" m_lNumRequests %d\n",pEventQueue->m_lNumRequests);
  276. dprintf(" m_lMaxThreads %d\n",pEventQueue->m_lMaxThreads);
  277. dprintf(" m_lHiPriBound %d\n",pEventQueue->m_lHiPriBound);
  278. dprintf(" m_lHiPriMaxThreads %d\n",pEventQueue->m_lHiPriMaxThreads);
  279. dprintf(" m_lStartSlowdownCount %d\n",pEventQueue->m_lStartSlowdownCount);
  280. dprintf(" m_lAbsoluteLimitCount %d\n",pEventQueue->m_lAbsoluteLimitCount);
  281. dprintf(" m_lOneSecondDelayCount %d\n",pEventQueue->m_lOneSecondDelayCount);
  282. dprintf(" m_dblAlpha %f\n",pEventQueue->m_dblAlpha);
  283. dprintf(" m_dblBeta %f\n",pEventQueue->m_dblBeta);
  284. dprintf(" m_dwTimeout %x\n",pEventQueue->m_dwTimeout);
  285. dprintf(" m_pEss %p\n",pEventQueue->m_pEss);
  286. }
  287. else
  288. {
  289. dprintf("RM %p\n",pEventQueue_OOP);
  290. }
  291. }
  292. DECLARE_API(ess)
  293. {
  294. INIT_API();
  295. ULONG_PTR Addr = (ExtensionApis.lpGetExpressionRoutine)("wbemcore!g_pESS");
  296. VOID * pVoid= NULL;
  297. if (!Addr)
  298. {
  299. pVoid = (VOID *)(ExtensionApis.lpGetExpressionRoutine)(args);
  300. }
  301. if (Addr || pVoid)
  302. {
  303. if (Addr)
  304. ReadMemory(Addr,&pVoid,sizeof(pVoid),NULL);
  305. DEFINE_CPP_VAR(CEssObjectSink::XNewESS,varImp);
  306. CEssObjectSink::XNewESS * pImp = GET_CPP_VAR_PTR(CEssObjectSink::XNewESS,varImp);
  307. if (ReadMemory((ULONG_PTR)pVoid,pImp,sizeof(CEssObjectSink::XNewESS),NULL))
  308. {
  309. dprintf(" CEssObjectSink %p\n",pImp->m_pObject);
  310. DEFINE_CPP_VAR(CEssObjectSink,varCEssObjectSink);
  311. CEssObjectSink * pEssSink = GET_CPP_VAR_PTR(CEssObjectSink,varCEssObjectSink);
  312. if (ReadMemory((ULONG_PTR)pImp->m_pObject,pEssSink,sizeof(CEssObjectSink),NULL))
  313. {
  314. Print_CEventQueue((ULONG_PTR)pEssSink->m_pEss+FIELD_OFFSET(CEss,m_Queue),hCurrentProcess);
  315. dprintf(" m_pEss %p\n",pEssSink->m_pEss);
  316. dprintf(" m_bShutdown %08x\n",pEssSink->m_bShutdown);
  317. dprintf(" m_pCoreServices %p\n",pEssSink->m_pCoreServices);
  318. // CEss;
  319. DEFINE_CPP_VAR(CEss,varCEss);
  320. CEss * pEss = GET_CPP_VAR_PTR(CEss,varCEss);
  321. if (ReadMemory((ULONG_PTR)pEssSink->m_pEss,pEss,sizeof(CEss),NULL))
  322. {
  323. _Map * pMap = (_Map *)((BYTE *)pEssSink->m_pEss + FIELD_OFFSET(CEss,m_mapNamespaces));
  324. PrintMapCB(pMap,TRUE,CallBackEssNamespace);
  325. }
  326. else
  327. {
  328. dprintf("RM %p err %d\n",pEssSink->m_pEss,GetLastError());
  329. }
  330. }
  331. else
  332. {
  333. dprintf("RM %p err %d\n",pImp->m_pObject,GetLastError());
  334. }
  335. }
  336. else
  337. {
  338. dprintf("RM %p err %d\n",Addr,GetLastError());
  339. }
  340. }
  341. else
  342. {
  343. dprintf("invalid address %s\n",args);
  344. }
  345. }