hexdump.c.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. hexdump.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='hexdecode.c.html' title=' hexdecode.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='hexencode.c.html' title=' hexencode.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * void hexdump (void const * memory, size_t offset, size_t extent, FILE * fp);
  24. *
  25. * memory.h
  26. *
  27. * print memory as a hexadecimal dump showing relative offsets and
  28. * an ASCII character display; this function is similar to but not
  29. * the same as function hexview;
  30. *
  31. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  32. * Copyright (c) 2001-2006 by Charles Maier Associates;
  33. * Licensed under the Internet Software Consortium License;
  34. *
  35. *--------------------------------------------------------------------*/
  36. #ifndef HEXDUMP_SOURCE
  37. #define HEXDUMP_SOURCE
  38. #include &lt;stdio.h&gt;
  39. #include &lt;ctype.h&gt;
  40. #include &lt;stdint.h&gt;
  41. #include &quot;../tools/memory.h&quot;
  42. #include &quot;../tools/number.h&quot;
  43. void hexdump (void const * memory, size_t offset, size_t extent, FILE * fp)
  44. {
  45. byte * origin = (byte *)(memory);
  46. unsigned block = 0x10;
  47. size_t lower = block * (offset / block);
  48. size_t upper = block + lower;
  49. size_t index = 0;
  50. char buffer [ADDRSIZE + 72];
  51. char * output;
  52. while (lower &lt; extent)
  53. {
  54. output = buffer + ADDRSIZE;
  55. for (index = lower; output-- &gt; buffer; index &gt;&gt;= 4)
  56. {
  57. *output = DIGITS_HEX [index &amp; 0x0F];
  58. }
  59. output = buffer + ADDRSIZE;
  60. for (index = lower; index &lt; upper; index++)
  61. {
  62. *output++ = ' ';
  63. if (index &lt; offset)
  64. {
  65. *output++ = ' ';
  66. *output++ = ' ';
  67. }
  68. else if (index &lt; extent)
  69. {
  70. *output++ = DIGITS_HEX [(origin [index] &gt;&gt; 4) &amp; 0x0F];
  71. *output++ = DIGITS_HEX [(origin [index] &gt;&gt; 0) &amp; 0x0F];
  72. }
  73. else
  74. {
  75. *output++ = ' ';
  76. *output++ = ' ';
  77. }
  78. }
  79. *output++ = ' ';
  80. for (index = lower; index &lt; upper; index++)
  81. {
  82. if (index &lt; offset)
  83. {
  84. *output++ = ' ';
  85. }
  86. else if (index &lt; extent)
  87. {
  88. unsigned c = origin [index];
  89. *output++ = isprint (c)? c: '.';
  90. }
  91. else
  92. {
  93. *output++ = ' ';
  94. }
  95. }
  96. *output++ = '\n';
  97. *output++ = '\0';
  98. fputs (buffer, fp);
  99. lower += block;
  100. upper += block;
  101. }
  102. if (extent)
  103. {
  104. output = buffer;
  105. *output++ = '\n';
  106. *output++ = '\0';
  107. fputs (buffer, fp);
  108. }
  109. fflush (fp);
  110. return;
  111. }
  112. #endif
  113. </pre>
  114. <div class='footerlink'>
  115. [<a href='hexdecode.c.html' title=' hexdecode.c '>PREV</a>]
  116. [<a href='toolkit.html' title=' Index '>HOME</a>]
  117. [<a href='hexencode.c.html' title=' hexencode.c '>NEXT</a>]
  118. </div>
  119. </body>
  120. </html>