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.

261 lines
6.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: doxid.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to display COXID table
  9. //
  10. // Functions: oxidHelp
  11. // displayOxid
  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 ScanCLSID(LPSTR lpsz, CLSID *pClsid);
  24. ULONG ScanAddr(char *lpsz);
  25. static char *aszProtSeq[] = {/* 0x00 */ 0,
  26. /* 0x01 */ "mswmsg",
  27. /* 0x02 */ 0,
  28. /* 0x03 */ 0,
  29. /* 0x04 */ "ncacn_dnet_dsp",
  30. /* 0x05 */ 0,
  31. /* 0x06 */ 0,
  32. /* 0x07 */ "ncacn_ip_tcp",
  33. /* 0x08 */ "ncadg_ip_udp",
  34. /* 0x09 */ "ncacn_nb_tcp",
  35. /* 0x0a */ 0,
  36. /* 0x0b */ 0,
  37. /* 0x0c */ "ncacn_spx",
  38. /* 0x0d */ "ncacn_nb_ipx",
  39. /* 0x0e */ "ncadg_ipx",
  40. /* 0x0f */ "ncacn_np",
  41. /* 0x10 */ "ncalrpc",
  42. /* 0x11 */ 0,
  43. /* 0x12 */ 0,
  44. /* 0x13 */ "ncacn_nb_nb"};
  45. //+-------------------------------------------------------------------------
  46. //
  47. // Function: oxidHelp
  48. //
  49. // Synopsis: Display a menu for the command 'id'
  50. //
  51. // Arguments: -
  52. //
  53. // Returns: -
  54. //
  55. // History: 21-Aug-95 BruceMa Created
  56. //
  57. //--------------------------------------------------------------------------
  58. void oxidHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  59. {
  60. Printf("\nox - Display entire OXID table:\n");
  61. Printf("addr oxid\n");
  62. Printf("...\n\n");
  63. Printf("ox addr - Display specific OXID entry:\n");
  64. Printf("oxid serverPid serverTid flags hRpc IRemUnknown* runDownIPID refs stringBindings\n");
  65. }
  66. //+-------------------------------------------------------------------------
  67. //
  68. // Function: displayOxid
  69. //
  70. // Synopsis: Display the entire OXID table
  71. //
  72. // Arguments: [hProcess] - Handle of this process
  73. // [lpExtensionApis] - Table of extension functions
  74. //
  75. // Returns: -
  76. //
  77. // History: 21-Aug-95 BruceMa Created
  78. //
  79. //--------------------------------------------------------------------------
  80. void displayOxid(HANDLE hProcess,
  81. PNTSD_EXTENSION_APIS lpExtensionApis)
  82. {
  83. ULONG pAdr;
  84. SOXIDEntry *pOXIDentry;
  85. SOXIDEntry *pFirstOXIDentry;
  86. SOXIDEntry sOXIDentry;
  87. char szGuid[CLSIDSTR_MAX];
  88. STRINGARRAY *pBindings;
  89. ULONG ulSize;
  90. // Read the address of the first in use OXID entry
  91. pAdr = GetExpression("ole32!COXIDTable___InUseHead");
  92. pFirstOXIDentry = (SOXIDEntry *) pAdr;
  93. ReadMem(&pOXIDentry, pAdr + sizeof(ULONG), sizeof(SOXIDEntry *));
  94. // Do over in use OXID entries
  95. do
  96. {
  97. // Read the next OXID entry
  98. ReadMem(&sOXIDentry, pOXIDentry, sizeof(SOXIDEntry));
  99. // Print the address
  100. Printf("%x ", pOXIDentry);
  101. // Print the OXID
  102. FormatCLSID((GUID &) sOXIDentry.oxid, szGuid);
  103. Printf("%s\n", szGuid);
  104. // Go to the next in use OXID entry
  105. pOXIDentry = sOXIDentry.pNext;
  106. // Just in case
  107. if (CheckControlC())
  108. {
  109. return;
  110. }
  111. } until_(pOXIDentry == pFirstOXIDentry);
  112. }
  113. //+-------------------------------------------------------------------------
  114. //
  115. // Function: displayOxidEntry
  116. //
  117. // Synopsis: Display an entry in the OXID table
  118. //
  119. // Arguments: [hProcess] - Handle of this process
  120. // [lpExtensionApis] - Table of extension functions
  121. // [arg] - OXID of entry to display
  122. //
  123. // Returns: -
  124. //
  125. // History: 21-Aug-95 BruceMa Created
  126. //
  127. //--------------------------------------------------------------------------
  128. void displayOxidEntry(HANDLE hProcess,
  129. PNTSD_EXTENSION_APIS lpExtensionApis,
  130. char *arg)
  131. {
  132. OXID oxid;
  133. ULONG pAdr;
  134. SOXIDEntry *pOXIDentry;
  135. SOXIDEntry *pFirstOXIDentry;
  136. SOXIDEntry sOXIDentry;
  137. char szGuid[CLSIDSTR_MAX];
  138. STRINGARRAY *pBindings;
  139. ULONG ulSize;
  140. // Check for help
  141. if (arg[0] == '?')
  142. {
  143. Printf("oxid serverPid serverTid flags hRpc IRemUnknown* runDownIPID refs stringBindings\n");
  144. return;
  145. }
  146. // Convert the argument to an OXID
  147. pAdr = ScanAddr(arg);
  148. // Read the OXID entry
  149. ReadMem(&sOXIDentry, pAdr, sizeof(SOXIDEntry));
  150. // OXID
  151. FormatCLSID((GUID &) sOXIDentry.oxid, szGuid);
  152. Printf("%s ", szGuid);
  153. // Server PID
  154. Printf("%3x ", sOXIDentry.dwPid);
  155. // Server TID
  156. Printf("%3x ", sOXIDentry.dwTid);
  157. // Flags
  158. if (sOXIDentry.dwFlags & OXIDF_REGISTERED)
  159. {
  160. Printf("R");
  161. }
  162. if (sOXIDentry.dwFlags & OXIDF_MACHINE_LOCAL)
  163. {
  164. Printf("L");
  165. }
  166. if (sOXIDentry.dwFlags & OXIDF_STOPPED)
  167. {
  168. Printf("S");
  169. }
  170. if (sOXIDentry.dwFlags & OXIDF_PENDINGRELEASE)
  171. {
  172. Printf("P");
  173. }
  174. Printf(" ");
  175. // RPC binding handle
  176. Printf("%x ", sOXIDentry.hServer);
  177. // Proxy for RemUnknown
  178. Printf("%x ", sOXIDentry.pRU);
  179. // IPID of IRunDown and Remote Unknown
  180. Printf("[%d.%d %3x %3x %d] ",
  181. sOXIDentry.ipidRundown.page,
  182. sOXIDentry.ipidRundown.offset,
  183. sOXIDentry.ipidRundown.pid,
  184. sOXIDentry.ipidRundown.tid,
  185. sOXIDentry.ipidRundown.seq);
  186. // References
  187. Printf("%d\n ", sOXIDentry.cRefs);
  188. // Print the string bindings
  189. ReadMem(&ulSize, sOXIDentry.psa, sizeof(ULONG));
  190. pBindings = (STRINGARRAY *) OleAlloc(ulSize * sizeof(WCHAR));
  191. ReadMem(pBindings, sOXIDentry.psa, ulSize * sizeof(WCHAR));
  192. // Do over protocol sequence/network address pairs
  193. for (UINT k = 0; k < ulSize - 2 ||
  194. pBindings->awszStringArray[k] == 0; )
  195. {
  196. char *pszProtSeq;
  197. // The protocol sequence
  198. pszProtSeq = aszProtSeq[pBindings->awszStringArray[k]];
  199. if (pszProtSeq == NULL)
  200. {
  201. Printf("%d", pBindings->awszStringArray[k]);
  202. }
  203. else
  204. {
  205. Printf("%s", pszProtSeq);
  206. }
  207. k++;
  208. // The network address
  209. Printf("%ws ", &pBindings->awszStringArray[k]);
  210. k += lstrlenW(&pBindings->awszStringArray[k]) + 1;
  211. }
  212. Printf("\n");
  213. OleFree(pBindings);
  214. }