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.

492 lines
13 KiB

  1. /*++
  2. Copyright (c) 2001-2001 Microsoft Corporation
  3. Module Name:
  4. provutil.cpp
  5. Revision History:
  6. ivanbrug jan 2001 created
  7. --*/
  8. #include <wmiexts.h>
  9. #include <utilfun.h>
  10. #include <malloc.h>
  11. #ifndef POLARITY
  12. #define POLARITY
  13. #endif
  14. #include <wbemint.h>
  15. #ifdef SetContext
  16. #undef SetContext
  17. #endif
  18. #include <ProvSubS.h>
  19. //#include <provregdecoupled.h>
  20. //#include <provdcaggr.h>
  21. typedef ULONG_PTR CServerObject_DecoupledClientRegistration_Element;
  22. typedef ULONG_PTR CDecoupledAggregator_IWbemProvider;
  23. #include <provfact.h>
  24. #include <provwsv.h>
  25. #include <provcache.h>
  26. //
  27. //
  28. // Dump the Provider cache
  29. //
  30. typedef WCHAR * WmiKey;
  31. typedef void * WmiElement;
  32. typedef WmiAvlTree<WmiKey,WmiElement>::WmiAvlNode Node;
  33. /*
  34. class Node {
  35. public:
  36. VOID * m_Key;
  37. Node * m_Left;
  38. Node * m_Right;
  39. Node * m_Parent;
  40. int m_Status;
  41. VOID * m_Element;
  42. };
  43. */
  44. class NodeBind;
  45. VOID DumpTreeBind(NodeBind * pNode_OOP,DWORD * pCount,BOOL * pbStop);
  46. VOID
  47. DumpTree(Node * pNode_OOP,DWORD * pCount,BOOL * pbStop)
  48. {
  49. if (!pNode_OOP)
  50. return;
  51. if (CheckControlC())
  52. {
  53. if(pbStop)
  54. *pbStop = TRUE;
  55. }
  56. if (pbStop)
  57. {
  58. if (*pbStop)
  59. return;
  60. }
  61. DEFINE_CPP_VAR(Node,MyNode);
  62. WCHAR pBuff[MAX_PATH+1];
  63. Node * pNode = GET_CPP_VAR_PTR(Node,MyNode);
  64. BOOL bRet;
  65. if (ReadMemory((ULONG_PTR)pNode_OOP,pNode,sizeof(Node),NULL))
  66. {
  67. DumpTree(pNode->m_Left,pCount,pbStop);
  68. //dprintf("--------\n");
  69. if (pCount) {
  70. *pCount++;
  71. };
  72. dprintf(" (L %p R %p P %p) %p\n",
  73. //pNode->m_Key,
  74. pNode->m_Left,
  75. pNode->m_Right,
  76. pNode->m_Parent,
  77. pNode->m_State);
  78. if (pNode->m_Key)
  79. {
  80. ReadMemory((ULONG_PTR)pNode->m_Key,pBuff,MAX_PATH*sizeof(WCHAR),NULL);
  81. pBuff[MAX_PATH] = 0;
  82. dprintf(" %S\n",pBuff);
  83. }
  84. dprintf(" - %p real %p\n",pNode->m_Element,((ULONG_PTR *)pNode->m_Element-4));
  85. if (pNode->m_Element)
  86. {
  87. GetVTable((MEMORY_ADDRESS)(pNode->m_Element));
  88. //
  89. // attention to the vtable trick !!!!
  90. //
  91. DEFINE_CPP_VAR(CServerObject_BindingFactory,MyFactory);
  92. CServerObject_BindingFactory * pBindF = GET_CPP_VAR_PTR(CServerObject_BindingFactory,MyFactory);
  93. ULONG_PTR AddrInner = (ULONG_PTR)((ULONG_PTR *)pNode->m_Element-4);
  94. if (ReadMemory(AddrInner,pBindF,sizeof(CServerObject_BindingFactory),NULL))
  95. {
  96. DumpTreeBind((NodeBind *)pBindF->m_Cache.m_Root,pCount,pbStop);
  97. }
  98. else
  99. {
  100. dprintf("RM %p\n",AddrInner);
  101. }
  102. }
  103. DumpTree(pNode->m_Right,pCount,pbStop);
  104. }
  105. else
  106. {
  107. dprintf("RM %p\n",pNode_OOP);
  108. }
  109. }
  110. template <typename WmiElement, typename WmiKey> struct WmiBasicNode
  111. {
  112. WmiElement m_Element ;
  113. WmiKey m_Key ;
  114. WmiBasicNode *m_Left ;
  115. WmiBasicNode *m_Right ;
  116. WmiBasicNode *m_Parent ;
  117. };
  118. typedef WmiBasicNode<void *, void *> VoidPtrNode;
  119. VOID
  120. DumpTreeVoidNode(VoidPtrNode * pNode_OOP,DWORD * pCount,BOOL * pbStop)
  121. {
  122. if (!pNode_OOP) return;
  123. //dprintf("-%p\n",pNode_OOP);
  124. if (CheckControlC()){ if(pbStop) *pbStop = TRUE; }
  125. if (pbStop) { if (*pbStop) return; }
  126. DEFINE_CPP_VAR(VoidPtrNode,MyNode);
  127. VoidPtrNode * pNode = GET_CPP_VAR_PTR(VoidPtrNode,MyNode);
  128. BOOL bRet;
  129. static WCHAR pBuff[MAX_PATH+1];
  130. if (ReadMemory((ULONG_PTR)pNode_OOP,pNode,sizeof(VoidPtrNode),NULL))
  131. {
  132. DumpTreeVoidNode((VoidPtrNode *)pNode->m_Left,pCount,pbStop);
  133. //dprintf("--------\n");
  134. if (pCount) { *pCount++; };
  135. dprintf(" (L %p R %p P %p)\n",
  136. pNode->m_Left,
  137. pNode->m_Right,
  138. pNode->m_Parent);
  139. dprintf(" - Element %p\n",pNode->m_Element);
  140. if (pNode->m_Element)
  141. {
  142. GetVTable((MEMORY_ADDRESS)(pNode->m_Element));
  143. DEFINE_CPP_VAR(CInterceptor_IWbemProvider,varProv);
  144. CInterceptor_IWbemProvider * pProv = GET_CPP_VAR_PTR(CInterceptor_IWbemProvider,varProv);
  145. BOOL bRet;
  146. if (ReadMemory((ULONG_PTR)pNode->m_Element,pProv,sizeof(CInterceptor_IWbemProvider),NULL))
  147. {
  148. if (pProv->m_Key.m_Provider)
  149. {
  150. ReadMemory((ULONG_PTR)pProv->m_Key.m_Provider,pBuff,MAX_PATH*sizeof(WCHAR),NULL);
  151. pBuff[MAX_PATH] = 0;
  152. dprintf(" Provider: %S\n",pBuff);
  153. }
  154. else
  155. {
  156. dprintf(" Provider: %p\n",0);
  157. }
  158. dprintf(" Hosting : %08x\n",pProv->m_Key.m_Hosting);
  159. if (pProv->m_Key.m_Group)
  160. {
  161. ReadMemory((ULONG_PTR)pProv->m_Key.m_Group,pBuff,MAX_PATH*sizeof(WCHAR),NULL);
  162. pBuff[MAX_PATH] = 0;
  163. dprintf(" Group : %S\n",pBuff);
  164. }
  165. else
  166. {
  167. dprintf(" Group : %p\n",0);
  168. }
  169. }
  170. else
  171. {
  172. dprintf("RM %p\n",pNode->m_Element);
  173. }
  174. }
  175. DumpTreeVoidNode((VoidPtrNode *)pNode->m_Right,pCount,pbStop);
  176. }
  177. else
  178. {
  179. dprintf("RM %p\n",pNode_OOP);
  180. }
  181. }
  182. typedef WmiAvlTree<long,long>::WmiAvlNode NodeLong;
  183. VOID
  184. DumpTreeNodeLong(NodeLong * pNodeLong_OOP,DWORD * pCount,BOOL * pbStop)
  185. {
  186. if (!pNodeLong_OOP)
  187. return;
  188. if (CheckControlC()) { if(pbStop) *pbStop = TRUE; }
  189. if (pbStop) { if (*pbStop) return; }
  190. DEFINE_CPP_VAR(NodeLong,MyNode);
  191. NodeLong * pNode = GET_CPP_VAR_PTR(NodeLong,MyNode);
  192. BOOL bRet;
  193. if (ReadMemory((ULONG_PTR)pNodeLong_OOP,pNode,sizeof(NodeLong),NULL))
  194. {
  195. DumpTreeNodeLong((NodeLong *)pNode->m_Left,pCount,pbStop);
  196. if (pCount) {
  197. *pCount++;
  198. };
  199. dprintf(" (L %p R %p P %p) %p\n",
  200. pNode->m_Left,
  201. pNode->m_Right,
  202. pNode->m_Parent,
  203. pNode->m_State);
  204. dprintf(" - pid %p ProviderController %p\n",pNode->m_Key,pNode->m_Element);
  205. if (pNode->m_Element)
  206. {
  207. GetVTable((MEMORY_ADDRESS)(pNode->m_Element));
  208. DEFINE_CPP_VAR(ProviderController,varCtrl);
  209. ProviderController * pCtrl = GET_CPP_VAR_PTR(ProviderController,varCtrl);
  210. if (ReadMemory((ULONG_PTR)pNode->m_Element,pCtrl,sizeof(ProviderController),NULL))
  211. {
  212. DWORD dwCount = 0;
  213. BOOL bStop = FALSE;
  214. DumpTreeVoidNode((VoidPtrNode *)pCtrl->m_Container.m_Root,&dwCount,&bStop);
  215. }
  216. else
  217. {
  218. dprintf("RM %p\n",pNode->m_Element);
  219. }
  220. }
  221. DumpTreeNodeLong((NodeLong *)pNode->m_Right,pCount,pbStop);
  222. }
  223. else
  224. {
  225. dprintf("RM %p\n",pNodeLong_OOP);
  226. }
  227. }
  228. DECLARE_API(pc)
  229. {
  230. INIT_API();
  231. ULONG_PTR Addr = GetExpression("wbemcore!CCoreServices__m_pProvSS");
  232. if (Addr)
  233. {
  234. CServerObject_ProviderSubSystem * pProvSS_OOP = NULL;
  235. if (ReadMemory(Addr,&pProvSS_OOP,sizeof(void *),NULL))
  236. {
  237. dprintf("pProvSS %p\n",pProvSS_OOP);
  238. BOOL bRet;
  239. DEFINE_CPP_VAR(CServerObject_ProviderSubSystem,MyProvSS);
  240. CServerObject_ProviderSubSystem * pProvSS = GET_CPP_VAR_PTR(CServerObject_ProviderSubSystem,MyProvSS);
  241. if (ReadMemory((ULONG_PTR)pProvSS_OOP,pProvSS,sizeof(CServerObject_ProviderSubSystem),NULL))
  242. {
  243. DEFINE_CPP_VAR(CWbemGlobal_IWmiFactoryController_Cache,MyCacheNode);
  244. CWbemGlobal_IWmiFactoryController_Cache * pNodeCache = NULL; //GET_CPP_VAR_PTR(CWbemGlobal_IWmiFactoryController_Cache CacheNode,MyCacheNode);
  245. pNodeCache = &pProvSS->m_Cache;
  246. //dprintf(" root %p\n",pNodeCache->m_Root);
  247. DWORD Count = 0;
  248. BOOL bStop = FALSE;
  249. DumpTree((Node *)pNodeCache->m_Root,&Count,&bStop);
  250. //dprintf("traversed %d nodes\n",Count);
  251. }
  252. else
  253. {
  254. dprintf("RM %p\n",pProvSS_OOP);
  255. }
  256. }
  257. else
  258. {
  259. dprintf("RM %p\n",Addr);
  260. }
  261. }
  262. else
  263. {
  264. dprintf("invalid address %s\n",args);
  265. }
  266. Addr = GetExpression("wmiprvsd!ProviderSubSystem_Globals__s_HostedProviderController");
  267. if (Addr)
  268. {
  269. if (ReadMemory(Addr,&Addr,sizeof(ULONG_PTR),NULL))
  270. {
  271. dprintf("CWbemGlobal_HostedProviderController %p\n",Addr);
  272. DEFINE_CPP_VAR(CWbemGlobal_HostedProviderController,varHostedCtrl);
  273. CWbemGlobal_HostedProviderController * pHostedCtrl = GET_CPP_VAR_PTR(CWbemGlobal_HostedProviderController,varHostedCtrl);
  274. if (ReadMemory(Addr,pHostedCtrl,sizeof(CWbemGlobal_HostedProviderController),NULL))
  275. {
  276. DWORD dwCount = 0;
  277. BOOL bStop = FALSE;
  278. DumpTreeNodeLong((NodeLong *)pHostedCtrl->m_Container.m_Root,&dwCount,&bStop);
  279. }
  280. else
  281. {
  282. dprintf("RM %p\n",Addr);
  283. }
  284. }
  285. else
  286. {
  287. dprintf("RM %p\n",Addr);
  288. }
  289. }
  290. else
  291. {
  292. dprintf("unable to resolve wmiprvsd!ProviderSubSystem_Globals__s_HostedProviderController\n");
  293. }
  294. }
  295. //
  296. //
  297. // CServerObject_BindingFactory
  298. //
  299. //////////////
  300. class NodeBind
  301. {
  302. public:
  303. ProviderCacheKey m_Key;
  304. NodeBind * m_Left;
  305. NodeBind * m_Right;
  306. NodeBind * m_Parent;
  307. int m_State;
  308. //WmiCacheController<ProviderCacheKey>::WmiCacheElement
  309. void * m_Element;
  310. };
  311. VOID
  312. DumpTreeBind(NodeBind * pNode_OOP,DWORD * pCount,BOOL * pbStop)
  313. {
  314. //dprintf("%p ????\n",pNode_OOP);
  315. if (!pNode_OOP)
  316. return;
  317. if (CheckControlC())
  318. {
  319. if(pbStop)
  320. *pbStop = TRUE;
  321. }
  322. if (pbStop)
  323. {
  324. if (*pbStop)
  325. return;
  326. }
  327. DEFINE_CPP_VAR(NodeBind,MyNode);
  328. static WCHAR pBuff[MAX_PATH+1];
  329. NodeBind * pNode = GET_CPP_VAR_PTR(NodeBind,MyNode);
  330. BOOL bRet;
  331. if (ReadMemory((ULONG_PTR)pNode_OOP,pNode,sizeof(NodeBind),NULL))
  332. {
  333. DumpTreeBind(pNode->m_Left,pCount,pbStop);
  334. //dprintf("--------\n");
  335. if (pCount) {
  336. *pCount++;
  337. };
  338. dprintf(" - (L %p R %p P %p) %p\n",
  339. pNode->m_Left,
  340. pNode->m_Right,
  341. pNode->m_Parent,
  342. pNode->m_State);
  343. if (pNode->m_Key.m_Provider)
  344. {
  345. ReadMemory((ULONG_PTR)pNode->m_Key.m_Provider,pBuff,MAX_PATH*sizeof(WCHAR),NULL);
  346. pBuff[MAX_PATH] = 0;
  347. dprintf(" Provider: %S\n",pBuff);
  348. }
  349. else
  350. {
  351. dprintf(" Provider: %p\n",0);
  352. }
  353. dprintf(" Hosting : %08x\n",pNode->m_Key.m_Hosting);
  354. if (pNode->m_Key.m_Group)
  355. {
  356. ReadMemory((ULONG_PTR)pNode->m_Key.m_Group,pBuff,MAX_PATH*sizeof(WCHAR),NULL);
  357. pBuff[MAX_PATH] = 0;
  358. dprintf(" Group : %S\n",pBuff);
  359. }
  360. else
  361. {
  362. dprintf(" Group : %p\n",0);
  363. }
  364. dprintf(" - %p\n",pNode->m_Element);
  365. if (pNode->m_Element)
  366. {
  367. GetVTable((MEMORY_ADDRESS)(pNode->m_Element));
  368. }
  369. DumpTreeBind(pNode->m_Right,pCount,pbStop);
  370. }
  371. else
  372. {
  373. dprintf("RM %p\n",pNode_OOP);
  374. }
  375. }
  376. DECLARE_API(pf)
  377. {
  378. INIT_API();
  379. ULONG_PTR Addr = GetExpression(args);
  380. if (Addr)
  381. {
  382. DEFINE_CPP_VAR(CServerObject_BindingFactory,MyFactory);
  383. CServerObject_BindingFactory * pBindF = GET_CPP_VAR_PTR(CServerObject_BindingFactory,MyFactory);
  384. BOOL bRet;
  385. bRet = ReadMemory(Addr,pBindF,sizeof(CServerObject_BindingFactory),NULL);
  386. if (bRet)
  387. {
  388. dprintf(" root %p\n",pBindF->m_Cache.m_Root);
  389. DWORD Count = 0;
  390. BOOL bStop = FALSE;
  391. DumpTreeBind((NodeBind *)pBindF->m_Cache.m_Root,&Count,&bStop);
  392. }
  393. }
  394. else
  395. {
  396. dprintf("invalid address %s\n",args);
  397. }
  398. }