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.

341 lines
8.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: dipid.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to display CIPID table
  9. //
  10. // Functions: ipidHelp
  11. // displayIpid
  12. //
  13. //
  14. // History: 21-Aug-95 BruceMa Created
  15. //
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <ole2int.h>
  19. #include <windows.h>
  20. #include "ole.h"
  21. #include "dipid.h"
  22. void FormatCLSID(REFGUID rguid, LPSTR lpsz);
  23. BOOL GetRegistryInterfaceName(REFIID iid, char *szValue, DWORD *pcbValue);
  24. ULONG ScanAddr(char *lpsz);
  25. //+-------------------------------------------------------------------------
  26. //
  27. // Function: ipidHelp
  28. //
  29. // Synopsis: Display a menu for the command 'id'
  30. //
  31. // Arguments: -
  32. //
  33. // Returns: -
  34. //
  35. // History: 21-Aug-95 BruceMa Created
  36. //
  37. //--------------------------------------------------------------------------
  38. void ipidHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  39. {
  40. Printf("\nip - Display entire IPID table:\n");
  41. Printf("index IPID oxidAddr nextIPIDsameObj\n");
  42. Printf("...\n\n");
  43. Printf("ip ipid - Display specific IPID entry:\n");
  44. Printf("PID TID seq IID ChnlBfr* prxy/stub realPv oxidAddr flags strongRefs weakRefs nextIPIDsameObj\n");
  45. }
  46. //+-------------------------------------------------------------------------
  47. //
  48. // Function: displayIpid
  49. //
  50. // Synopsis: Display the entire IPID table
  51. //
  52. // Arguments: [hProcess] - Handle of this process
  53. // [lpExtensionApis] - Table of extension functions
  54. //
  55. // Returns: -
  56. //
  57. // History: 21-Aug-95 BruceMa Created
  58. //
  59. //--------------------------------------------------------------------------
  60. void displayIpid(HANDLE hProcess,
  61. PNTSD_EXTENSION_APIS lpExtensionApis)
  62. {
  63. ULONG pAdr;
  64. ULONG pStart;
  65. ULONG pEnd;
  66. UINT cPages;
  67. SIPIDEntry **pIndexTable;
  68. SIPIDEntry sIPIDentry[IPIDsPerPage];
  69. SOXIDEntry sOXIDentry;
  70. char szGuid[CLSIDSTR_MAX];
  71. // Read the IPID page index table
  72. pAdr = GetExpression("ole32!CIPIDTable___pTbl");
  73. ReadMem(&pStart, pAdr, sizeof(SIPIDEntry **));
  74. pAdr = GetExpression("ole32!CIPIDTable___pTblEnd");
  75. ReadMem(&pEnd, pAdr, sizeof(SIPIDEntry **));
  76. cPages = (pEnd - pStart) / sizeof(SIPIDEntry **);
  77. pIndexTable = (SIPIDEntry **) OleAlloc(cPages * sizeof(SIPIDEntry *));
  78. ReadMem(pIndexTable, pStart, cPages * sizeof(SIPIDEntry *));
  79. // Do over IPID entry pages
  80. for (UINT k = 0; k < cPages; k++)
  81. {
  82. // Read the next page of IPID entries
  83. ReadMem(sIPIDentry, pIndexTable[k], IPIDTBL_PAGESIZE);
  84. // Do over entries within this page
  85. for (UINT j = 0; j < IPIDsPerPage; j++)
  86. {
  87. // Only look at non-vacant entries
  88. if (!(sIPIDentry[j].dwFlags & IPIDF_VACANT))
  89. {
  90. // Print the page/offset for this entry
  91. Printf("%d.%d ", k, j);
  92. // Print the IPID
  93. if (sIPIDentry[j].ipid.page > 1000 ||
  94. sIPIDentry[j].ipid.page < 0)
  95. {
  96. FormatCLSID((GUID &) sIPIDentry[j].ipid, szGuid);
  97. Printf("%s ", szGuid);
  98. }
  99. else
  100. {
  101. Printf("[%d.%d %3x %3x %d] ",
  102. sIPIDentry[j].ipid.page,
  103. sIPIDentry[j].ipid.offset,
  104. sIPIDentry[j].ipid.pid,
  105. sIPIDentry[j].ipid.tid,
  106. sIPIDentry[j].ipid.seq);
  107. }
  108. // Print the associated OXID addr
  109. Printf("%x ", sIPIDentry[j].pOXIDEntry);
  110. // Next IPID for this object
  111. if (sIPIDentry[j].iNextOID != -1)
  112. {
  113. Printf("%d.%d\n",
  114. sIPIDentry[j].iNextOID >> 16,
  115. sIPIDentry[j].iNextOID & 0xffff);
  116. }
  117. else
  118. {
  119. Printf("NULL\n");
  120. }
  121. }
  122. }
  123. }
  124. // Release resources
  125. OleFree(pIndexTable);
  126. }
  127. //+-------------------------------------------------------------------------
  128. //
  129. // Function: displayIpidEntry
  130. //
  131. // Synopsis: Display an entry in the IPID table
  132. //
  133. // Arguments: [hProcess] - Handle of this process
  134. // [lpExtensionApis] - Table of extension functions
  135. // [arg] - IPID of entry to display
  136. //
  137. // Returns: -
  138. //
  139. // History: 21-Aug-95 BruceMa Created
  140. //
  141. //--------------------------------------------------------------------------
  142. void displayIpidEntry(HANDLE hProcess,
  143. PNTSD_EXTENSION_APIS lpExtensionApis,
  144. char *arg)
  145. {
  146. char *s;
  147. IPID ipid;
  148. ULONG ppIPIDentry;;
  149. SIPIDEntry *pIPIDentry;
  150. SIPIDEntry sIPIDentry;
  151. char szGuid[CLSIDSTR_MAX];
  152. SOXIDEntry sOXID;
  153. // Check for help
  154. if (arg[0] == '?')
  155. {
  156. Printf("PID TID seq IID ChnlBfr* prxy/stub realPv oxidAddr flags strongRefs weakRefs nextIPIDsameObj\n");
  157. return;
  158. }
  159. // arg may be either page.offset or a hex address
  160. BOOL fAdr = TRUE;
  161. for (s = arg; *s; s++)
  162. {
  163. if (*s == '.')
  164. {
  165. fAdr = FALSE;
  166. }
  167. }
  168. // The argument is a hex address
  169. if (fAdr)
  170. {
  171. pIPIDentry = (SIPIDEntry *) ScanAddr(arg);
  172. }
  173. // The argment has the form page.offset
  174. else
  175. {
  176. // Make sure the argument looks like an IPID
  177. BOOL fOk = TRUE;
  178. UINT cPoint = 0;
  179. if (!IsDecimal(arg[0]))
  180. {
  181. fOk = FALSE;
  182. }
  183. for (s = arg; *s; s++)
  184. {
  185. if (*s != '.' && !IsDecimal(*s))
  186. {
  187. fOk = FALSE;
  188. }
  189. if (*s == '.')
  190. {
  191. cPoint++;
  192. }
  193. }
  194. if (!IsDecimal(*(s - 1)))
  195. {
  196. fOk = FALSE;
  197. }
  198. if (!(fOk && cPoint == 1))
  199. {
  200. Printf("...%s is not an IPID\n", arg);
  201. return;
  202. }
  203. // Convert the argument to an IPID
  204. for (ipid.page = 0; *arg && *arg != '.'; arg++)
  205. {
  206. ipid.page = 10 * ipid.page + *arg - '0';
  207. }
  208. for (arg++, ipid.offset = 0; *arg; arg++)
  209. {
  210. ipid.offset = 10 * ipid.offset + *arg - '0';
  211. }
  212. // Read the address of the page containing the entry we want
  213. ppIPIDentry = GetExpression("ole32!CIPIDTable___pTbl");
  214. ReadMem(&ppIPIDentry, ppIPIDentry, sizeof(SIPIDEntry **));
  215. ppIPIDentry += ipid.page * sizeof(SIPIDEntry **);
  216. ReadMem(&pIPIDentry, ppIPIDentry, sizeof(SIPIDEntry *));
  217. // Compute the address of the entry we're seeking
  218. pIPIDentry += ipid.offset;
  219. }
  220. // Now read the entry
  221. ReadMem(&sIPIDentry, pIPIDentry, sizeof(SIPIDEntry));
  222. // Check whether the entry is vacant
  223. if (sIPIDentry.dwFlags & IPIDF_VACANT)
  224. {
  225. Printf("VACANT\n");
  226. return;
  227. }
  228. // The ipid may just be a GUID; e.g. client side scm interfaces
  229. if (sIPIDentry.ipid.page >> 1000 || sIPIDentry.ipid.page < 0)
  230. {
  231. FormatCLSID((GUID &) sIPIDentry.ipid, szGuid);
  232. Printf("%s ", szGuid);
  233. }
  234. else
  235. {
  236. // Server PID
  237. Printf("%3x ", sIPIDentry.ipid.pid);
  238. // Server TID
  239. Printf("%3x ", sIPIDentry.ipid.tid);
  240. // Sequence number
  241. Printf("%d ", sIPIDentry.ipid.seq);
  242. }
  243. // IID
  244. DWORD cbValue;
  245. if (!GetRegistryInterfaceName(sIPIDentry.iid, szGuid, &cbValue))
  246. {
  247. FormatCLSID(sIPIDentry.iid, szGuid);
  248. }
  249. Printf("%s ", szGuid);
  250. // CRpcChannelBuffer *
  251. Printf("%x ", sIPIDentry.pChnl);
  252. // Address of proxy/stub
  253. Printf("%x ", sIPIDentry.pStub);
  254. // Real interface pinter
  255. Printf("%x ", sIPIDentry.pv);
  256. // Associated OXID
  257. Printf("%x ", sIPIDentry.pOXIDEntry);
  258. // Flags
  259. if (sIPIDentry.dwFlags & IPIDF_CONNECTING)
  260. {
  261. Printf("C");
  262. }
  263. if (sIPIDentry.dwFlags & IPIDF_DISCONNECTED)
  264. {
  265. Printf("D");
  266. }
  267. if (sIPIDentry.dwFlags & IPIDF_SERVERENTRY)
  268. {
  269. Printf("S");
  270. }
  271. if (sIPIDentry.dwFlags & IPIDF_NOPING)
  272. {
  273. Printf("N");
  274. }
  275. Printf(" ole32!CCacheEnum__Skip+0x82");
  276. // Strong references
  277. Printf("%d ", sIPIDentry.cStrongRefs);
  278. // Weak references
  279. Printf("%d ", sIPIDentry.cWeakRefs);
  280. // Next IPID for this object (if any)
  281. if (sIPIDentry.iNextOID != -1)
  282. {
  283. Printf("%d.%d\n",
  284. sIPIDentry.iNextOID >> 16,
  285. sIPIDentry.iNextOID & 0xffff);
  286. }
  287. else
  288. {
  289. Printf("NULL\n");
  290. }
  291. }