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.

1192 lines
34 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. umode.c
  5. Abstract:
  6. Functions for USER MODE Winsock structures.
  7. Author:
  8. Keith Moore (keithmo) 19-Apr-1995
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. typedef
  16. BOOL
  17. (* PENUM_SOCKETS_CALLBACK)(
  18. ULONG64 ActualAddress,
  19. ULONG64 Context
  20. );
  21. VOID
  22. EnumSockets(
  23. ULONG64 TableAddr,
  24. PENUM_SOCKETS_CALLBACK Callback,
  25. ULONG64 Context
  26. );
  27. ULONG64
  28. FindHandleContext (
  29. IN ULONG64 TableAddr,
  30. IN ULONG64 Handle
  31. );
  32. BOOL
  33. DumpSocketCallback (
  34. ULONG64 ActualAddress,
  35. ULONG64 Context
  36. );
  37. PSTR
  38. SansockStateToString(
  39. VOID
  40. );
  41. PSTR
  42. SandupeStateToString(
  43. ULONG State
  44. );
  45. ULONG
  46. DumpDProvCallback (
  47. PFIELD_INFO pField,
  48. PVOID UserContext
  49. );
  50. VOID
  51. DumpDProv (
  52. ULONG64 Address
  53. );
  54. ULONG
  55. DumpNProvCallback (
  56. PFIELD_INFO pField,
  57. PVOID UserContext
  58. );
  59. VOID
  60. DumpNProv (
  61. ULONG64 Address
  62. );
  63. VOID
  64. ReadUmGlobals (
  65. );
  66. //
  67. // Basic or often used parameters obtained from symbol parser
  68. // or global for the process.
  69. //
  70. ULONG LookupTableOffset, LookupTableSize, HandleContextOffset, SzProtocolOffset;
  71. ULONG64 Ws2_32ContextTable, MswsockContextTable, Ws2_32DProcess;
  72. ULONG64 CurrentProcess;
  73. DECLARE_API(sock)
  74. /*++
  75. Routine Description:
  76. Dumps User Mode socket structures.
  77. Arguments:
  78. None.
  79. Return Value:
  80. None.
  81. --*/
  82. {
  83. INT i;
  84. CHAR expr[MAX_ADDRESS_EXPRESSION];
  85. PCHAR argp;
  86. gClient = pClient;
  87. argp = ProcessOptions ((PCHAR)args);
  88. if (argp==NULL)
  89. return E_INVALIDARG;
  90. ReadUmGlobals ();
  91. if (Ws2_32ContextTable==0 ||
  92. LookupTableOffset==0 ||
  93. LookupTableSize==0 ||
  94. HandleContextOffset==0 ||
  95. (MswsockContextTable==0 && (Options & AFDKD_MSWSOCK_DISPLAY))) {
  96. return E_INVALIDARG;
  97. }
  98. dprintf (AFDKD_BRIEF_SOCKET_DISPLAY_HEADER);
  99. if ((argp[0]==0) || (Options & AFDKD_ENDPOINT_SCAN)) {
  100. EnumSockets(
  101. Ws2_32ContextTable,
  102. DumpSocketCallback,
  103. 0
  104. );
  105. }
  106. else {
  107. //
  108. // Snag the handle from the command line.
  109. //
  110. while (sscanf( argp, "%s%n", expr, &i )==1) {
  111. ULONG64 handle, contextPtr;
  112. if( CheckControlC() ) {
  113. break;
  114. }
  115. argp+=i;
  116. handle = GetExpression (expr);
  117. contextPtr = FindHandleContext (Ws2_32ContextTable, handle);
  118. if (contextPtr!=0) {
  119. DumpSocketCallback (contextPtr, 0);
  120. }
  121. }
  122. }
  123. dprintf (AFDKD_BRIEF_SOCKET_DISPLAY_TRAILER);
  124. if (Options & AFDKD_MSWSOCK_DISPLAY) {
  125. dprintf (AFDKD_BRIEF_MSWSOCK_DISPLAY_TRAILER);
  126. }
  127. return S_OK;
  128. }
  129. DECLARE_API(dprov)
  130. /*++
  131. Routine Description:
  132. Dumps User Mode Winsock data providers
  133. Arguments:
  134. None.
  135. Return Value:
  136. None.
  137. --*/
  138. {
  139. INT i;
  140. CHAR expr[MAX_ADDRESS_EXPRESSION];
  141. PCHAR argp;
  142. ULONG64 address;
  143. ULONG result;
  144. gClient = pClient;
  145. argp = ProcessOptions ((PCHAR)args);
  146. if (argp==NULL)
  147. return E_INVALIDARG;
  148. ReadUmGlobals ();
  149. dprintf (AFDKD_BRIEF_DPROV_DISPLAY_HEADER);
  150. if (argp[0]==0) {
  151. if (Ws2_32DProcess==0) {
  152. dprintf ("\ndprov: WS2_32!DPROCESS::sm_current_dprocess is NULL\n");
  153. return E_INVALIDARG;
  154. }
  155. result = GetFieldValue (Ws2_32DProcess,
  156. "WS2_32!DPROCESS",
  157. "m_protocol_catalog",
  158. address);
  159. if (result!=0) {
  160. dprintf ("\ndprov: Could not read protocol catalog, err: %ld\n", result);
  161. return E_INVALIDARG;
  162. }
  163. if (address==0) {
  164. dprintf ("\ndprov: Protocol catalog is NULL\n");
  165. return E_INVALIDARG;
  166. }
  167. result = GetFieldValue (address,
  168. "WS2_32!DCATALOG",
  169. "m_protocol_list.Flink",
  170. address);
  171. if (result!=0) {
  172. dprintf ("\ndprov: Could not read protocol catalog list Flink, err: %ld\n", result);
  173. return E_INVALIDARG;
  174. }
  175. if (address==0) {
  176. dprintf ("\ndprov: Protocol catalog list Flink is NULL\n");
  177. return E_INVALIDARG;
  178. }
  179. ListType (
  180. "WS2_32!PROTO_CATALOG_ITEM", // Type
  181. address, // Address
  182. 1, // ListByFieldAddress
  183. "m_CatalogLinkage.Flink", // NextPointer
  184. NULL,
  185. DumpDProvCallback
  186. );
  187. }
  188. else {
  189. //
  190. // Snag the provider from the command line.
  191. //
  192. while (sscanf( argp, "%s%n", expr, &i )==1) {
  193. if( CheckControlC() ) {
  194. break;
  195. }
  196. argp+=i;
  197. address = GetExpression (expr);
  198. result = (ULONG)InitTypeRead (address, WS2_32!PROTO_CATALOG_ITEM);
  199. if (result!=0) {
  200. dprintf ("\ndprov: Could not read WS2_32!PROTO_CATALOG_ITEM @ %p, err: %d\n",
  201. address, result);
  202. continue;
  203. }
  204. DumpDProv (address);
  205. if (Options & AFDKD_FIELD_DISPLAY) {
  206. ProcessFieldOutput (address, "WS2_32!PROTO_CATALOG_ITEM");
  207. }
  208. }
  209. }
  210. dprintf (AFDKD_BRIEF_DPROV_DISPLAY_TRAILER);
  211. return S_OK;
  212. }
  213. DECLARE_API(nprov)
  214. /*++
  215. Routine Description:
  216. Dumps User Mode Winsock Name Space providers
  217. Arguments:
  218. None.
  219. Return Value:
  220. None.
  221. --*/
  222. {
  223. INT i;
  224. CHAR expr[MAX_ADDRESS_EXPRESSION];
  225. PCHAR argp;
  226. ULONG64 address;
  227. ULONG result;
  228. gClient = pClient;
  229. argp = ProcessOptions ((PCHAR)args);
  230. if (argp==NULL)
  231. return E_INVALIDARG;
  232. ReadUmGlobals ();
  233. dprintf (AFDKD_BRIEF_NPROV_DISPLAY_HEADER);
  234. if (argp[0]==0) {
  235. if (Ws2_32DProcess==0) {
  236. dprintf ("\nnprov: WS2_32!DPROCESS::sm_current_dprocess is NULL\n");
  237. return E_INVALIDARG;
  238. }
  239. result = GetFieldValue (Ws2_32DProcess,
  240. "WS2_32!DPROCESS",
  241. "m_namespace_catalog",
  242. address);
  243. if (result!=0) {
  244. dprintf ("\nnprov: Could not read name space catalog, err: %ld\n", result);
  245. return E_INVALIDARG;
  246. }
  247. if (address==0) {
  248. dprintf ("\nnprov: Name space catalog is NULL\n");
  249. return E_INVALIDARG;
  250. }
  251. result = GetFieldValue (address,
  252. "WS2_32!NSCATALOG",
  253. "m_namespace_list.Flink",
  254. address);
  255. if (result!=0) {
  256. dprintf ("\nnprov: Could not read name space catalog list Flink, err: %ld\n", result);
  257. return E_INVALIDARG;
  258. }
  259. if (address==0) {
  260. dprintf ("\nnprov: Name space catalog list Flink is NULL\n");
  261. return E_INVALIDARG;
  262. }
  263. ListType (
  264. "WS2_32!NSCATALOGENTRY", // Type
  265. address, // Address
  266. 1, // ListByFieldAddress
  267. "m_CatalogLinkage.Flink", // NextPointer
  268. NULL,
  269. DumpNProvCallback
  270. );
  271. }
  272. else {
  273. //
  274. // Snag the provider from the command line.
  275. //
  276. while (sscanf( argp, "%s%n", expr, &i )==1) {
  277. if( CheckControlC() ) {
  278. break;
  279. }
  280. argp+=i;
  281. address = GetExpression (expr);
  282. result = (ULONG)InitTypeRead (address, WS2_32!NSCATALOGENTRY);
  283. if (result!=0) {
  284. dprintf ("\nnprov: Could not read WS2_32!NSCATALOGENTRY @ %p, err: %d\n",
  285. address, result);
  286. continue;
  287. }
  288. DumpNProv (address);
  289. if (Options & AFDKD_FIELD_DISPLAY) {
  290. ProcessFieldOutput (address, "WS2_32!NSCATALOGENTRY");
  291. }
  292. }
  293. }
  294. dprintf (AFDKD_BRIEF_NPROV_DISPLAY_TRAILER);
  295. return S_OK;
  296. }
  297. VOID
  298. EnumSockets(
  299. ULONG64 TableAddr,
  300. PENUM_SOCKETS_CALLBACK Callback,
  301. ULONG64 Context
  302. )
  303. /*++
  304. Routine Description:
  305. Enumerates all sockets in the socket handle table, invoking the
  306. specified callback for each socket.
  307. Arguments:
  308. TableAddr - address of the table
  309. Callback - Points to the callback to invoke for each socket.
  310. Context - An uninterpreted context value passed to the callback
  311. routine.
  312. Return Value:
  313. None.
  314. --*/
  315. {
  316. ULONG result;
  317. ULONG mask;
  318. ULONG64 lookupTableAddr;
  319. DWORD i,j;
  320. if ((result=(ULONG)InitTypeRead (
  321. TableAddr,
  322. WS2HELP!_CONTEXT_TABLE))!=0) {
  323. dprintf(
  324. "\nEnumSockets: Could not read _CONTEXT_TABLE @ %p, err: %d\n",
  325. TableAddr, result
  326. );
  327. return;
  328. }
  329. mask = (ULONG)ReadField (HandleToIndexMask);
  330. lookupTableAddr = TableAddr+LookupTableOffset;
  331. for (i=0; i<=mask; i++, lookupTableAddr+=LookupTableSize) {
  332. ULONG64 hashTableAddr, contextPtrAddr;
  333. ULONG numBuckets;
  334. if( CheckControlC() ) {
  335. return;
  336. }
  337. if ((result=(ULONG)InitTypeRead (
  338. lookupTableAddr,
  339. WS2HELP!_CTX_LOOKUP_TABLE))!=0) {
  340. dprintf(
  341. "\nEnumSockets: Could not read _CTX_LOOKUP_TABLE @ %p, err: %d\n",
  342. lookupTableAddr, result
  343. );
  344. continue;
  345. }
  346. hashTableAddr = ReadField (HashTable);
  347. if (hashTableAddr==0) {
  348. continue;
  349. }
  350. result = (ULONG)InitTypeRead (hashTableAddr, WS2HELP!_CTX_HASH_TABLE);
  351. if( result!=0) {
  352. dprintf(
  353. "\nEnumSockets: Could not read _CTX_HASH_TABLE @ %p, err: %d\n",
  354. hashTableAddr, result
  355. );
  356. continue;
  357. }
  358. numBuckets = (ULONG)ReadField (NumBuckets);
  359. contextPtrAddr = hashTableAddr+HandleContextOffset;
  360. for (j=0; j<numBuckets; j++, contextPtrAddr+=IsPtr64 () ? 8 : 4) {
  361. ULONG64 contextPtr;
  362. if( CheckControlC() ) {
  363. return;
  364. }
  365. result = ReadPtr (contextPtrAddr, &contextPtr);
  366. if (result!=0) {
  367. dprintf(
  368. "\nEnumSockets: Could not read LPWSHANDLE_CONTEXT @ %p, err: %d\n",
  369. contextPtrAddr, result
  370. );
  371. }
  372. else if (contextPtr==0) {
  373. }
  374. else {
  375. if (! (Callback) (contextPtr, Context)) {
  376. return;
  377. }
  378. }
  379. }
  380. }
  381. } // EnumSockets
  382. ULONG64
  383. FindHandleContext (
  384. IN ULONG64 TableAddr,
  385. IN ULONG64 Handle
  386. )
  387. /*++
  388. Routine Description:
  389. Find the socket in the socket handle table and returns its
  390. associated context structure
  391. Arguments:
  392. TableAddr - address of the table
  393. Handle - handle to find
  394. Return Value:
  395. Context or NULL if not found.
  396. --*/
  397. {
  398. ULONG result;
  399. ULONG mask;
  400. ULONG64 lookupTableAddr;
  401. ULONG64 hashTableAddr,contextPtrAddr,contextPtr;
  402. ULONG numBuckets;
  403. if ((result=(ULONG)InitTypeRead (
  404. TableAddr,
  405. WS2HELP!_CONTEXT_TABLE))!=0) {
  406. dprintf(
  407. "\nFindHandleContext: Could not read _CONTEXT_TABLE @ %p, err: %d\n",
  408. TableAddr, result
  409. );
  410. return 0;
  411. }
  412. mask = (ULONG)ReadField (HandleToIndexMask);
  413. lookupTableAddr = TableAddr +
  414. LookupTableOffset +
  415. LookupTableSize*((Handle>>2)&mask);
  416. if ((result=(ULONG)InitTypeRead (
  417. lookupTableAddr,
  418. WS2HELP!_CTX_LOOKUP_TABLE))!=0) {
  419. dprintf(
  420. "\nFindHandleContext: Could not read _CTX_LOOKUP_TABLE @ %p, err: %d\n",
  421. lookupTableAddr, result
  422. );
  423. return 0;
  424. }
  425. hashTableAddr = ReadField (HashTable);
  426. if (hashTableAddr==0) {
  427. dprintf(
  428. "\nFindHandleContext: HASH table for handle %p is NULL @ %p\n",
  429. Handle, lookupTableAddr
  430. );
  431. return 0;
  432. }
  433. result = (ULONG)InitTypeRead (hashTableAddr, WS2HELP!_CTX_HASH_TABLE);
  434. if( result!=0) {
  435. dprintf(
  436. "\nFindHandleContext: Could not read _CTX_HASH_TABLE @ %p, err: %d\n",
  437. hashTableAddr, result
  438. );
  439. return 0;
  440. }
  441. numBuckets = (ULONG)ReadField (NumBuckets);
  442. if (numBuckets==0) {
  443. dprintf(
  444. "\nFindHandleContext: NumBuckets in _CTX_HASH_TABLE @ %p is 0!!!\n",
  445. hashTableAddr
  446. );
  447. return 0;
  448. }
  449. contextPtrAddr = hashTableAddr +
  450. HandleContextOffset +
  451. (IsPtr64 () ? 8 : 4) * (Handle%numBuckets);
  452. result = ReadPtr (contextPtrAddr, &contextPtr);
  453. if (result!=0) {
  454. dprintf(
  455. "\nFindHandleContext: Could not read LPWSHANDLE_CONTEXT @ %p, err: %d\n",
  456. contextPtrAddr, result
  457. );
  458. return 0;
  459. }
  460. if (contextPtr==0) {
  461. dprintf(
  462. "\nFindHandleContext: LPWSHANDLE_CONTEXT is NULL for handle %p @ %p\n",
  463. Handle, contextPtrAddr
  464. );
  465. return 0;
  466. }
  467. return contextPtr;
  468. }
  469. enum {
  470. AFDKD_SocketStateInitializing = -1,
  471. AFDKD_SocketStateOpen = 0,
  472. AFDKD_SocketStateBound,
  473. AFDKD_SocketStateBoundSpecific, // Datagram only
  474. AFDKD_SocketStateConnected, // VC only
  475. AFDKD_SocketStateClosing
  476. } AFDKD_SOCK_STATE;
  477. BOOL
  478. DumpSocketCallback (
  479. ULONG64 ActualAddress,
  480. ULONG64 Context
  481. )
  482. /*++
  483. Routine Description:
  484. Dumps ws2_32 and mswsock socket information
  485. Arguments:
  486. Actual address - address of ws2_32 socket info
  487. Context - NOT used.
  488. Return Value:
  489. TRUE to continue enumeration.
  490. --*/
  491. {
  492. ULONG result;
  493. ULONG64 catItemAddress, handle, mssockAddr = 0;
  494. WCHAR szProtocol[255+1]; //WSAPROTOCOL_LEN+1 in winsock2.h
  495. result = GetFieldValue (ActualAddress, "WS2_32!DSOCKET", "Handle", handle);
  496. if (result!=0) {
  497. dprintf(
  498. "\nDumpSocketCallback: Could not read socket handle from DSOCKET @ %p, err: %d\n",
  499. ActualAddress, result
  500. );
  501. return TRUE;
  502. }
  503. if (Options & AFDKD_CONDITIONAL) {
  504. BOOLEAN skip = FALSE;
  505. if (Options & AFDKD_MSWSOCK_DISPLAY) {
  506. mssockAddr = FindHandleContext (MswsockContextTable, handle);
  507. if (mssockAddr!=0) {
  508. if (SavedMinorVersion>=2213) {
  509. skip = !CheckConditional (mssockAddr, "MSWSOCK!SOCKET_INFORMATION");
  510. }
  511. else {
  512. skip = !CheckConditional (mssockAddr, "MSAFD!SOCKET_INFORMATION");
  513. }
  514. }
  515. else
  516. skip = TRUE;
  517. }
  518. else {
  519. skip = !CheckConditional (ActualAddress, "WS2_32!DSOCKET");
  520. }
  521. if (skip) {
  522. dprintf (".");
  523. return TRUE;
  524. }
  525. }
  526. result = (ULONG)InitTypeRead (ActualAddress, WS2_32!DSOCKET);
  527. if (result!=0) {
  528. dprintf(
  529. "\nDumpSocketCallback: Could not read DSOCKET @ %p, err: %d\n",
  530. ActualAddress, result
  531. );
  532. return TRUE;
  533. }
  534. catItemAddress = ReadField (m_catalog_item);
  535. if (catItemAddress!=0 && SzProtocolOffset!=0) {
  536. if (!ReadMemory (catItemAddress + SzProtocolOffset,
  537. szProtocol,
  538. sizeof (szProtocol),
  539. NULL)) {
  540. _snwprintf (szProtocol, sizeof (szProtocol)/2, L"Could not read protocol string @ %I64X", catItemAddress+SzProtocolOffset);
  541. }
  542. }
  543. else {
  544. szProtocol[0] = 0;
  545. }
  546. dprintf ("\n%06.6p %p %c%c%c %p-%-.256ls",
  547. handle,
  548. ActualAddress,
  549. ReadField (m_pvd_socket) ? 'P' : ' ',
  550. ReadField (m_api_socket) ? 'A' : ' ',
  551. ReadField (m_overlapped_socket) ? 'O' : ' ',
  552. ReadField (m_provider),
  553. szProtocol);
  554. if (Options & AFDKD_MSWSOCK_DISPLAY) {
  555. ULONG64 sansockAddr, val;
  556. if (mssockAddr==0) {
  557. mssockAddr = FindHandleContext (MswsockContextTable, handle);
  558. }
  559. if (mssockAddr!=0) {
  560. if (SavedMinorVersion>=2213) {
  561. result = (ULONG)InitTypeRead (mssockAddr, MSWSOCK!SOCKET_INFORMATION);
  562. }
  563. else {
  564. result = (ULONG)InitTypeRead (mssockAddr, MSAFD!SOCKET_INFORMATION);
  565. }
  566. if (result!=0) {
  567. dprintf (
  568. "\nDumpSocketCallback: Could not read SOCKET_INFORMATION @ %p\n",
  569. mssockAddr);
  570. return TRUE;
  571. }
  572. dprintf (
  573. "\n MSAFD_sock:%p", mssockAddr);
  574. switch (ReadField(State)) {
  575. case AFDKD_SocketStateInitializing:
  576. dprintf (",initializing");
  577. break;
  578. case AFDKD_SocketStateOpen:
  579. dprintf (",open");
  580. break;
  581. case AFDKD_SocketStateBound:
  582. case AFDKD_SocketStateBoundSpecific:
  583. {
  584. CHAR transportAddress[MAX_TRANSPORT_ADDR];
  585. ULONG length = (ULONG)ReadField (LocalAddressLength);
  586. ULONG64 address = ReadField (LocalAddress);
  587. if (ReadMemory (address,
  588. transportAddress,
  589. length<sizeof (transportAddress)
  590. ? length
  591. : sizeof (transportAddress),
  592. &length)) {
  593. dprintf (",bnd:%s",
  594. TransportAddressToString (
  595. (PTRANSPORT_ADDRESS)(
  596. transportAddress
  597. -FIELD_OFFSET (TRANSPORT_ADDRESS, Address[0].AddressType)),
  598. address));
  599. }
  600. else {
  601. dprintf (",bnd:%p", address);
  602. }
  603. }
  604. break;
  605. case AFDKD_SocketStateConnected:
  606. {
  607. CHAR transportAddress[MAX_TRANSPORT_ADDR];
  608. ULONG length = (ULONG)ReadField (LocalAddressLength);
  609. ULONG64 address = ReadField (LocalAddress);
  610. if (ReadMemory (address,
  611. transportAddress,
  612. length<sizeof (transportAddress)
  613. ? length
  614. : sizeof (transportAddress),
  615. &length)) {
  616. dprintf (",bnd:%s",
  617. TransportAddressToString (
  618. (PTRANSPORT_ADDRESS)(
  619. transportAddress
  620. -FIELD_OFFSET (TRANSPORT_ADDRESS, Address[0].AddressType)),
  621. address));
  622. }
  623. else {
  624. dprintf (",bnd:%p", address);
  625. }
  626. length = (ULONG)ReadField (RemoteAddressLength);
  627. address = ReadField (RemoteAddress);
  628. if (ReadMemory (address,
  629. transportAddress,
  630. length<sizeof (transportAddress)
  631. ? length
  632. : sizeof (transportAddress),
  633. &length)) {
  634. dprintf (",con:%s",
  635. TransportAddressToString (
  636. (PTRANSPORT_ADDRESS)(
  637. transportAddress
  638. -FIELD_OFFSET (TRANSPORT_ADDRESS, Address[0].AddressType)),
  639. address));
  640. }
  641. else {
  642. dprintf (",con:%p", address);
  643. }
  644. }
  645. break;
  646. case AFDKD_SocketStateClosing:
  647. dprintf (",closing");
  648. break;
  649. default:
  650. dprintf (",in state %d", (ULONG)ReadField (State));
  651. break;
  652. }
  653. dprintf (",flags:%s%s%s%s%s%s%s%s%s%s",
  654. ReadField (Listening) ? "L" : "",
  655. ReadField (Broadcast) ? "B" : "",
  656. ReadField (Debug) ? "D" : "",
  657. ReadField (OobInline) ? "O" : "",
  658. ReadField (ReuseAddresses) ? "A" : "",
  659. ReadField (ExclusiveAddressUse) ? "E" : "",
  660. ReadField (NonBlocking) ? "N" : "",
  661. ReadField (ConditionalAccept) ? "C" : "",
  662. ReadField (ReceiveShutdown) ? "R" : "",
  663. ReadField (SendShutdown) ? "S" : ""
  664. );
  665. if (ReadField (LingerInfo.l_onoff)) {
  666. dprintf (",linger:%d", (ULONG)ReadField (LingerInfo.l_linger));
  667. }
  668. if ((val=ReadField (SendTimeout))!=0) {
  669. dprintf (",sndTO:%ld",(ULONG)val);
  670. }
  671. if ((val=ReadField (ReceiveTimeout))!=0) {
  672. dprintf (",rcvTO:%ld",(ULONG)val);
  673. }
  674. if ((val=ReadField (EventSelectlNetworkEvents))!=0) {
  675. dprintf (",eventSel:%lx",(ULONG)val);
  676. }
  677. if ((val=ReadField (AsyncSelectlEvent))!=0) {
  678. dprintf (",asyncSel:%lx",(ULONG)val);
  679. }
  680. if ((sansockAddr=ReadField(SanSocket))!=0) {
  681. BOOLEAN flowOn;
  682. UINT count;
  683. if (SavedMinorVersion>=2213) {
  684. result = (ULONG)InitTypeRead (sansockAddr, MSWSOCK!SOCK_SAN_INFORMATION);
  685. }
  686. else {
  687. result = (ULONG)InitTypeRead (sansockAddr, MSAFD!SOCK_SAN_INFORMATION);
  688. }
  689. if (result!=0) {
  690. dprintf (
  691. "\nDumpSocketCallback: Could not read SOCK_SAN_INFORMATION @ %p\n",
  692. sansockAddr);
  693. return TRUE;
  694. }
  695. dprintf ("\n SAN_sock:%p,%s,%ssndCr:%d,rcvCr:%d",
  696. sansockAddr,
  697. SansockStateToString (),
  698. SandupeStateToString ((ULONG)ReadField(SockDupState)),
  699. (ULONG)ReadField(SendCredit),
  700. (ULONG)ReadField(ReceiversSendCredit));
  701. count = (ULONG)ReadField (ReceiveBytesBuffered);
  702. if (count>0) {
  703. dprintf(",rcvB:%d", count);
  704. }
  705. count = (ULONG)ReadField (ExpeditedBytesBuffered);
  706. if (count>0) {
  707. dprintf(",oobB:%d", count);
  708. }
  709. count = (ULONG)ReadField (SendBytesBuffered);
  710. if (count>0) {
  711. dprintf(",sndB:%d", count);
  712. }
  713. flowOn = ReadField (FlowControlInitialized)!=0;
  714. dprintf (",flags:%s%s%s",
  715. flowOn ? "F" : "",
  716. ReadField (RemoteReset) ? "R" : "",
  717. ReadField (IsClosing) ? "C" : "");
  718. }
  719. if (Options & AFDKD_FIELD_DISPLAY) {
  720. if (SavedMinorVersion>=2213) {
  721. ProcessFieldOutput (mssockAddr, "MSWSOCK!SOCKET_INFORMATION");
  722. }
  723. else {
  724. ProcessFieldOutput (mssockAddr, "MSAFD!SOCKET_INFORMATION");
  725. }
  726. }
  727. } // else Socket not in mswsock handle table
  728. } // else MSWSOCK display is not enabled.
  729. return TRUE;
  730. }
  731. enum {
  732. AFDKD_CONNECTED=1,
  733. AFDKD_NON_BLOCKING_IN_PROGRESS=2,
  734. AFDKD_BLOCKING_IN_PROGRESS=3,
  735. AFDKD_WAITING_FOR_FIRST_MSG=4
  736. } AFDKD_SAN_SOCK_STATE;
  737. typedef enum {
  738. AFDKD_NonBlockingConnectState = 1,
  739. AFDKD_ListenState = 2,
  740. AFDKD_AcceptInProgress = 3
  741. } AFDKD_SAN_SOCK_STATE1;
  742. enum {
  743. AFDKD_SUSPENDING_COMMUNICATION=1, // suspending all data transfers (source proc)
  744. AFDKD_SOCK_MIGRATED=2, // sock now fully owned by some other proc
  745. AFDKD_COMM_SUSPENDED=3, // remote peer has requested suspension
  746. AFDKD_IMPORTING_SOCK=4 // getting sock from source process
  747. } AFDKD_SAN_DUPE_STATE;
  748. PSTR
  749. SansockStateToString(
  750. VOID
  751. )
  752. {
  753. ULONG IsConnected = (ULONG)ReadField (IsConnected);
  754. ULONG State1 = (ULONG)ReadField(State1);
  755. if (IsConnected == AFDKD_NON_BLOCKING_IN_PROGRESS ||
  756. IsConnected == AFDKD_BLOCKING_IN_PROGRESS) {
  757. return "con-ing";
  758. }
  759. else if (IsConnected == AFDKD_CONNECTED) {
  760. return "con-ed";
  761. }
  762. else if (IsConnected == AFDKD_WAITING_FOR_FIRST_MSG) {
  763. return "waiting";
  764. }
  765. else if (State1 == AFDKD_ListenState) {
  766. return "lsn-ing";
  767. }
  768. else if (State1 == AFDKD_AcceptInProgress) {
  769. return "acc-ing";
  770. }
  771. return "unknown state";
  772. }
  773. PSTR
  774. SandupeStateToString(
  775. ULONG State
  776. )
  777. {
  778. switch (State) {
  779. case 0:
  780. return "";
  781. case AFDKD_SUSPENDING_COMMUNICATION:
  782. return "ssp-ing,";
  783. case AFDKD_SOCK_MIGRATED:
  784. return "mgr-ed,";
  785. case AFDKD_COMM_SUSPENDED:
  786. return "ssp-ed,";
  787. case AFDKD_IMPORTING_SOCK:
  788. return "imp-ing,";
  789. default:
  790. return "unknown dupe state,";
  791. }
  792. }
  793. ULONG
  794. DumpDProvCallback (
  795. PFIELD_INFO pField,
  796. PVOID UserContext
  797. )
  798. {
  799. ULONG result;
  800. if (!(Options & AFDKD_CONDITIONAL) ||
  801. CheckConditional (pField->address, "WS2_32!PROTO_CATALOG_ITEM")) {
  802. result = (ULONG)InitTypeRead (pField->address, WS2_32!PROTO_CATALOG_ITEM);
  803. if (result!=0) {
  804. dprintf ("\nDumpDProvCallback: Could not read WS2_32!PROTO_CATALOG_ITEM @ %p, err: %d\n",
  805. pField->address, result);
  806. return 1;
  807. }
  808. DumpDProv (pField->address);
  809. if (Options & AFDKD_FIELD_DISPLAY) {
  810. ProcessFieldOutput (pField->address, "WS2_32!PROTO_CATALOG_ITEM");
  811. }
  812. }
  813. else {
  814. dprintf (".");
  815. }
  816. return 0;
  817. }
  818. VOID
  819. DumpDProv (
  820. ULONG64 Address
  821. )
  822. {
  823. WCHAR szProtocol[255+1]; //WSAPROTOCOL_LEN+1 in winsock2.h
  824. LONG protocol = (LONG)ReadField (m_ProtoInfo.iProtocol);
  825. CHAR protoStr[16];
  826. if (protocol==0x80000000) {
  827. _snprintf (protoStr, sizeof (protoStr)-1, "-000");
  828. }
  829. else {
  830. _snprintf (protoStr, sizeof (protoStr)-1, "%4d", protocol);
  831. }
  832. protoStr[sizeof(protoStr)-1] = 0;
  833. if (!ReadMemory (Address + SzProtocolOffset,
  834. szProtocol,
  835. sizeof (szProtocol),
  836. NULL)) {
  837. _snwprintf (szProtocol, sizeof (szProtocol)/2-1, L"Could not read protocol string @ %I64X", Address+SzProtocolOffset);
  838. szProtocol[sizeof(szProtocol)/2-1] = 0;
  839. }
  840. // Provider PFlag SFlag CatID Ch RefC Tripple Protocol Name
  841. dprintf (
  842. IsPtr64 ()
  843. ? "\n%011.011p %2.2x %6.6x %5d %2d %4.4x %2d,%1d,%s(%d) %ls"
  844. : "\n%008.008p %2.2x %6.6x %5d %2d %4.4x %2d,%1d,%s(%d) %ls",
  845. Address,
  846. (LONG)ReadField (m_ProtoInfo.dwProviderFlags),
  847. (LONG)ReadField (m_ProtoInfo.dwServiceFlags1),
  848. (LONG)ReadField (m_ProtoInfo.dwCatalogEntryId),
  849. (LONG)ReadField (m_ProtoInfo.ProtocolChain.ChainLen),
  850. (LONG)ReadField (m_reference_count),
  851. (LONG)ReadField (m_ProtoInfo.iAddressFamily),
  852. (LONG)ReadField (m_ProtoInfo.iSocketType),
  853. protoStr,
  854. (LONG)ReadField (m_ProtoInfo.iProtocolMaxOffset),
  855. szProtocol);
  856. }
  857. ULONG
  858. DumpNProvCallback (
  859. PFIELD_INFO pField,
  860. PVOID UserContext
  861. )
  862. {
  863. ULONG result;
  864. if (!(Options & AFDKD_CONDITIONAL) ||
  865. CheckConditional (pField->address, "WS2_32!NSCATALOGENTRY")) {
  866. result = (ULONG)InitTypeRead (pField->address, WS2_32!NSCATALOGENTRY);
  867. if (result!=0) {
  868. dprintf ("\nDumpNProvCallback: Could not read WS2_32!NSCATALOGENTRY @ %p, err: %d\n",
  869. pField->address, result);
  870. return 1;
  871. }
  872. DumpNProv (pField->address);
  873. if (Options & AFDKD_FIELD_DISPLAY) {
  874. ProcessFieldOutput (pField->address, "WS2_32!NSCATALOGENTRY");
  875. }
  876. }
  877. else {
  878. dprintf (".");
  879. }
  880. return 0;
  881. }
  882. VOID
  883. DumpNProv (
  884. ULONG64 Address
  885. )
  886. {
  887. WCHAR szProtocol[255+1]; //WSAPROTOCOL_LEN+1 in winsock2.h
  888. ULONG64 strAddr = ReadField (m_providerDisplayString);
  889. if (strAddr!=0) {
  890. if (!ReadMemory (strAddr,
  891. szProtocol,
  892. sizeof (szProtocol),
  893. NULL)) {
  894. _snwprintf (szProtocol, sizeof (szProtocol)/2-1, L"Could not read protocol string @ %I64X", strAddr);
  895. }
  896. }
  897. else {
  898. _snwprintf (szProtocol, sizeof (szProtocol)/2-1, L"NULL");
  899. }
  900. szProtocol[sizeof(szProtocol)/2-1] = 0;
  901. // Provider NSid AF Fl RefC Display String"
  902. dprintf (
  903. IsPtr64 ()
  904. ? "\n%011.011p %5d %2d %s%s %4.4x %ls"
  905. : "\n%008.008p %5d %2d %s%s %4.4x %ls",
  906. Address,
  907. (LONG)ReadField (m_namespace_id),
  908. (LONG)ReadField (m_address_family),
  909. ReadField (m_enabled) ? "E" : " ",
  910. ReadField (m_stores_service_class_info) ? "C" : " ",
  911. (LONG)ReadField (m_reference_count),
  912. szProtocol);
  913. }
  914. VOID
  915. ReadUmGlobals (
  916. )
  917. /*++
  918. Routine Description:
  919. Reads type info and globals of Winsock user mode DLLs
  920. Arguments:
  921. None
  922. Return Value:
  923. None
  924. --*/
  925. {
  926. ULONG result;
  927. ULONG64 process;
  928. process = GetExpression ("@$proc");
  929. if (CurrentProcess==0 ||
  930. CurrentProcess!=process ||
  931. LookupTableOffset==0 ||
  932. HandleContextOffset==0 ||
  933. LookupTableSize==0) {
  934. if ((LookupTableOffset==0 &&
  935. (result=(ULONG)GetFieldOffset(
  936. "WS2HELP!_CONTEXT_TABLE",
  937. "Tables",
  938. &LookupTableOffset))!=0) ||
  939. (HandleContextOffset==0 &&
  940. (result=(ULONG)GetFieldOffset(
  941. "WS2HELP!_CTX_HASH_TABLE",
  942. "Buckets",
  943. &HandleContextOffset))!=0) ||
  944. (LookupTableSize==0 &&
  945. (LookupTableSize = GetTypeSize (
  946. "WS2HELP!_CTX_LOOKUP_TABLE"))==0) ) {
  947. dprintf ("\nReadUmGlobals: Could not get WS2HELP.DLL type info, err:%ld\n", result);
  948. }
  949. }
  950. if (CurrentProcess==0 ||
  951. CurrentProcess!=process ||
  952. Ws2_32ContextTable==0 ||
  953. SzProtocolOffset==0 ||
  954. Ws2_32DProcess==0) {
  955. if ((Ws2_32ContextTable==0 &&
  956. (result=GetFieldValue (0,
  957. "WS2_32!DSOCKET__sm_context_table",
  958. NULL,
  959. Ws2_32ContextTable))!=0 &&
  960. (result=GetFieldValue (0,
  961. "WS2_32!DSOCKET::sm_context_table",
  962. NULL,
  963. Ws2_32ContextTable))!=0) ||
  964. (Ws2_32DProcess==0 &&
  965. (result=GetFieldValue (0,
  966. "WS2_32!DPROCESS__sm_current_dprocess",
  967. NULL,
  968. Ws2_32DProcess))!=0 &&
  969. (result=GetFieldValue (0,
  970. "WS2_32!DSOCKET::sm_current_dprocess",
  971. NULL,
  972. Ws2_32DProcess))!=0) ||
  973. (SzProtocolOffset==0 &&
  974. (result=(ULONG)GetFieldOffset (
  975. "WS2_32!PROTO_CATALOG_ITEM",
  976. "m_ProtoInfo.szProtocol",
  977. &SzProtocolOffset))!=0) ) {
  978. dprintf ("\nReadUmGlobals: Could not get WS2_32.DLL globals/type info, err: %ld\n", result);
  979. }
  980. }
  981. if (Options & AFDKD_MSWSOCK_DISPLAY) {
  982. if (CurrentProcess==0 ||
  983. CurrentProcess!=process ||
  984. MswsockContextTable==0) {
  985. if (SavedMinorVersion>=2213) {
  986. result=GetFieldValue (0,
  987. "MSWSOCK!SockContextTable",
  988. NULL,
  989. MswsockContextTable);
  990. if (result!=0) {
  991. dprintf ("\nReadUmGlobals: Could not get MSWSOCK.DLL globals, err: %ld\n", result);
  992. }
  993. }
  994. else {
  995. result=GetFieldValue (0,
  996. "MSAFD!SockContextTable",
  997. NULL,
  998. MswsockContextTable);
  999. if (result!=0) {
  1000. dprintf ("\nReadUmGlobals: Could not get MSAFD.DLL globals, err: %ld\n", result);
  1001. }
  1002. }
  1003. }
  1004. }
  1005. CurrentProcess = process;
  1006. dprintf ("\nCurrent process: %p\n", process);
  1007. }