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.

480 lines
10 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. tcpext.c
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the kernel debugger extensions dll.
  8. Author:
  9. John Ballard
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. //
  16. // globals
  17. //
  18. EXT_API_VERSION ApiVersion = { 3, 5, EXT_API_VERSION_NUMBER, 0 };
  19. WINDBG_EXTENSION_APIS ExtensionApis;
  20. USHORT SavedMajorVersion;
  21. USHORT SavedMinorVersion;
  22. BOOLEAN ChkTarget;
  23. INT Item;
  24. HANDLE _hInstance;
  25. HANDLE _hAdditionalReference;
  26. HANDLE _hProcessHeap;
  27. int _Indent = 0;
  28. char IndentBuf[ 80 ]={"\0 "};
  29. DllInit(
  30. HANDLE hModule,
  31. DWORD dwReason,
  32. DWORD dwReserved
  33. )
  34. {
  35. switch (dwReason) {
  36. case DLL_THREAD_ATTACH:
  37. break;
  38. case DLL_THREAD_DETACH:
  39. break;
  40. case DLL_PROCESS_DETACH:
  41. break;
  42. case DLL_PROCESS_ATTACH:
  43. _hInstance = hModule;
  44. _hAdditionalReference = NULL;
  45. break;
  46. }
  47. return TRUE;
  48. }
  49. VOID
  50. WinDbgExtensionDllInit(
  51. PWINDBG_EXTENSION_APIS lpExtensionApis,
  52. USHORT MajorVersion,
  53. USHORT MinorVersion
  54. )
  55. {
  56. ExtensionApis = *lpExtensionApis;
  57. SavedMajorVersion = MajorVersion;
  58. SavedMinorVersion = MinorVersion;
  59. ChkTarget = SavedMajorVersion == 0x0c ? TRUE : FALSE;
  60. return;
  61. }
  62. DECLARE_API( version )
  63. {
  64. #if DBG
  65. PCHAR DebuggerType = "Checked";
  66. #else
  67. PCHAR DebuggerType = "Free";
  68. #endif
  69. dprintf( "%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  70. DebuggerType,
  71. VER_PRODUCTBUILD,
  72. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  73. SavedMinorVersion
  74. );
  75. }
  76. VOID
  77. CheckVersion(
  78. VOID
  79. )
  80. {
  81. return;
  82. #if DBG
  83. if ((SavedMajorVersion != 0x0c) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  84. dprintf("\r\n*** Extension DLL(%d Checked) does not match target system(%d %s)\r\n\r\n",
  85. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  86. }
  87. #else
  88. if ((SavedMajorVersion != 0x0f) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  89. dprintf("\r\n*** Extension DLL(%d Free) does not match target system(%d %s)\r\n\r\n",
  90. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  91. }
  92. #endif
  93. }
  94. LPEXT_API_VERSION
  95. ExtensionApiVersion(
  96. VOID
  97. )
  98. {
  99. return &ApiVersion;
  100. }
  101. //
  102. // Exported functions
  103. //
  104. DECLARE_API( help )
  105. /*++
  106. Routine Description:
  107. Command help for ISN debugger extensions.
  108. Arguments:
  109. None
  110. Return Value:
  111. None
  112. --*/
  113. {
  114. dprintf("tcpip debugger extension commands:\n\n");
  115. dprintf("\ttcb <ptr> - Dump a TCB\n");
  116. dprintf("\ttcbtable - Dump TCB table\n");
  117. dprintf("\ttcbsrch <ptr> - Searchs given tcb in tcbtable\n");
  118. dprintf("\ttcpaostats - Dump AOStats\n");
  119. dprintf("\ttcptwqstats - Dump TWQ Stats\n");
  120. dprintf("\ttcpconn <ptr> [f] - Dump a TCPConn\n");
  121. dprintf("\ttcpconntable [f] - Dump TCPConnTable\n");
  122. dprintf("\ttcpconnstats - Dump TCPConnStats\n");
  123. dprintf("\tirp <ptr> [f] - Dump an IRP\n");
  124. dprintf("\tao <ptr> - Dump an AddressObject\n");
  125. dprintf("\tnte <ptr> - Dump a NetTableEntry\n");
  126. dprintf("\tntelist - Dump NetTableList\n");
  127. dprintf("\tinterface <ptr> - Dump an Interface\n");
  128. dprintf("\tiflist - Dump IFList\n");
  129. dprintf("\trce <ptr> - Dump a RouteCacheEntry\n");
  130. dprintf("\trte <ptr> - Dump a RouteTableEntry\n");
  131. dprintf("\trtes - Dump RouteTable (like route print)\n");
  132. dprintf("\trtetable - Dump whole trie \n");
  133. dprintf("\tate <ptr> - Dump an ARPTableEntry\n");
  134. dprintf("\tai <ptr> - Dump an ARPInterface\n");
  135. dprintf("\tarptable [<ptr>] - Dump ARPTable [starting from address]\n");
  136. dprintf("\tMDLChain <ptr> - Dump the MDL chain\n");
  137. dprintf("\tdumplog - Dump the Log buffer (only on checked build)\n");
  138. dprintf("\ttcpfile <ptr> - Dump the tcp file object\n");
  139. dprintf("\ttcpconnblock <ptr> - Dump the connection block\n");
  140. dprintf("\n");
  141. dprintf( "Compiled on " __DATE__ " at " __TIME__ "\n" );
  142. return;
  143. }
  144. ULONG
  145. GetUlongValue (
  146. PCHAR String
  147. )
  148. {
  149. ULONG Location;
  150. ULONG Value;
  151. ULONG result;
  152. Location = GetExpression( String );
  153. if (!Location) {
  154. dprintf("unable to get %s\n",String);
  155. return 0;
  156. }
  157. if ((!ReadMemory((DWORD)Location,&Value,sizeof(ULONG),&result)) ||
  158. (result < sizeof(ULONG))) {
  159. dprintf("unable to get %s\n",String);
  160. return 0;
  161. }
  162. return Value;
  163. }
  164. VOID
  165. dprintSymbolPtr
  166. (
  167. PVOID Pointer,
  168. PCHAR EndOfLine
  169. )
  170. {
  171. UCHAR SymbolName[ 80 ];
  172. ULONG Displacement;
  173. dprintf("%-10lx", ( ULONG )Pointer );
  174. GetSymbol( Pointer, SymbolName, &Displacement );
  175. if ( Displacement == 0 )
  176. {
  177. dprintf( "(%s)%s", SymbolName, EndOfLine );
  178. }
  179. else
  180. {
  181. dprintf( "(%s + 0x%X)%s", SymbolName, Displacement, EndOfLine );
  182. }
  183. }
  184. VOID
  185. dprint_nchar
  186. (
  187. PCHAR pch,
  188. int cch
  189. )
  190. {
  191. CHAR ch;
  192. int index;
  193. for ( index = 0; index < cch; index ++ )
  194. {
  195. ch = pch[ index ];
  196. dprintf( "%c", ( ch >= 32 ) ? ch : '.' );
  197. }
  198. }
  199. VOID
  200. dprint_hardware_address
  201. (
  202. PUCHAR Address
  203. )
  204. {
  205. dprintf( "%02x-%02x-%02x-%02x-%02x-%02x",
  206. Address[ 0 ],
  207. Address[ 1 ],
  208. Address[ 2 ],
  209. Address[ 3 ],
  210. Address[ 4 ],
  211. Address[ 5 ] );
  212. }
  213. VOID
  214. dprint_IP_address
  215. (
  216. IPAddr Address
  217. )
  218. {
  219. uchar IPAddrBuffer[(sizeof(IPAddr) * 4)];
  220. uint i;
  221. uint IPAddrCharCount;
  222. //
  223. // Convert the IP address into a string.
  224. //
  225. IPAddrCharCount = 0;
  226. for (i = 0; i < sizeof(IPAddr); i++) {
  227. uint CurrentByte;
  228. CurrentByte = Address & 0xff;
  229. if (CurrentByte > 99) {
  230. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 100) + '0';
  231. CurrentByte %= 100;
  232. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 10) + '0';
  233. CurrentByte %= 10;
  234. } else if (CurrentByte > 9) {
  235. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 10) + '0';
  236. CurrentByte %= 10;
  237. }
  238. IPAddrBuffer[IPAddrCharCount++] = CurrentByte + '0';
  239. if (i != (sizeof(IPAddr) - 1))
  240. IPAddrBuffer[IPAddrCharCount++] = '.';
  241. Address >>= 8;
  242. }
  243. IPAddrBuffer[IPAddrCharCount] = '\0';
  244. dprintf( "%s", IPAddrBuffer );
  245. }
  246. BOOL
  247. dprint_enum_name
  248. (
  249. ULONG Value,
  250. PENUM_INFO pEnumInfo
  251. )
  252. {
  253. while ( pEnumInfo->pszDescription != NULL )
  254. {
  255. if ( pEnumInfo->Value == Value )
  256. {
  257. dprintf( "%.40s", pEnumInfo->pszDescription );
  258. return( TRUE );
  259. }
  260. pEnumInfo ++;
  261. }
  262. dprintf( "Unknown enumeration value." );
  263. return( FALSE );
  264. }
  265. BOOL
  266. dprint_flag_names
  267. (
  268. ULONG Value,
  269. PFLAG_INFO pFlagInfo
  270. )
  271. {
  272. BOOL bFoundOne = FALSE;
  273. while ( pFlagInfo->pszDescription != NULL )
  274. {
  275. if ( pFlagInfo->Value & Value )
  276. {
  277. if ( bFoundOne )
  278. {
  279. dprintf( " | " );
  280. }
  281. bFoundOne = TRUE;
  282. dprintf( "%.15s", pFlagInfo->pszDescription );
  283. }
  284. pFlagInfo ++;
  285. }
  286. return( bFoundOne );
  287. }
  288. BOOL
  289. dprint_masked_value
  290. (
  291. ULONG Value,
  292. ULONG Mask
  293. )
  294. {
  295. CHAR Buf[ 9 ];
  296. ULONG nibble;
  297. int index;
  298. for ( index = 0; index < 8; index ++ )
  299. {
  300. nibble = ( Mask & 0xF0000000 );
  301. /*
  302. dprintf( "#%d: nibble == %08X\n"
  303. " Mask == %08X\n"
  304. " Value == %08X\n", index, nibble, Mask, Value );
  305. */
  306. if ( nibble )
  307. {
  308. Buf[ index ] = "0123456789abcdef"[ (( nibble & Value ) >> 28) & 0xF ];
  309. }
  310. else
  311. {
  312. Buf[ index ] = ' ';
  313. }
  314. Mask <<= 4;
  315. Value <<= 4;
  316. }
  317. Buf[ 8 ] = '\0';
  318. dprintf( "%s", Buf );
  319. return( TRUE );
  320. }
  321. void
  322. dprint_unicode_string( UNICODE_STRING String )
  323. {
  324. WCHAR Buf[256];
  325. ULONG result;
  326. dprintf( "{ " );
  327. dprintf( "Length %x, MaxLength %x ", String.Length, String.MaximumLength );
  328. if ( String.Length ) {
  329. if (!ReadMemory( (ULONG)String.Buffer,
  330. Buf,
  331. sizeof( Buf ),
  332. &result ))
  333. {
  334. dprintf( "ReadMemory(@%lx) failed.",String.Buffer );
  335. } else {
  336. Buf[MAX(255, (String.Length/sizeof(WCHAR)) )] = L'\0';
  337. dprintf( "\"%ws\"", Buf );
  338. }
  339. }
  340. dprintf( " }\n" );
  341. }
  342. void
  343. dprint_ansi_string( PUCHAR String )
  344. {
  345. UCHAR Buf[256] = {0};
  346. ULONG result;
  347. if ( String ) {
  348. if (!ReadMemory( (ULONG)String,
  349. Buf,
  350. sizeof( Buf ) - 1,
  351. &result )) {
  352. dprintf( "ReadMemory(@%lx) failed.", String );
  353. } else {
  354. dprintf( "%s", Buf );
  355. }
  356. }
  357. }
  358. VOID dprint_addr_list( ULONG_PTR FirstAddress, ULONG OffsetToNextPtr )
  359. {
  360. ULONG_PTR Address;
  361. ULONG result;
  362. int index;
  363. Address = FirstAddress;
  364. if ( Address == (ULONG)NULL )
  365. {
  366. dprintf( "%08X (Empty)\n", Address );
  367. return;
  368. }
  369. dprintf( "{ " );
  370. for ( index = 0; Address != (ULONG_PTR)NULL; index ++ )
  371. {
  372. if ( index != 0 )
  373. {
  374. dprintf( ", ");
  375. }
  376. if ( index == 100 )
  377. {
  378. dprintf( "Next list might be corrupted. ");
  379. Address = (ULONG_PTR)NULL;
  380. }
  381. dprintf( "%08X", Address );
  382. if ( !ReadMemory( Address + OffsetToNextPtr,
  383. &Address,
  384. sizeof( Address ),
  385. &result ))
  386. {
  387. dprintf( "ReadMemory() failed." );
  388. Address = (ULONG_PTR)NULL;
  389. }
  390. }
  391. dprintf( " }\n" );
  392. }