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.

322 lines
9.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: drot.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to display the ROT
  9. //
  10. // Functions: displayRot
  11. //
  12. //
  13. // History: 06-01-95 BruceMa Created
  14. // 06-26-95 BruceMa Add SCM ROT support
  15. //
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <ole2int.h>
  19. #include <windows.h>
  20. #include "ole.h"
  21. #include "drot.h"
  22. void FormatCLSID(REFGUID rguid, LPSTR lpsz);
  23. //+-------------------------------------------------------------------------
  24. //
  25. // Function: cliRotHelp
  26. //
  27. // Synopsis: Display a menu for the command 'rt'
  28. //
  29. // Arguments: -
  30. //
  31. // Returns: -
  32. //
  33. // History: 01-Jun-95 BruceMa Created
  34. //
  35. //--------------------------------------------------------------------------
  36. void cliRotHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  37. {
  38. Printf("rt - Display the Running Object Table:\n");
  39. Printf("Client side ROT\n");
  40. Printf("sig\tcall?\t(scmLoc scmId)\thApt\n");
  41. Printf("...\n\n");
  42. Printf("Client side hint table\n");
  43. Printf("<indices of set indicators>\n");
  44. }
  45. //+-------------------------------------------------------------------------
  46. //
  47. // Function: scmRotHelp
  48. //
  49. // Synopsis: Display a menu for the command 'rt'
  50. //
  51. // Arguments: -
  52. //
  53. // Returns: -
  54. //
  55. // History: 01-Jun-95 BruceMa Created
  56. //
  57. //--------------------------------------------------------------------------
  58. void scmRotHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  59. {
  60. Printf("rt - Display the Running Object Table:\n");
  61. Printf("Client side ROT\n");
  62. Printf("sig\tcall?\t(scmLoc scmId)\thApt\n");
  63. Printf("...\n\n");
  64. Printf("Client side hint table\n");
  65. Printf("<indices of set indicators>\n");
  66. }
  67. //+-------------------------------------------------------------------------
  68. //
  69. // Function: displayCliRot
  70. //
  71. // Synopsis: Formats and writes an ole processes' version of the
  72. // ROT to the debug terminal
  73. //
  74. // Arguments: [hProcess] - Handle of this process
  75. // [lpExtensionApis] - Table of extension functions
  76. //
  77. // Returns: -
  78. //
  79. // History: 01-Jun-95 BruceMa Created
  80. //
  81. //--------------------------------------------------------------------------
  82. void displayCliRot(HANDLE hProcess, PNTSD_EXTENSION_APIS lpExtensionApis)
  83. {
  84. ULONG padr;
  85. SRunningObjectTable *psRot;
  86. SRunningObjectTable sRot;
  87. SRotItem sRotItm;
  88. SRotItem **ppsRotItm;
  89. SRotItem *psRotItm;
  90. int cSize;
  91. // Read the CRunningObjectTable
  92. padr = GetExpression("ole32!pRot");
  93. ReadMem(&psRot, padr, sizeof(SRunningObjectTable *));
  94. ReadMem(&sRot, psRot, sizeof(SRunningObjectTable));
  95. // Read the array of pointers to ROT items
  96. UINT ulSize = sRot._afvRotList.m_nSize * sizeof(SRotItem *);
  97. ppsRotItm = (SRotItem **) OleAlloc(ulSize);
  98. ReadMem(ppsRotItm, sRot._afvRotList.m_pData, ulSize);
  99. // Display the ROT items in the table
  100. Printf("Client side ROT\n");
  101. for (cSize = 0; cSize < sRot._afvRotList.m_nSize; cSize++)
  102. {
  103. psRotItm = ppsRotItm[cSize];
  104. if (psRotItm != NULL)
  105. {
  106. // Fetch the next ROT item
  107. ReadMem(&sRotItm, psRotItm, sizeof(SRotItem));
  108. // Display this ROT item
  109. if (sRotItm._fDontCallApp)
  110. {
  111. Printf("%d\tTRUE\t(0x%p %x)\t%x\n",
  112. sRotItm._wItemSig,
  113. sRotItm._scmregkey.dwEntryLoc,
  114. sRotItm._scmregkey.dwScmId,
  115. sRotItm._hApt);
  116. }
  117. else
  118. {
  119. Printf("%d\tFALSE\t(0x%p %x)\t%x\n",
  120. sRotItm._wItemSig,
  121. sRotItm._scmregkey.dwEntryLoc,
  122. sRotItm._scmregkey.dwScmId,
  123. sRotItm._hApt);
  124. }
  125. }
  126. }
  127. // Display the client side ROT hint table
  128. BYTE *pHint;
  129. UINT k, l;
  130. // Read the client side ROT hint table
  131. pHint = (BYTE *) OleAlloc(SCM_HASH_SIZE * sizeof(DWORD));
  132. ReadMem(pHint, sRot._crht._pbHintArray, SCM_HASH_SIZE * sizeof(BYTE));
  133. // Display the client side hint table
  134. Printf("\nClient side hint table\n");
  135. for (l = 0, k = 0; k < SCM_HASH_SIZE; k++)
  136. {
  137. if (l == 16)
  138. {
  139. Printf("\n");
  140. l = 0;
  141. }
  142. if (pHint[k])
  143. {
  144. Printf("%02d ", k);
  145. l++;
  146. }
  147. }
  148. if (l > 1)
  149. {
  150. Printf("\n");
  151. }
  152. // Delete resources
  153. OleFree(ppsRotItm);
  154. OleFree(pHint);
  155. }
  156. //+-------------------------------------------------------------------------
  157. //
  158. // Function: displayScmRot
  159. //
  160. // Synopsis: Formats and writes the full ROT to the debug terminal
  161. //
  162. // Arguments: [hProcess] - Handle of this process
  163. // [lpExtensionApis] - Table of extension functions
  164. //
  165. // Returns: -
  166. //
  167. // History: 26-Jun-95 BruceMa Created
  168. //
  169. //--------------------------------------------------------------------------
  170. void displayScmRot(HANDLE hProcess,
  171. PNTSD_EXTENSION_APIS lpExtensionApis)
  172. {
  173. ULONG addr;
  174. UINT cEnt;
  175. char szClsid[CLSIDSTR_MAX];
  176. SPerMachineROT sPerMachineRot;
  177. SRotAcctEntry sRotAcctEntry;
  178. SScmRot sScmRot;
  179. SScmRotEntry **ppScmHashTbl;
  180. SScmRotEntry *pScmRotEntry;
  181. SScmRotEntry sScmRotEntry;
  182. WCHAR wszSID[64];
  183. char szSID[64];
  184. MNKEQBUF *pMnkEqBfr;
  185. IFData sIFData;
  186. SYSTEMTIME sSystemTime;
  187. // Get the address of the per machine ROT global
  188. addr = GetExpression("scm!pPerMachineRot");
  189. // Read the CPerMachineRot
  190. ReadMem(&addr, addr, sizeof(ULONG));
  191. ReadMem(&sPerMachineRot, addr, sizeof(SPerMachineROT));
  192. // Read the first CRotAcctEntry
  193. ReadMem(&sRotAcctEntry, sPerMachineRot._safvRotAcctTable.m_pData,
  194. sizeof(SRotAcctEntry));
  195. // Read the CScmRot table
  196. ReadMem(&sScmRot, sRotAcctEntry.pscmrot, sizeof(SScmRot));
  197. // Read the hash table of CScmRotEntry *'s
  198. ppScmHashTbl = (SScmRotEntry **) OleAlloc(sScmRot._sht._ndwHashTableSize *
  199. sizeof(SScmRotEntry *));
  200. ReadMem(ppScmHashTbl, sScmRot._sht._apsheHashTable,
  201. sScmRot._sht._ndwHashTableSize * sizeof(SScmRotEntry *));
  202. // A header
  203. ReadMem(wszSID, sRotAcctEntry.unicodestringSID, 64);
  204. Unicode2Ansi(szSID, wszSID, 64);
  205. szSID[32] = '\0';
  206. Printf("\nSCM side ROT for SID %s\n\n", szSID);
  207. // Do over entries in the hash table
  208. for (cEnt = 0, pScmRotEntry = ppScmHashTbl[0];
  209. cEnt < sScmRot._sht._ndwHashTableSize;
  210. cEnt++, pScmRotEntry = ppScmHashTbl[cEnt])
  211. {
  212. // Only look at non-empty entries
  213. while (pScmRotEntry)
  214. {
  215. // Read the CScmRotEntry
  216. ReadMem(&sScmRotEntry, pScmRotEntry, sizeof(SScmRotEntry));
  217. // Read the moniker comparison buffer
  218. ULONG ulSize;
  219. ReadMem(&ulSize, sScmRotEntry._pmkeqbufKey, sizeof(ULONG));
  220. pMnkEqBfr = (MNKEQBUF *) OleAlloc(sizeof(ULONG) + ulSize);
  221. ReadMem(pMnkEqBfr, sScmRotEntry._pmkeqbufKey,
  222. sizeof(ULONG) + ulSize);
  223. // Read the interface data buffer
  224. ReadMem(&sIFData, sScmRotEntry._pifdObject,
  225. sizeof(IFData));
  226. // The registration Id
  227. Printf("RegID: %x\n", sScmRotEntry._dwScmRotId);
  228. // The moniker display name
  229. Unicode2Ansi(szSID, pMnkEqBfr->_wszName, 64);
  230. Printf("Display Name: %s\n", szSID);
  231. // The last time changed
  232. FileTimeToSystemTime(&sScmRotEntry._filetimeLastChange,
  233. &sSystemTime);
  234. Printf("Last Change: %2d:%02d:%02d %2d/%2d/%2d\n",
  235. sSystemTime.wHour - 7,
  236. sSystemTime.wMinute,
  237. sSystemTime.wSecond,
  238. sSystemTime.wMonth,
  239. sSystemTime.wDay,
  240. sSystemTime.wYear - 1900);
  241. // The clsid of the moniker
  242. FormatCLSID(pMnkEqBfr->_clsid, szClsid);
  243. Printf("Moniker Type: %s\n", szClsid);
  244. // The server unique id (from CoGetCurrentProcess())
  245. Printf("Server ID: %d\n", sScmRotEntry._dwProcessID);
  246. // The RPC end point
  247. Unicode2Ansi(szSID, sIFData._wszEndPoint, 64);
  248. Printf("Endpoint: %s\n", szSID);
  249. // The object ID
  250. FormatCLSID(sIFData._oid, szClsid);
  251. Printf("Object OID: %s\n", szClsid);
  252. // The IID of the object
  253. FormatCLSID(sIFData._iid, szClsid);
  254. Printf("Object IID: %s\n\n", szClsid);
  255. // The hash table entry can be a list, i.e. a hash bucket, of
  256. // ROT entries having the same hash value
  257. pScmRotEntry = sScmRotEntry._sheNext;
  258. // Release the moniker compare buffer
  259. OleFree(pMnkEqBfr);
  260. }
  261. }
  262. OleFree(ppScmHashTbl);
  263. }