50 lines
964 B
C
50 lines
964 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int dumpgroup = 0; // To know where newline should be
|
|
int hexnum = 1; // To put space after every second hex number
|
|
|
|
int chardump(char *data, int end_of_line /* to display only 16 chars */) {
|
|
for (int i=0; i < end_of_line; i++) {
|
|
if (data[i] == "\0")
|
|
printf(".");
|
|
else
|
|
printf("%c", data[i]);
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
}
|
|
|
|
|
|
int hexdump(char *data) {
|
|
//printf("%s\n", data); // FIXME
|
|
for (int i=0; i < strlen(data); i++) {
|
|
hexnum++;
|
|
if (data[i] == '\0')
|
|
printf("00");
|
|
else
|
|
printf("%02x", data[i]);
|
|
if (hexnum%2) {
|
|
printf(" ");
|
|
dumpgroup++;
|
|
}
|
|
if (dumpgroup == 8) {
|
|
dumpgroup = 0;
|
|
printf(" ");
|
|
chardump(data, i);
|
|
//printf("\n");
|
|
}
|
|
}
|
|
//printf("\n"); // FIXME
|
|
}
|
|
|
|
int main() {
|
|
FILE *infile = fopen("../tests/test.bin", "r");//fopen("test.bin", "r");
|
|
char data[50];
|
|
while (fgets(data, 50, infile) != NULL) {
|
|
hexdump(data);
|
|
}
|
|
printf("\n"); // FIXME
|
|
fclose(infile);
|
|
}
|