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.

1423 lines
42 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. afds.c
  5. Abstract:
  6. Implements tcpip commands
  7. Author:
  8. Vadim Eydelman, October 2001
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. VOID
  16. DumpTCBBrief (
  17. ULONG64 Address
  18. );
  19. VOID
  20. DumpSynTCBBrief (
  21. ULONG64 Address
  22. );
  23. VOID
  24. DumpTWTCBBrief (
  25. ULONG64 Address
  26. );
  27. ULONG
  28. TCBListCallback (
  29. PFIELD_INFO pField,
  30. PVOID UserContext
  31. );
  32. ULONG
  33. SynTCBListCallback (
  34. PFIELD_INFO pField,
  35. PVOID UserContext
  36. );
  37. ULONG
  38. TWTCBQueueCallback (
  39. PFIELD_INFO pField,
  40. PVOID UserContext
  41. );
  42. LONG64 TCBTable,SynTCBTable,TWQueue;
  43. ULONG TCBTableSize, TCBTablePartitions;
  44. USHORT TWTCBDelta;
  45. ULONG SynTCBListLinkOffset, TWTCBQueueLinkOffset;
  46. DECLARE_API (tcb)
  47. /*++
  48. Routine Description:
  49. Dump TCP/IP TCB.
  50. Arguments:
  51. None.
  52. Return Value:
  53. None.
  54. --*/
  55. {
  56. ULONG result,i;
  57. PCHAR argp;
  58. LONG64 address;
  59. CHAR expr[MAX_ADDRESS_EXPRESSION];
  60. gClient = pClient;
  61. if (!CheckKmGlobals (
  62. )) {
  63. return E_INVALIDARG;
  64. }
  65. argp = ProcessOptions ((PCHAR)args);
  66. if (argp==NULL)
  67. return E_INVALIDARG;
  68. Options |= AFDKD_BRIEF_DISPLAY;
  69. dprintf (AFDKD_BRIEF_TCB_DISPLAY_HEADER);
  70. if (argp[0]==0) {
  71. union {
  72. struct {
  73. LONG64 next;
  74. LONG64 prev;
  75. } *q64;
  76. struct {
  77. LONG32 next;
  78. LONG32 prev;
  79. } *q32;
  80. LONG64 *p64;
  81. LONG32 *p32;
  82. } table;
  83. ULONG64 count;
  84. ULONG size;
  85. result = GetFieldValue (0, "TCPIP!MaxHashTableSize", NULL, count);
  86. if (result!=0) {
  87. if (TCBTableSize==0) {
  88. dprintf ("\ntcb: Could not read TCPIP!MaxHashTableSize, err: %ld\n", result);
  89. return E_INVALIDARG;
  90. }
  91. }
  92. else if (count==0) {
  93. dprintf ("\ntcb: TCPIP!MaxHashTableSize is 0!!!\n");
  94. return E_INVALIDARG;
  95. }
  96. else {
  97. TCBTableSize = (ULONG)count;
  98. }
  99. if (Options & AFDKD_SYNTCB_DISPLAY) {
  100. result = GetFieldValue (0, "TCPIP!SYNTCBTable", NULL, address);
  101. if (result!=0) {
  102. if (SynTCBTable==0) {
  103. dprintf ("\ntcb: Could not read TCPIP!SYNTCBTable, err: %ld\n", result);
  104. return E_INVALIDARG;
  105. }
  106. }
  107. else if (address==0) {
  108. dprintf ("\ntcb: TCPIP!SYNTCBTable is NULL!!!\n");
  109. return E_INVALIDARG;
  110. }
  111. else
  112. SynTCBTable = address;
  113. size = (IsPtr64 ()
  114. ? sizeof(table.q64[0])
  115. : sizeof (table.q32[0]))*TCBTableSize;
  116. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  117. if (table.p64==NULL) {
  118. dprintf ("\ntcb: Failed to allocate SYNTCBTable, size: %ld\n", size);
  119. return E_INVALIDARG;
  120. }
  121. if (!ReadMemory (SynTCBTable, table.p64, size, &result)) {
  122. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  123. dprintf ("\ntcb: Failed to read TCPIP!SYNTCBTable\n");
  124. return E_INVALIDARG;
  125. }
  126. result = GetFieldOffset ("TCPIP!SYNTCB", "syntcb_link", &SynTCBListLinkOffset);
  127. if (result!=0) {
  128. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  129. dprintf ("\ntcb: Failed to get syntcb_link offset in TCPIP!SYNTCB, err: %ld\n", result);
  130. return E_INVALIDARG;
  131. }
  132. for (i=0; i<TCBTableSize; i++) {
  133. LONG64 address2 = SynTCBTable+i*(IsPtr64()
  134. ? sizeof(table.q64[i])
  135. : sizeof(table.q32[i]));
  136. if( CheckControlC() ) {
  137. break;
  138. }
  139. address = IsPtr64() ? table.q64[i].next : table.q32[i].next;
  140. if (address!=address2) {
  141. ListType (
  142. "TCPIP!Queue", // Type
  143. address, // Address
  144. 0, // ListByFieldAddress
  145. "q_next", // NextPointer
  146. &address2, // Context
  147. SynTCBListCallback);
  148. }
  149. }
  150. }
  151. else if (Options & AFDKD_TWTCB_DISPLAY) {
  152. result = GetFieldValue (0, "TCPIP!NumTcbTablePartitions", NULL, count);
  153. if (result!=0) {
  154. if (TCBTablePartitions==0) {
  155. dprintf ("\ntcb: Could not read TCPIP!NumTcbTablePartitions, err: %ld\n", result);
  156. return E_INVALIDARG;
  157. }
  158. }
  159. else if (count==0) {
  160. dprintf ("\ntcb: TCPIP!NumTcbTablePartitions is 0!!!\n");
  161. return E_INVALIDARG;
  162. }
  163. else {
  164. TCBTablePartitions = (ULONG)count;
  165. }
  166. result = GetFieldValue (0, "TCPIP!TWQueue", NULL, address);
  167. if (result!=0) {
  168. if (TWQueue==0) {
  169. dprintf ("\ntcb: Could not read TCPIP!TWQueue, err: %ld\n", result);
  170. return E_INVALIDARG;
  171. }
  172. }
  173. else if (address==0) {
  174. dprintf ("\ntcb: TCPIP!TWQueue is NULL!!!\n");
  175. return E_INVALIDARG;
  176. }
  177. else
  178. TWQueue = address;
  179. size = (IsPtr64 ()
  180. ? sizeof(table.q64[0])
  181. : sizeof(table.q32[0])) * TCBTablePartitions;
  182. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  183. if (table.p64==NULL) {
  184. dprintf ("\ntcb: Failed to allocate TWQueue, size: %ld\n", size);
  185. return E_INVALIDARG;
  186. }
  187. if (!ReadMemory (TWQueue, table.p64, size, &result)) {
  188. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  189. dprintf ("\ntcb: Failed to read TCPIP!TWQueue\n");
  190. return E_INVALIDARG;
  191. }
  192. result = GetFieldOffset ("TCPIP!TWTCB", "twtcb_TWQueue", &TWTCBQueueLinkOffset);
  193. if (result!=0) {
  194. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  195. dprintf ("\ntcb: Failed to get twtcb_TWQueue offset in TCPIP!TWTCB, err: %ld\n", result);
  196. return E_INVALIDARG;
  197. }
  198. for (i=0; i<TCBTablePartitions; i++) {
  199. LONG64 address2 = TWQueue+i*(IsPtr64()
  200. ? sizeof(table.q64[i])
  201. : sizeof(table.q32[i]));
  202. if( CheckControlC() ) {
  203. break;
  204. }
  205. address = IsPtr64() ? table.q64[i].next : table.q32[i].next;
  206. if (address!=address2 ) {
  207. TWTCBDelta = 0;
  208. ListType (
  209. "TCPIP!Queue", // Type
  210. address, // Address
  211. 0, // ListByFieldAddress
  212. "q_next", // NextPointer
  213. &address2, // Context
  214. TWTCBQueueCallback);
  215. }
  216. }
  217. }
  218. else {
  219. result = GetFieldValue (0, "TCPIP!TCBTable", NULL, address);
  220. if (result!=0) {
  221. if (TCBTable==0) {
  222. dprintf ("\ntcb: Could not read TCPIP!TCBTable, err: %ld\n", result);
  223. return E_INVALIDARG;
  224. }
  225. }
  226. else if (address==0) {
  227. dprintf ("\ntcb: TCPIP!TCBTable is NULL!!!\n");
  228. return E_INVALIDARG;
  229. }
  230. else
  231. TCBTable = address;
  232. size = (IsPtr64 ()
  233. ? sizeof(table.p64[0])
  234. : sizeof(table.p32[0]))*TCBTableSize;
  235. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  236. if (table.p64==NULL) {
  237. dprintf ("\ntcb: Failed to allocate SYNTCBTable, size: %ld\n", size);
  238. return E_INVALIDARG;
  239. }
  240. if (!ReadMemory (TCBTable, table.p64, size, &result)) {
  241. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  242. dprintf ("\ntcb: Failed to read TCPIP!TCBTable\n");
  243. return E_INVALIDARG;
  244. }
  245. for (i=0; i<TCBTableSize; i++) {
  246. if( CheckControlC() ) {
  247. break;
  248. }
  249. address = IsPtr64() ? table.p64[i] : table.p32[i];
  250. if (address!=0) {
  251. ListType (
  252. "TCPIP!TCB", // Type
  253. address, // Address
  254. 0, // ListByFieldAddress
  255. "tcb_next", // NextPointer
  256. argp, // Context
  257. TCBListCallback);
  258. }
  259. }
  260. }
  261. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  262. }
  263. else {
  264. //
  265. // Snag the address from the command line.
  266. //
  267. while (sscanf( argp, "%s%n", expr, &i )==1) {
  268. if( CheckControlC() ) {
  269. break;
  270. }
  271. argp+=i;
  272. address = GetExpression (expr);
  273. result = (ULONG)InitTypeRead (address, TCPIP!TCB);
  274. if (result!=0) {
  275. dprintf ("\nendp: Could not read TCB @ %p, err: %d\n",
  276. address, result);
  277. break;
  278. }
  279. DumpTCBBrief (address);
  280. if (Options & AFDKD_FIELD_DISPLAY) {
  281. ProcessFieldOutput (address, "TCPIP!TCB");
  282. }
  283. }
  284. }
  285. dprintf (AFDKD_BRIEF_TCB_DISPLAY_TRAILER);
  286. return S_OK;
  287. }
  288. ULONG
  289. TCBListCallback (
  290. PFIELD_INFO pField,
  291. PVOID UserContext
  292. )
  293. {
  294. ULONG result;
  295. if (pField->address==0)
  296. return 1;
  297. if (!(Options & AFDKD_CONDITIONAL) ||
  298. CheckConditional (pField->address, "TCPIP!TCB")) {
  299. result = (ULONG)InitTypeRead (pField->address, TCPIP!TCB);
  300. if (result!=0) {
  301. dprintf ("\nTCBListCallback: Could not read TCPIP!TCB @ %p, err: %d\n",
  302. pField->address, result);
  303. }
  304. DumpTCBBrief (pField->address);
  305. if (Options & AFDKD_FIELD_DISPLAY) {
  306. ProcessFieldOutput (pField->address, "TCPIP!TCB");
  307. }
  308. }
  309. else {
  310. dprintf (".");
  311. }
  312. return 0;
  313. }
  314. ULONG
  315. SynTCBListCallback (
  316. PFIELD_INFO pField,
  317. PVOID UserContext
  318. )
  319. {
  320. ULONG result;
  321. ULONG64 address;
  322. if (pField->address==0)
  323. return 1;
  324. else if (pField->address==*(LONG64 *)UserContext)
  325. return 1;
  326. address = pField->address-SynTCBListLinkOffset;
  327. if (!(Options & AFDKD_CONDITIONAL) ||
  328. CheckConditional (address, "TCPIP!SYNTCB")) {
  329. result = (ULONG)InitTypeRead (address, TCPIP!SYNTCB);
  330. if (result!=0) {
  331. dprintf ("\nSynTCBListCallback: Could not read TCPIP!SYNTCB @ %p, err: %d\n",
  332. address, result);
  333. }
  334. DumpSynTCBBrief (address);
  335. if (Options & AFDKD_FIELD_DISPLAY) {
  336. ProcessFieldOutput (pField->address, "TCPIP!SYNTCB");
  337. }
  338. }
  339. else {
  340. dprintf (".");
  341. }
  342. return 0;
  343. }
  344. ULONG
  345. TWTCBQueueCallback (
  346. PFIELD_INFO pField,
  347. PVOID UserContext
  348. )
  349. {
  350. ULONG result;
  351. ULONG64 address;
  352. ULONG64 delta;
  353. if (pField->address==0)
  354. return 1;
  355. else if (pField->address==*(LONG64 *)UserContext)
  356. return 1;
  357. address = pField->address-TWTCBQueueLinkOffset;
  358. result = GetFieldValue (address, "TCPIP!TWTCB", "twtcb_rexmittimer", delta);
  359. if (result!=0) {
  360. dprintf ("\nTWTCBQueueCallback: Could not read twtcb_rexmittimer of TCPIP!TWTCB @ %p, err: %d\n",
  361. address, result);
  362. return 1;
  363. }
  364. TWTCBDelta += (USHORT)delta;
  365. if (!(Options & AFDKD_CONDITIONAL) ||
  366. CheckConditional (address, "TCPIP!TWTCB")) {
  367. result = (ULONG)InitTypeRead (address, TCPIP!TWTCB);
  368. if (result!=0) {
  369. dprintf ("\nTCBListCallback: Could not read TCPIP!TWTCB @ %p, err: %d\n",
  370. address, result);
  371. return 1;
  372. }
  373. DumpTWTCBBrief (address);
  374. if (Options & AFDKD_FIELD_DISPLAY) {
  375. ProcessFieldOutput (address, "TCPIP!TWTCB");
  376. }
  377. }
  378. else {
  379. dprintf (".");
  380. }
  381. return 0;
  382. }
  383. CHAR *TCBStateStrings [] = {
  384. "Cd",
  385. "Li",
  386. "SS",
  387. "SR",
  388. "Es",
  389. "F1",
  390. "F2",
  391. "CW",
  392. "Ci",
  393. "LA",
  394. "TW"
  395. };
  396. #define MAX_TCB_STATE (sizeof(TCBStateStrings)/sizeof (TCBStateStrings[0]))
  397. VOID
  398. DumpTCBBrief (
  399. ULONG64 Address
  400. )
  401. {
  402. TA_IP_ADDRESS address;
  403. CHAR src[MAX_ADDRESS_STRING], dst[MAX_ADDRESS_STRING];
  404. CHAR symbol[MAX_FIELD_CHARS];
  405. ULONG64 offset;
  406. UCHAR state;
  407. ULONG flags;
  408. ULONG64 conn,pid,ctx;
  409. state = (UCHAR)ReadField (tcb_state);
  410. flags = (ULONG)ReadField(tcb_flags);
  411. GetSymbol (ReadField (tcb_rcvind), symbol, &offset);
  412. address.TAAddressCount = 1;
  413. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
  414. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
  415. address.Address[0].Address[0].in_addr = (ULONG)ReadField (tcb_saddr);
  416. address.Address[0].Address[0].sin_port = (USHORT)ReadField (tcb_sport);
  417. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  418. src[sizeof(src)-1] = 0;
  419. address.Address[0].Address[0].in_addr = (ULONG)ReadField (tcb_daddr);
  420. address.Address[0].Address[0].sin_port = (USHORT)ReadField (tcb_dport);
  421. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (dst)-1);
  422. dst[sizeof(dst)-1] = 0;
  423. ctx = ReadField (tcb_conncontext);
  424. if (SavedMinorVersion>=2219) {
  425. if (GetFieldValue (Address, "TCPIP!TCB", "tcb_conn", conn)!=0 ||
  426. GetFieldValue (conn, "TCPIP!TCPConn", "tc_owningpid", pid)!=0) {
  427. pid = 0;
  428. }
  429. }
  430. else {
  431. pid = 0;
  432. }
  433. /* TCB State Flags Client ConnCtx PID Src Addr Dst Addr*/
  434. dprintf (
  435. IsPtr64 ()
  436. ? "\n%011.011p %-2.2s %8.8x %-6.8s %011.011p %4.4x %-19s %-s"
  437. : "\n%008.008p %-2.2s %8.8x %-6.8s %008.008p %4.4x %-19s %-s",
  438. DISP_PTR (Address),
  439. state<MAX_TCB_STATE ? TCBStateStrings[state] : "??",
  440. flags,
  441. strtok (symbol, "!"),
  442. DISP_PTR(ctx),
  443. (ULONG)pid,
  444. src,
  445. dst);
  446. }
  447. VOID
  448. DumpSynTCBBrief (
  449. ULONG64 Address
  450. )
  451. {
  452. TA_IP_ADDRESS address;
  453. CHAR src[MAX_ADDRESS_STRING], dst[MAX_ADDRESS_STRING];
  454. UCHAR state;
  455. ULONG flags;
  456. state = (UCHAR)ReadField (syntcb_state);
  457. flags = (ULONG)ReadField(syntcb_flags);
  458. address.TAAddressCount = 1;
  459. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
  460. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
  461. address.Address[0].Address[0].in_addr = (ULONG)ReadField (syntcb_saddr);
  462. address.Address[0].Address[0].sin_port = (USHORT)ReadField (syntcb_sport);
  463. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  464. src[sizeof(src)-1] = 0;
  465. address.Address[0].Address[0].in_addr = (ULONG)ReadField (syntcb_daddr);
  466. address.Address[0].Address[0].sin_port = (USHORT)ReadField (syntcb_dport);
  467. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (dst)-1);
  468. dst[sizeof(dst)-1] = 0;
  469. /* TCB State Flags Client ConnCtx PID Src Addr Dst Addr*/
  470. dprintf (
  471. IsPtr64 ()
  472. ? "\n%011.011p %-2.2s %8.8x %-19s %-s"
  473. : "\n%008.008p %-2.2s %8.8x %-19s %-s",
  474. DISP_PTR (Address),
  475. state<MAX_TCB_STATE ? TCBStateStrings[state] : "??",
  476. flags,
  477. src,
  478. dst);
  479. }
  480. VOID
  481. DumpTWTCBBrief (
  482. ULONG64 Address
  483. )
  484. {
  485. TA_IP_ADDRESS address;
  486. CHAR src[MAX_ADDRESS_STRING], dst[MAX_ADDRESS_STRING];
  487. address.TAAddressCount = 1;
  488. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
  489. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
  490. address.Address[0].Address[0].in_addr = (ULONG)ReadField (twtcb_saddr);
  491. address.Address[0].Address[0].sin_port = (USHORT)ReadField (twtcb_sport);
  492. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  493. src[sizeof(src)-1] = 0;
  494. address.Address[0].Address[0].in_addr = (ULONG)ReadField (twtcb_daddr);
  495. address.Address[0].Address[0].sin_port = (USHORT)ReadField (twtcb_dport);
  496. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (dst)-1);
  497. dst[sizeof(dst)-1] = 0;
  498. /* TCB St Flags Client ConnCtx PID Src Addr Dst Addr*/
  499. dprintf (
  500. IsPtr64 ()
  501. ? "\n%011.011p TW expires in %5d ticks %-19s %-s"
  502. : "\n%008.008p TW expires in %5d ticks %-19s %-s",
  503. DISP_PTR (Address),
  504. TWTCBDelta,
  505. src,
  506. dst);
  507. }
  508. VOID
  509. DumpTCB6Brief (
  510. ULONG64 Address
  511. );
  512. ULONG
  513. TCB6ListCallback (
  514. PFIELD_INFO pField,
  515. PVOID UserContext
  516. );
  517. ULONG64 TCB6Table;
  518. ULONG TCB6TableSize;
  519. DECLARE_API (tcb6)
  520. /*++
  521. Routine Description:
  522. Dump TCP/IP TCB.
  523. Arguments:
  524. None.
  525. Return Value:
  526. None.
  527. --*/
  528. {
  529. ULONG result,i;
  530. PCHAR argp;
  531. ULONG64 address;
  532. CHAR expr[MAX_ADDRESS_EXPRESSION];
  533. gClient = pClient;
  534. if (!CheckKmGlobals ()) {
  535. return E_INVALIDARG;
  536. }
  537. argp = ProcessOptions ((PCHAR)args);
  538. if (argp==NULL)
  539. return E_INVALIDARG;
  540. Options |= AFDKD_BRIEF_DISPLAY;
  541. dprintf (AFDKD_BRIEF_TCB6_DISPLAY_HEADER);
  542. if (argp[0]==0) {
  543. union {
  544. ULONG64 *p64;
  545. ULONG *p32;
  546. } table;
  547. ULONG64 count;
  548. ULONG size;
  549. result = GetFieldValue (0, "TCPIP6!TCBTable", NULL, address);
  550. if (result!=0) {
  551. if (TCB6Table==0) {
  552. dprintf ("\ntcb6: Could not read TCPIP6!TCBTable, err: %ld\n", result);
  553. return E_INVALIDARG;
  554. }
  555. }
  556. else if (address==0) {
  557. dprintf ("\ntcb6: TCPIP6!TCBTable is NULL!!!\n");
  558. return E_INVALIDARG;
  559. }
  560. else
  561. TCB6Table = address;
  562. result = GetFieldValue (0, "TCPIP6!TcbTableSize", NULL, count);
  563. if (result!=0) {
  564. if (TCB6TableSize==0) {
  565. dprintf ("\ntcb6: Could not read TCPIP6!TcbTableSize, err: %ld\n", result);
  566. return E_INVALIDARG;
  567. }
  568. }
  569. else if (count==0) {
  570. dprintf ("\ntcb6: TCPIP6!TcbTableSize is 0!!!\n");
  571. return E_INVALIDARG;
  572. }
  573. else {
  574. TCB6TableSize = (ULONG)count;
  575. }
  576. size = (IsPtr64 () ? sizeof (ULONG64) : sizeof (ULONG))*TCB6TableSize;
  577. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  578. if (table.p64==NULL) {
  579. dprintf ("\ntcb: Failed to allocate TCBTable, size: %ld\n", size);
  580. return E_INVALIDARG;
  581. }
  582. if (!ReadMemory (TCB6Table, table.p64, size, &result)) {
  583. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  584. dprintf ("\ntcb: Failed to read TCBTable\n");
  585. return E_INVALIDARG;
  586. }
  587. for (i=0; i<TCB6TableSize; i++) {
  588. if( CheckControlC() ) {
  589. break;
  590. }
  591. address = IsPtr64() ? table.p64[i] : table.p32[i];
  592. if (address!=0) {
  593. ListType (
  594. "TCPIP6!TCB", // Type
  595. address, // Address
  596. 0, // ListByFieldAddress
  597. "tcb_next", // NextPointer
  598. argp, // Context
  599. TCB6ListCallback);
  600. }
  601. }
  602. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  603. }
  604. else {
  605. //
  606. // Snag the address from the command line.
  607. //
  608. while (sscanf( argp, "%s%n", expr, &i )==1) {
  609. if( CheckControlC() ) {
  610. break;
  611. }
  612. argp+=i;
  613. address = GetExpression (expr);
  614. result = (ULONG)InitTypeRead (address, TCPIP6!TCB);
  615. if (result!=0) {
  616. dprintf ("\nendp: Could not read TCB @ %p, err: %d\n",
  617. address, result);
  618. break;
  619. }
  620. DumpTCBBrief (address);
  621. if (Options & AFDKD_FIELD_DISPLAY) {
  622. ProcessFieldOutput (address, "TCPIP6!TCB");
  623. }
  624. }
  625. }
  626. dprintf (AFDKD_BRIEF_TCB6_DISPLAY_TRAILER);
  627. return S_OK;
  628. }
  629. ULONG
  630. TCB6ListCallback (
  631. PFIELD_INFO pField,
  632. PVOID UserContext
  633. )
  634. {
  635. ULONG result;
  636. if (pField->address==0)
  637. return 0;
  638. if (!(Options & AFDKD_CONDITIONAL) ||
  639. CheckConditional (pField->address, "TCPIP6!TCB")) {
  640. result = (ULONG)InitTypeRead (pField->address, TCPIP6!TCB);
  641. if (result!=0) {
  642. dprintf ("\nTCBListCallback: Could not read TCB @ %p, err: %d\n",
  643. pField->address, result);
  644. }
  645. DumpTCB6Brief (pField->address);
  646. if (Options & AFDKD_FIELD_DISPLAY) {
  647. ProcessFieldOutput (pField->address, "TCPIP6!TCB");
  648. }
  649. }
  650. else {
  651. dprintf (".");
  652. }
  653. return 0;
  654. }
  655. VOID
  656. DumpTCB6Brief (
  657. ULONG64 Address
  658. )
  659. {
  660. TA_IP6_ADDRESS address;
  661. CHAR src[MAX_ADDRESS_STRING], dst[MAX_ADDRESS_STRING];
  662. CHAR symbol[MAX_FIELD_CHARS];
  663. ULONG64 offset;
  664. UCHAR state;
  665. ULONG flags;
  666. ULONG64 conn,pid,ctx;
  667. state = (UCHAR)ReadField (tcb_state);
  668. flags = (ULONG)ReadField (tcb_flags);
  669. GetSymbol (ReadField (tcb_rcvind), symbol, &offset);
  670. address.TAAddressCount = 1;
  671. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP6;
  672. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP6;
  673. GetFieldValue (Address, "TCPIP6!TCB", "tcb_saddr", address.Address[0].Address[0].sin6_addr);
  674. address.Address[0].Address[0].sin6_port = (USHORT)ReadField (tcb_sport);
  675. address.Address[0].Address[0].sin6_scope_id = (ULONG)ReadField(tcb_sscope_id);
  676. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  677. src[sizeof(src)-1] = 0;
  678. GetFieldValue (Address, "TCPIP6!TCB", "tcb_daddr", address.Address[0].Address[0].sin6_addr);
  679. address.Address[0].Address[0].sin6_port = (USHORT)ReadField (tcb_dport);
  680. address.Address[0].Address[0].sin6_scope_id = (ULONG)ReadField(tcb_dscope_id);
  681. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (dst)-1);
  682. dst[sizeof(dst)-1] = 0;
  683. ctx = ReadField (tcb_conncontext);
  684. if (SavedMinorVersion>=2471) {
  685. if (GetFieldValue (Address, "TCPIP6!TCB", "tcb_conn", conn)!=0 ||
  686. GetFieldValue (conn, "TCPIP6!TCPConn", "tc_owningpid", pid)!=0) {
  687. pid = 0;
  688. }
  689. }
  690. else {
  691. pid = 0;
  692. }
  693. /* TCB State Flags Client ConnCtx PID Src Dst*/
  694. dprintf (
  695. IsPtr64 ()
  696. ? "\n%011.011p %-2.2s %8.8x %-6.8s %011.011p %4.4x %-s\n"
  697. " %-s"
  698. : "\n%008.008p %-2.2s %8.8x %-6.8s %008.008p %4.4x %-s\n"
  699. " %-s",
  700. DISP_PTR (Address),
  701. state<MAX_TCB_STATE ? TCBStateStrings[state] : "??",
  702. flags,
  703. strtok (symbol, "!"),
  704. DISP_PTR(ctx),
  705. (ULONG)pid,
  706. src,
  707. dst);
  708. }
  709. VOID
  710. DumpTAOBrief (
  711. ULONG64 Address
  712. );
  713. ULONG
  714. TAOListCallback (
  715. PFIELD_INFO pField,
  716. PVOID UserContext
  717. );
  718. ULONG64 AOTable;
  719. ULONG AOTableSize;
  720. DECLARE_API (tao)
  721. /*++
  722. Routine Description:
  723. Dump TCP/IP Address Objects.
  724. Arguments:
  725. None.
  726. Return Value:
  727. None.
  728. --*/
  729. {
  730. ULONG result,i;
  731. PCHAR argp;
  732. ULONG64 address;
  733. CHAR expr[MAX_ADDRESS_EXPRESSION];
  734. gClient = pClient;
  735. if (!CheckKmGlobals ()) {
  736. return E_INVALIDARG;
  737. }
  738. argp = ProcessOptions ((PCHAR)args);
  739. if (argp==NULL)
  740. return E_INVALIDARG;
  741. Options |= AFDKD_BRIEF_DISPLAY;
  742. dprintf (AFDKD_BRIEF_TAO_DISPLAY_HEADER);
  743. if (argp[0]==0) {
  744. union {
  745. ULONG64 *p64;
  746. ULONG *p32;
  747. } table;
  748. ULONG64 count;
  749. ULONG size;
  750. result = GetFieldValue (0, "TCPIP!AddrObjTable", NULL, address);
  751. if (result!=0) {
  752. if (AOTable==0) {
  753. dprintf ("\ntao: Could not read TCPIP!AddrObjTable, err: %ld\n", result);
  754. return E_INVALIDARG;
  755. }
  756. }
  757. else if (address==0) {
  758. dprintf ("\ntao: TCPIP!AddrObjTable is NULL!!!\n");
  759. return E_INVALIDARG;
  760. }
  761. else
  762. AOTable = address;
  763. result = GetFieldValue (0, "TCPIP!AddrObjTableSize", NULL, count);
  764. if (result!=0) {
  765. if (AOTableSize==0) {
  766. dprintf ("\ntao: Could not read TCPIP!AddrObjTableSize, err: %ld\n", result);
  767. return E_INVALIDARG;
  768. }
  769. }
  770. else if (count==0) {
  771. dprintf ("\ntao: TCPIP!AddrObjTableSize is 0!!!\n");
  772. return E_INVALIDARG;
  773. }
  774. else {
  775. AOTableSize = (ULONG)count;
  776. }
  777. size = (IsPtr64 () ? sizeof (ULONG64) : sizeof (ULONG))*AOTableSize;
  778. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  779. if (table.p64==NULL) {
  780. dprintf ("\ntcb: Failed to allocate AOTable, size: %ld\n", size);
  781. return E_INVALIDARG;
  782. }
  783. if (!ReadMemory (AOTable, table.p64, size, &result)) {
  784. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  785. dprintf ("\ntcb: Failed to read AOTable\n");
  786. return E_INVALIDARG;
  787. }
  788. for (i=0; i<AOTableSize; i++) {
  789. if( CheckControlC() ) {
  790. break;
  791. }
  792. address = IsPtr64() ? table.p64[i] : table.p32[i];
  793. if (address!=0) {
  794. ListType (
  795. "TCPIP!AddrObj", // Type
  796. address, // Address
  797. 0, // ListByFieldAddress
  798. "ao_next", // NextPointer
  799. argp, // Context
  800. TAOListCallback);
  801. }
  802. }
  803. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  804. }
  805. else {
  806. //
  807. // Snag the address from the command line.
  808. //
  809. while (sscanf( argp, "%s%n", expr, &i )==1) {
  810. if( CheckControlC() ) {
  811. break;
  812. }
  813. argp+=i;
  814. address = GetExpression (expr);
  815. result = (ULONG)InitTypeRead (address, TCPIP!AddrObj);
  816. if (result!=0) {
  817. dprintf ("\ntao: Could not read AddrObj @ %p, err: %d\n",
  818. address, result);
  819. break;
  820. }
  821. DumpTAOBrief (address);
  822. if (Options & AFDKD_FIELD_DISPLAY) {
  823. ProcessFieldOutput (address, "TCPIP!AddrObj");
  824. }
  825. }
  826. }
  827. dprintf (AFDKD_BRIEF_TAO_DISPLAY_TRAILER);
  828. return S_OK;
  829. }
  830. ULONG
  831. TAOListCallback (
  832. PFIELD_INFO pField,
  833. PVOID UserContext
  834. )
  835. {
  836. ULONG result;
  837. if (pField->address==0)
  838. return 0;
  839. if (!(Options & AFDKD_CONDITIONAL) ||
  840. CheckConditional (pField->address, "TCPIP!AddrObj")) {
  841. result = (ULONG)InitTypeRead (pField->address, TCPIP!AddrObj);
  842. if (result!=0) {
  843. dprintf ("\nAOListCallback: Could not read AddrObj @ %p, err: %d\n",
  844. pField->address, result);
  845. }
  846. DumpTAOBrief (pField->address);
  847. if (Options & AFDKD_FIELD_DISPLAY) {
  848. ProcessFieldOutput (pField->address, "TCPIP!AddrObj");
  849. }
  850. }
  851. else {
  852. dprintf (".");
  853. }
  854. return 0;
  855. }
  856. VOID
  857. DumpTAOBrief (
  858. ULONG64 Address
  859. )
  860. {
  861. TA_IP_ADDRESS address;
  862. CHAR src[MAX_ADDRESS_STRING], dst[MAX_ADDRESS_STRING];
  863. CHAR symbol[MAX_FIELD_CHARS];
  864. ULONG64 offset;
  865. ULONG64 pid, ctx = 0;
  866. ULONG result;
  867. USHORT prot;
  868. ULONG flags, ifidx;
  869. address.TAAddressCount = 1;
  870. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
  871. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
  872. address.Address[0].Address[0].in_addr = (ULONG)ReadField (ao_addr);
  873. address.Address[0].Address[0].sin_port = (USHORT)ReadField (ao_port);
  874. ifidx = (ULONG)ReadField (ao_bindindex);
  875. if (ifidx==0 || (address.Address[0].Address[0].in_addr!=0)) {
  876. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  877. }
  878. else {
  879. _snprintf (src, sizeof (src)-1, "%%%d:%d", ifidx, NTOHS (address.Address[0].Address[0].sin_port));
  880. }
  881. src[sizeof(src)-1] = 0;
  882. prot = (USHORT)ReadField (ao_prot);
  883. flags = (ULONG)ReadField (ao_flags);
  884. if ((offset=ReadField (ao_connect))!=0) {
  885. ctx = ReadField (ao_conncontext);
  886. }
  887. else if ((offset=ReadField (ao_rcvdg))!=0) {
  888. ctx = ReadField (ao_rcvdgcontext);
  889. }
  890. else if ((offset=ReadField (ao_disconnect))!=0) {
  891. ctx = ReadField (ao_disconncontext);
  892. }
  893. else if ((offset=ReadField (ao_error))!=0) {
  894. ctx = ReadField (ao_errcontext);
  895. }
  896. else if ((offset=ReadField (ao_rcv))!=0) {
  897. ctx = ReadField (ao_rcvcontext);
  898. }
  899. else if ((offset=ReadField (ao_errorex))!=0) {
  900. ctx = ReadField (ao_errorexcontext);
  901. }
  902. else if ((offset=ReadField (ao_chainedrcv))!=0) {
  903. ctx = ReadField (ao_chainedrcvcontext);
  904. }
  905. else if ((offset=ReadField (ao_exprcv))!=0) {
  906. ctx = ReadField (ao_exprcvcontext);
  907. }
  908. if (offset!=0) {
  909. GetSymbol (offset, symbol, &offset);
  910. }
  911. else {
  912. strncpy (symbol, "???", sizeof (symbol)-1);
  913. symbol[sizeof(symbol)-1] = 0;
  914. }
  915. if (SavedMinorVersion>=2219) {
  916. pid = ReadField (ao_owningpid);
  917. }
  918. else {
  919. pid = 0;
  920. }
  921. offset = ReadField (ao_RemoteAddress);
  922. if (offset!=0) {
  923. if (ReadMemory (offset, &address, sizeof (address), &result)) {
  924. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, offset), sizeof (dst)-1);
  925. }
  926. else {
  927. _snprintf (dst, sizeof (dst)-1, "Read err @ %I64X", offset);
  928. }
  929. dst[sizeof(dst)-1] = 0;
  930. }
  931. else {
  932. INT n;
  933. ULONG fldoff;
  934. n = _snprintf (dst, sizeof (dst)-1, "%3.3x", (ULONG)ReadField (ao_listencnt));
  935. result = GetFieldOffset ("TCPIP!AddrObj", "ao_activeq", &fldoff);
  936. if (result==0) {
  937. if (Options & AFDKD_LIST_COUNT) {
  938. n+= _snprintf (&dst[n], sizeof (dst)-1-n, " %3.3x",
  939. CountListEntries (Address+fldoff));
  940. }
  941. else {
  942. n+= _snprintf (&dst[n], sizeof (dst)-1-n, " %3.3s",
  943. ListCountEstimate (Address+fldoff));
  944. }
  945. }
  946. result = GetFieldOffset ("TCPIP!AddrObj", "ao_idleq", &fldoff);
  947. if (result==0) {
  948. if (Options & AFDKD_LIST_COUNT) {
  949. n+= _snprintf (&dst[n], sizeof (dst)-1-n, " %3.3x",
  950. CountListEntries (Address+fldoff));
  951. }
  952. else {
  953. n+= _snprintf (&dst[n], sizeof (dst)-1-n, " %3.3s",
  954. ListCountEstimate (Address+fldoff));
  955. }
  956. }
  957. dst[sizeof(dst)-1] = 0;
  958. }
  959. /* TCB Prot Flags Client ConnCtx PID Address Remote Address*/
  960. dprintf (
  961. IsPtr64 ()
  962. ? "\n%011.011p %4d %5.5x %-6.8s %011.011p %4.4x %-19s %-s"
  963. : "\n%008.008p %4d %5.5x %-6.8s %008.008p %4.4x %-19s %-s",
  964. DISP_PTR (Address),
  965. prot,
  966. flags,
  967. strtok (symbol, "!"),
  968. DISP_PTR(ctx),
  969. (ULONG)pid,
  970. src,
  971. dst);
  972. }
  973. VOID
  974. DumpTAO6Brief (
  975. ULONG64 Address
  976. );
  977. ULONG
  978. TAO6ListCallback (
  979. PFIELD_INFO pField,
  980. PVOID UserContext
  981. );
  982. ULONG64 AO6Table;
  983. ULONG AO6TableSize;
  984. DECLARE_API (tao6)
  985. /*++
  986. Routine Description:
  987. Dump TCP/IPv6 Address Objects.
  988. Arguments:
  989. None.
  990. Return Value:
  991. None.
  992. --*/
  993. {
  994. ULONG result,i;
  995. PCHAR argp;
  996. ULONG64 address;
  997. CHAR expr[MAX_ADDRESS_EXPRESSION];
  998. gClient = pClient;
  999. if (!CheckKmGlobals ()) {
  1000. return E_INVALIDARG;
  1001. }
  1002. argp = ProcessOptions ((PCHAR)args);
  1003. if (argp==NULL)
  1004. return E_INVALIDARG;
  1005. Options |= AFDKD_BRIEF_DISPLAY;
  1006. dprintf (AFDKD_BRIEF_TAO6_DISPLAY_HEADER);
  1007. if (argp[0]==0) {
  1008. union {
  1009. ULONG64 *p64;
  1010. ULONG *p32;
  1011. } table;
  1012. ULONG64 count;
  1013. ULONG size;
  1014. result = GetFieldValue (0, "TCPIP6!AddrObjTable", NULL, address);
  1015. if (result!=0) {
  1016. if (AO6Table==0) {
  1017. dprintf ("\ntao6: Could not read TCPIP6!AddrObjTable, err: %ld\n", result);
  1018. return E_INVALIDARG;
  1019. }
  1020. }
  1021. else if (address==0) {
  1022. dprintf ("\ntao6: TCPIP6!AddrObjTable is NULL!!!\n");
  1023. return E_INVALIDARG;
  1024. }
  1025. else
  1026. AO6Table = address;
  1027. result = GetFieldValue (0, "TCPIP6!AddrObjTableSize", NULL, count);
  1028. if (result!=0) {
  1029. if (AO6TableSize==0) {
  1030. dprintf ("\ntao6: Could not read TCPIP6!AddrObjTableSize, err: %ld\n", result);
  1031. return E_INVALIDARG;
  1032. }
  1033. }
  1034. else if (count==0) {
  1035. dprintf ("\ntao6: TCPIP6!AddrObjTableSize is 0!!!\n");
  1036. return E_INVALIDARG;
  1037. }
  1038. else {
  1039. AO6TableSize = (ULONG)count;
  1040. }
  1041. size = (IsPtr64 () ? sizeof (ULONG64) : sizeof (ULONG))*AO6TableSize;
  1042. table.p64 = RtlAllocateHeap (RtlProcessHeap (), 0, size);
  1043. if (table.p64==NULL) {
  1044. dprintf ("\ntcb: Failed to allocate AOTable, size: %ld\n", size);
  1045. return E_INVALIDARG;
  1046. }
  1047. if (!ReadMemory (AO6Table, table.p64, size, &result)) {
  1048. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  1049. dprintf ("\ntao6: Failed to read AOTable\n");
  1050. return E_INVALIDARG;
  1051. }
  1052. for (i=0; i<AO6TableSize; i++) {
  1053. if( CheckControlC() ) {
  1054. break;
  1055. }
  1056. address = IsPtr64() ? table.p64[i] : table.p32[i];
  1057. if (address!=0) {
  1058. ListType (
  1059. "TCPIP6!AddrObj", // Type
  1060. address, // Address
  1061. 0, // ListByFieldAddress
  1062. "ao_next", // NextPointer
  1063. argp, // Context
  1064. TAO6ListCallback);
  1065. }
  1066. }
  1067. RtlFreeHeap (RtlProcessHeap (), 0, table.p64);
  1068. }
  1069. else {
  1070. //
  1071. // Snag the address from the command line.
  1072. //
  1073. while (sscanf( argp, "%s%n", expr, &i )==1) {
  1074. if( CheckControlC() ) {
  1075. break;
  1076. }
  1077. argp+=i;
  1078. address = GetExpression (expr);
  1079. result = (ULONG)InitTypeRead (address, TCPIP6!AddrObj);
  1080. if (result!=0) {
  1081. dprintf ("\ntao6: Could not read AddrObj @ %p, err: %d\n",
  1082. address, result);
  1083. break;
  1084. }
  1085. DumpTAO6Brief (address);
  1086. if (Options & AFDKD_FIELD_DISPLAY) {
  1087. ProcessFieldOutput (address, "TCPIP6!AddrObj");
  1088. }
  1089. }
  1090. }
  1091. dprintf (AFDKD_BRIEF_TAO6_DISPLAY_TRAILER);
  1092. return S_OK;
  1093. }
  1094. ULONG
  1095. TAO6ListCallback (
  1096. PFIELD_INFO pField,
  1097. PVOID UserContext
  1098. )
  1099. {
  1100. ULONG result;
  1101. if (pField->address==0)
  1102. return 0;
  1103. if (!(Options & AFDKD_CONDITIONAL) ||
  1104. CheckConditional (pField->address, "TCPIP6!AddrObj")) {
  1105. result = (ULONG)InitTypeRead (pField->address, TCPIP6!AddrObj);
  1106. if (result!=0) {
  1107. dprintf ("\nTAO6ListCallback: Could not read AddrObj @ %p, err: %d\n",
  1108. pField->address, result);
  1109. }
  1110. DumpTAO6Brief (pField->address);
  1111. if (Options & AFDKD_FIELD_DISPLAY) {
  1112. ProcessFieldOutput (pField->address, "TCPIP6!AddrObj");
  1113. }
  1114. }
  1115. else {
  1116. dprintf (".");
  1117. }
  1118. return 0;
  1119. }
  1120. VOID
  1121. DumpTAO6Brief (
  1122. ULONG64 Address
  1123. )
  1124. {
  1125. TA_IP6_ADDRESS address;
  1126. CHAR src[MAX_ADDRESS_STRING];
  1127. CHAR symbol[MAX_FIELD_CHARS];
  1128. ULONG64 offset;
  1129. ULONG64 pid, ctx = 0;
  1130. USHORT prot;
  1131. ULONG flags;
  1132. address.TAAddressCount = 1;
  1133. address.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP6;
  1134. address.Address[0].AddressType = TDI_ADDRESS_TYPE_IP6;
  1135. GetFieldValue (Address, "TCPIP6!AddrObj", "ao_addr", address.Address[0].Address[0].sin6_addr);
  1136. address.Address[0].Address[0].sin6_port = (USHORT)ReadField (ao_port);
  1137. address.Address[0].Address[0].sin6_scope_id = (ULONG)ReadField (ao_scope_id);
  1138. strncpy (src, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, 0), sizeof (src)-1);
  1139. src[sizeof(src)-1] = 0;
  1140. prot = (USHORT)ReadField (ao_prot);
  1141. flags = (ULONG)ReadField (ao_flags);
  1142. if ((offset=ReadField (ao_connect))!=0) {
  1143. ctx = ReadField (ao_conncontext);
  1144. }
  1145. else if ((offset=ReadField (ao_rcvdg))!=0) {
  1146. ctx = ReadField (ao_rcvdgcontext);
  1147. }
  1148. else if ((offset=ReadField (ao_disconnect))!=0) {
  1149. ctx = ReadField (ao_disconncontext);
  1150. }
  1151. else if ((offset=ReadField (ao_error))!=0) {
  1152. ctx = ReadField (ao_errcontext);
  1153. }
  1154. else if ((offset=ReadField (ao_rcv))!=0) {
  1155. ctx = ReadField (ao_rcvcontext);
  1156. }
  1157. else if ((offset=ReadField (ao_errorex))!=0) {
  1158. ctx = ReadField (ao_errorexcontext);
  1159. }
  1160. #if 0
  1161. else if ((offset=ReadField (ao_chainedrcv))!=0) {
  1162. ctx = ReadField (ao_chainedrcvcontext);
  1163. }
  1164. #endif
  1165. else if ((offset=ReadField (ao_exprcv))!=0) {
  1166. ctx = ReadField (ao_exprcvcontext);
  1167. }
  1168. if (offset!=0) {
  1169. GetSymbol (offset, symbol, &offset);
  1170. }
  1171. else {
  1172. strncpy (symbol, "???", sizeof (symbol)-1);
  1173. symbol[sizeof (symbol)-1] = 0;
  1174. }
  1175. if (SavedMinorVersion>=2471) {
  1176. pid = ReadField (ao_owningpid);
  1177. }
  1178. else {
  1179. pid = 0;
  1180. }
  1181. #if 0
  1182. offset = ReadField (ao_RemoteAddress);
  1183. if (offset!=0) {
  1184. if (ReadMemory (offset, &address, sizeof (address), &result)) {
  1185. strncpy (dst, TransportAddressToString ((PTRANSPORT_ADDRESS)&address, offset), sizeof (dst)-1);
  1186. }
  1187. else {
  1188. _snprintf (dst, sizeof (dst), "Read err @ %I64X", offset);
  1189. }
  1190. dst[sizeof(dst)-1] = 0;
  1191. }
  1192. else {
  1193. dst[0] = 0;
  1194. }
  1195. #endif
  1196. /* TCB Prot Flags Client ConnCtx PID Addr*/
  1197. dprintf (
  1198. IsPtr64 ()
  1199. ? "\n%011.011p %4d %4.4x %-6.8s %011.011p %4.4x %-s"
  1200. : "\n%008.008p %4d %4.4x %-6.8s %008.008p %4.4x %-s",
  1201. DISP_PTR (Address),
  1202. prot,
  1203. flags,
  1204. strtok (symbol, "!"),
  1205. DISP_PTR(ctx),
  1206. (ULONG)pid,
  1207. src);
  1208. }
  1209. ULONG
  1210. GetRemoteAddressFromTcp (
  1211. ULONG64 FoAddress,
  1212. PVOID AddressBuffer,
  1213. SIZE_T AddressBufferLength
  1214. )
  1215. {
  1216. ULONG result;
  1217. ULONG64 fsContext=0, tcpConn=0, tcb=0, u64=0;
  1218. PTA_IP_ADDRESS ipAddress = AddressBuffer;
  1219. if ((result=GetFieldValue (FoAddress, "NT!_FILE_OBJECT", "FsContext", fsContext))==0 &&
  1220. (result=GetFieldValue (fsContext, "TCPIP!_TCP_CONTEXT", "Conn", tcpConn))==0 &&
  1221. (result=GetFieldValue (tcpConn, "TCPIP!TCPConn", "tc_tcb", tcb))==0 &&
  1222. (result=GetFieldValue (tcb, "TCPIP!TCB", "tcb_daddr", u64))==0 ) {
  1223. ipAddress->TAAddressCount = 1;
  1224. ipAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
  1225. ipAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
  1226. ipAddress->Address[0].Address[0].in_addr = (ULONG)u64;
  1227. GetFieldValue (tcb, "TCPIP!TCB", "tcb_dport", u64);
  1228. ipAddress->Address[0].Address[0].sin_port = (USHORT)u64;
  1229. ZeroMemory (&ipAddress->Address[0].Address[0].sin_zero,
  1230. sizeof (ipAddress->Address[0].Address[0].sin_zero));
  1231. }
  1232. return result;
  1233. }