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.

240 lines
5.0 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. #include "rxovride.h" //common compile flags
  21. #include "ntifs.h"
  22. #include <nt.h>
  23. //#include <ntrtl.h>
  24. #include "ntverp.h"
  25. #define KDEXTMODE
  26. #include <windef.h>
  27. #define NOEXTAPI
  28. #include <wdbgexts.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32. #include <kdextlib.h>
  33. #include <ntrxdef.h>
  34. #include <rxtypes.h>
  35. #include <rxlog.h>
  36. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  37. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  38. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  39. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadMemoryRoutine;
  40. #define PRINTF lpOutputRoutine
  41. #define ERROR lpOutputRoutine
  42. #define NL 1
  43. #define NONL 0
  44. #define SETCALLBACKS() \
  45. lpOutputRoutine = lpExtensionApis->lpOutputRoutine; \
  46. lpGetExpressionRoutine = lpExtensionApis->lpGetExpressionRoutine; \
  47. lpGetSymbolRoutine = lpExtensionApis->lpGetSymbolRoutine; \
  48. lpReadMemoryRoutine = lpExtensionApis->lpReadVirtualMemRoutine;
  49. #define DEFAULT_UNICODE_DATA_LENGTH 512
  50. USHORT s_UnicodeStringDataLength = DEFAULT_UNICODE_DATA_LENGTH;
  51. WCHAR s_UnicodeStringData[DEFAULT_UNICODE_DATA_LENGTH];
  52. WCHAR *s_pUnicodeStringData = s_UnicodeStringData;
  53. #define DEFAULT_ANSI_DATA_LENGTH 512
  54. USHORT s_AnsiStringDataLength = DEFAULT_ANSI_DATA_LENGTH;
  55. CHAR s_AnsiStringData[DEFAULT_ANSI_DATA_LENGTH];
  56. CHAR *s_pAnsiStringData = s_AnsiStringData;
  57. /*
  58. * Fetches the data at the given address
  59. */
  60. BOOLEAN
  61. GetData( ULONG_PTR dwAddress, PVOID ptr, ULONG size, PSZ type)
  62. {
  63. BOOL b;
  64. ULONG BytesRead;
  65. b = (lpReadMemoryRoutine)(dwAddress, ptr, size, &BytesRead );
  66. if (!b || BytesRead != size ) {
  67. PRINTF( "Unable to read %u bytes at %p, for %s\n", size, dwAddress, type );
  68. return FALSE;
  69. }
  70. return TRUE;
  71. }
  72. /*
  73. * Fetch the null terminated ASCII string at dwAddress into buf
  74. */
  75. BOOL
  76. GetString( ULONG_PTR dwAddress, PSZ buf )
  77. {
  78. do {
  79. if( !GetData( dwAddress,buf, 1, "..stringfetch") )
  80. return FALSE;
  81. dwAddress++;
  82. buf++;
  83. } while( *buf != '\0' );
  84. return TRUE;
  85. }
  86. /*
  87. * Displays a byte in hexadecimal
  88. */
  89. VOID
  90. PrintHexChar( UCHAR c )
  91. {
  92. PRINTF( "%c%c", "0123456789abcdef"[ (c>>4)&0xf ], "0123456789abcdef"[ c&0xf ] );
  93. }
  94. /*
  95. * Displays a buffer of data in hexadecimal
  96. */
  97. VOID
  98. PrintHexBuf( PUCHAR buf, ULONG cbuf )
  99. {
  100. while( cbuf-- ) {
  101. PrintHexChar( *buf++ );
  102. PRINTF( " " );
  103. }
  104. }
  105. /*
  106. * Displays a unicode string
  107. */
  108. BOOL
  109. PrintStringW(LPSTR msg, PUNICODE_STRING puStr, BOOL nl )
  110. {
  111. UNICODE_STRING UnicodeString;
  112. ANSI_STRING AnsiString;
  113. BOOL b;
  114. if( msg )
  115. PRINTF( msg );
  116. if( puStr->Length == 0 ) {
  117. if( nl )
  118. PRINTF( "\n" );
  119. return TRUE;
  120. }
  121. UnicodeString.Buffer = s_pUnicodeStringData;
  122. UnicodeString.MaximumLength = s_UnicodeStringDataLength;
  123. UnicodeString.Length = (puStr->Length > s_UnicodeStringDataLength)
  124. ? s_UnicodeStringDataLength
  125. : puStr->Length;
  126. b = (lpReadMemoryRoutine)(
  127. (ULONG_PTR) puStr->Buffer,
  128. UnicodeString.Buffer,
  129. UnicodeString.Length,
  130. NULL);
  131. if (b) {
  132. RtlUnicodeStringToAnsiString(&AnsiString, puStr, TRUE);
  133. PRINTF("%s%s", AnsiString.Buffer, nl ? "\n" : "" );
  134. RtlFreeAnsiString(&AnsiString);
  135. }
  136. return b;
  137. }
  138. /*
  139. * Displays a ANSI string
  140. */
  141. BOOL
  142. PrintStringA(LPSTR msg, PANSI_STRING pStr, BOOL nl )
  143. {
  144. ANSI_STRING AnsiString;
  145. BOOL b;
  146. if( msg )
  147. PRINTF( msg );
  148. if( pStr->Length == 0 ) {
  149. if( nl )
  150. PRINTF( "\n" );
  151. return TRUE;
  152. }
  153. AnsiString.Buffer = s_pAnsiStringData;
  154. AnsiString.MaximumLength = s_AnsiStringDataLength;
  155. AnsiString.Length = (pStr->Length > (s_AnsiStringDataLength - 1))
  156. ? (s_AnsiStringDataLength - 1)
  157. : pStr->Length;
  158. b = (lpReadMemoryRoutine)(
  159. (ULONG_PTR) pStr->Buffer,
  160. AnsiString.Buffer,
  161. AnsiString.Length,
  162. NULL);
  163. if (b) {
  164. AnsiString.Buffer[ AnsiString.Length ] = '\0';
  165. PRINTF("%s%s", AnsiString.Buffer, nl ? "\n" : "" );
  166. }
  167. return b;
  168. }