forked from pvpgn/d2gs109
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexdump.c
51 lines (40 loc) · 1.4 KB
/
hexdump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include "hexdump.h"
FILE *hexstrm = NULL;
extern void hexdump(void const * data, unsigned int len)
{
unsigned int i;
unsigned int r,c;
if (!hexstrm)
return;
if (!data)
return;
for (r=0,i=0; r<(len/16+(len%16!=0)); r++,i+=16)
{
fprintf(hexstrm,"%04X: ",i); /* location of first byte in line */
for (c=i; c<i+8; c++) /* left half of hex dump */
if (c<len)
fprintf(hexstrm,"%02X ",((unsigned char const *)data)[c]);
else
fprintf(hexstrm," "); /* pad if short line */
fprintf(hexstrm," ");
for (c=i+8; c<i+16; c++) /* right half of hex dump */
if (c<len)
fprintf(hexstrm,"%02X ",((unsigned char const *)data)[c]);
else
fprintf(hexstrm," "); /* pad if short line */
fprintf(hexstrm," ");
for (c=i; c<i+16; c++) /* ASCII dump */
if (c<len)
if (((unsigned char const *)data)[c]>=32 &&
((unsigned char const *)data)[c]<127)
fprintf(hexstrm,"%c",((char const *)data)[c]);
else
fprintf(hexstrm,"."); /* put this for non-printables */
else
fprintf(hexstrm," "); /* pad if short line */
fprintf(hexstrm,"\n");
}
fflush(hexstrm);
}