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.

132 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. HexDump.c
  5. Abstract:
  6. This module performs debug hex dumps.
  7. Author:
  8. John Rogers (JohnRo) 25-Apr-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 25-Apr-1991 JohnRo
  14. Created procedure version from macro in <netdebug.h>.
  15. 19-May-1991 JohnRo
  16. Make LINT-suggested changes.
  17. 12-Jun-1991 JohnRo
  18. Improved output readability.
  19. --*/
  20. // These must be included first:
  21. #include <windef.h> // IN, LPBYTE, LPVOID, NULL, etc.
  22. // These may be included in any order:
  23. #include <ctype.h> // isprint().
  24. #include <netdebug.h> // My prototype, NetpKdPrint(()).
  25. #if DBG
  26. #ifndef MIN
  27. #define MIN(a,b) ( ( (a) < (b) ) ? (a) : (b) )
  28. #endif
  29. #define DWORDS_PER_LINE 4
  30. #define BYTES_PER_LINE (DWORDS_PER_LINE * sizeof(DWORD))
  31. #define SPACE_BETWEEN_BYTES NetpKdPrint((" "))
  32. #define SPACE_BETWEEN_DWORDS NetpKdPrint((" "))
  33. DBGSTATIC VOID
  34. NetpDbgHexDumpLine(
  35. IN LPBYTE StartAddr,
  36. IN DWORD BytesInThisLine
  37. )
  38. {
  39. LPBYTE BytePtr;
  40. DWORD BytesDone;
  41. DWORD HexPosition;
  42. NetpKdPrint((FORMAT_LPVOID " ", (LPVOID) StartAddr));
  43. BytePtr = StartAddr;
  44. BytesDone = 0;
  45. while (BytesDone < BytesInThisLine) {
  46. NetpKdPrint(("%02X", *BytePtr)); // space for "xx" (see pad below).
  47. SPACE_BETWEEN_BYTES;
  48. ++BytesDone;
  49. if ( (BytesDone % sizeof(DWORD)) == 0) {
  50. SPACE_BETWEEN_DWORDS;
  51. }
  52. ++BytePtr;
  53. }
  54. HexPosition = BytesDone;
  55. while (HexPosition < BYTES_PER_LINE) {
  56. NetpKdPrint((" ")); // space for "xx" (see byte above).
  57. SPACE_BETWEEN_BYTES;
  58. ++HexPosition;
  59. if ( (HexPosition % sizeof(DWORD)) == 0) {
  60. SPACE_BETWEEN_DWORDS;
  61. }
  62. }
  63. BytePtr = StartAddr;
  64. BytesDone = 0;
  65. while (BytesDone < BytesInThisLine) {
  66. if (isprint(*BytePtr)) {
  67. NetpKdPrint(( FORMAT_CHAR, (CHAR) *BytePtr ));
  68. } else {
  69. NetpKdPrint(( "." ));
  70. }
  71. ++BytesDone;
  72. ++BytePtr;
  73. }
  74. NetpKdPrint(("\n"));
  75. } // NetpDbgHexDumpLine
  76. #endif // DBG
  77. // NetpDbgHexDump: do a hex dump of some number of bytes to the debug
  78. // terminal or whatever. This is a no-op in a nondebug build.
  79. #undef NetpDbgHexDump
  80. VOID
  81. NetpDbgHexDump(
  82. IN LPBYTE StartAddr,
  83. IN DWORD Length
  84. )
  85. {
  86. #if DBG
  87. DWORD BytesLeft = Length;
  88. LPBYTE LinePtr = StartAddr;
  89. DWORD LineSize;
  90. while (BytesLeft > 0) {
  91. LineSize = MIN(BytesLeft, BYTES_PER_LINE);
  92. NetpDbgHexDumpLine( LinePtr, LineSize );
  93. BytesLeft -= LineSize;
  94. LinePtr += LineSize;
  95. }
  96. #endif // DBG
  97. } // NetpDbgHexDump