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.

246 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. ------------------------------
  4. T H I S F I L E I S O B S O L E T E . I T I S B E I N G K E P T
  5. F O R A W H I L E J U S T T O M A K E S U R E
  6. ----------------------------
  7. Module Name:
  8. kdextlib.c
  9. Abstract:
  10. Library routines for dumping data structures given a meta level descrioption
  11. Author:
  12. Balan Sethu Raman (SethuR) 11-May-1994
  13. Notes:
  14. The implementation tends to avoid memory allocation and deallocation as much as possible.
  15. Therefore We have choosen an arbitrary length as the default buffer size. A mechanism will
  16. be provided to modify this buffer length through the debugger extension commands.
  17. Revision History:
  18. 11-Nov-1994 SethuR Created
  19. --*/
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include "rxovride.h" //common compile flags
  24. #include "ntifs.h"
  25. #include <nt.h>
  26. //#include <ntrtl.h>
  27. #include "ntverp.h"
  28. #ifdef __cplusplus
  29. }
  30. #endif
  31. #define KDEXTMODE
  32. #include <windef.h>
  33. #define NOEXTAPI
  34. #include <wdbgexts.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <stdio.h>
  38. #include <kdextlib.h>
  39. #include <ntrxdef.h>
  40. #include <rxtypes.h>
  41. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  42. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  43. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  44. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadMemoryRoutine;
  45. #define PRINTF lpOutputRoutine
  46. #define ERROR lpOutputRoutine
  47. #define NL 1
  48. #define NONL 0
  49. #define SETCALLBACKS() \
  50. lpOutputRoutine = lpExtensionApis->lpOutputRoutine; \
  51. lpGetExpressionRoutine = lpExtensionApis->lpGetExpressionRoutine; \
  52. lpGetSymbolRoutine = lpExtensionApis->lpGetSymbolRoutine; \
  53. lpReadMemoryRoutine = lpExtensionApis->lpReadVirtualMemRoutine;
  54. #define DEFAULT_UNICODE_DATA_LENGTH 512
  55. USHORT s_UnicodeStringDataLength = DEFAULT_UNICODE_DATA_LENGTH;
  56. WCHAR s_UnicodeStringData[DEFAULT_UNICODE_DATA_LENGTH];
  57. WCHAR *s_pUnicodeStringData = s_UnicodeStringData;
  58. #define DEFAULT_ANSI_DATA_LENGTH 512
  59. USHORT s_AnsiStringDataLength = DEFAULT_ANSI_DATA_LENGTH;
  60. CHAR s_AnsiStringData[DEFAULT_ANSI_DATA_LENGTH];
  61. CHAR *s_pAnsiStringData = s_AnsiStringData;
  62. /*
  63. * Fetches the data at the given address
  64. */
  65. BOOLEAN
  66. GetData( ULONG_PTR dwAddress, PVOID ptr, ULONG size, PSZ type)
  67. {
  68. BOOL b;
  69. ULONG BytesRead;
  70. b = (lpReadMemoryRoutine)(dwAddress, ptr, size, &BytesRead );
  71. if (!b || BytesRead != size ) {
  72. PRINTF( "Unable to read %u bytes at %p, for %s\n", size, dwAddress, type );
  73. return FALSE;
  74. }
  75. return TRUE;
  76. }
  77. /*
  78. * Fetch the null terminated ASCII string at dwAddress into buf
  79. */
  80. BOOL
  81. GetString( ULONG_PTR dwAddress, PSZ buf )
  82. {
  83. do {
  84. if( !GetData( dwAddress,buf, 1, "..stringfetch") )
  85. return FALSE;
  86. dwAddress++;
  87. buf++;
  88. } while( *buf != '\0' );
  89. return TRUE;
  90. }
  91. /*
  92. * Displays a byte in hexadecimal
  93. */
  94. VOID
  95. PrintHexChar( UCHAR c )
  96. {
  97. PRINTF( "%c%c", "0123456789abcdef"[ (c>>4)&0xf ], "0123456789abcdef"[ c&0xf ] );
  98. }
  99. /*
  100. * Displays a buffer of data in hexadecimal
  101. */
  102. VOID
  103. PrintHexBuf( PUCHAR buf, ULONG cbuf )
  104. {
  105. while( cbuf-- ) {
  106. PrintHexChar( *buf++ );
  107. PRINTF( " " );
  108. }
  109. }
  110. /*
  111. * Displays a unicode string
  112. */
  113. BOOL
  114. PrintStringW(LPSTR msg, PUNICODE_STRING puStr, BOOL nl )
  115. {
  116. UNICODE_STRING UnicodeString;
  117. ANSI_STRING AnsiString;
  118. BOOL b;
  119. if( msg )
  120. PRINTF( msg );
  121. if( puStr->Length == 0 ) {
  122. if( nl )
  123. PRINTF( "\n" );
  124. return TRUE;
  125. }
  126. UnicodeString.Buffer = s_pUnicodeStringData;
  127. UnicodeString.MaximumLength = s_UnicodeStringDataLength;
  128. UnicodeString.Length = (puStr->Length > s_UnicodeStringDataLength)
  129. ? s_UnicodeStringDataLength
  130. : puStr->Length;
  131. b = (lpReadMemoryRoutine)(
  132. (ULONG_PTR) puStr->Buffer,
  133. UnicodeString.Buffer,
  134. UnicodeString.Length,
  135. NULL);
  136. if (b) {
  137. RtlUnicodeStringToAnsiString(&AnsiString, puStr, TRUE);
  138. PRINTF("%s%s", AnsiString.Buffer, nl ? "\n" : "" );
  139. RtlFreeAnsiString(&AnsiString);
  140. }
  141. return b;
  142. }
  143. /*
  144. * Displays a ANSI string
  145. */
  146. BOOL
  147. PrintStringA(LPSTR msg, PANSI_STRING pStr, BOOL nl )
  148. {
  149. ANSI_STRING AnsiString;
  150. BOOL b;
  151. if( msg )
  152. PRINTF( msg );
  153. if( pStr->Length == 0 ) {
  154. if( nl )
  155. PRINTF( "\n" );
  156. return TRUE;
  157. }
  158. AnsiString.Buffer = s_pAnsiStringData;
  159. AnsiString.MaximumLength = s_AnsiStringDataLength;
  160. AnsiString.Length = (pStr->Length > (s_AnsiStringDataLength - 1))
  161. ? (s_AnsiStringDataLength - 1)
  162. : pStr->Length;
  163. b = (lpReadMemoryRoutine)(
  164. (ULONG_PTR) pStr->Buffer,
  165. AnsiString.Buffer,
  166. AnsiString.Length,
  167. NULL);
  168. if (b) {
  169. AnsiString.Buffer[ AnsiString.Length ] = '\0';
  170. PRINTF("%s%s", AnsiString.Buffer, nl ? "\n" : "" );
  171. }
  172. return b;
  173. }