hexdump: fix: add hexdump.c and delete binary
This commit is contained in:
parent
9b7fed8877
commit
af7ac2654c
BIN
src/hexdump
BIN
src/hexdump
Binary file not shown.
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -8,12 +9,14 @@ int hexnum = 1; // To put space after every second hex number
|
|||
bool canonical = true; // -C flag
|
||||
|
||||
int chardump(char *data, int start_of_line, int end_of_line /* to display only 16 chars */) {
|
||||
for (int i=0; i < end_of_line; i++) {
|
||||
if (data[i] == "\0" || data[i] == ' ')
|
||||
printf("|");
|
||||
for (int i=start_of_line; i < end_of_line+1; i++) {
|
||||
if (isprint(data[i]) == 0 || data[i] == '\n' || data[i] == '\0')
|
||||
printf(".");
|
||||
else
|
||||
printf("%c", data[i]);
|
||||
}
|
||||
printf("|\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -22,7 +25,6 @@ int hexdump(char *data) {
|
|||
//printf("%s\n", data); // FIXME
|
||||
int cur_start_of_line = 0;
|
||||
for (int i=0; i < strlen(data); i++) {
|
||||
hexnum++;
|
||||
if (data[i] == '\0')
|
||||
printf("00");
|
||||
else {
|
||||
|
@ -30,9 +32,10 @@ int hexdump(char *data) {
|
|||
printf("%02x", data[i]);
|
||||
else {
|
||||
printf("%02x ", data[i]);
|
||||
//dumpgroup++;
|
||||
}
|
||||
}
|
||||
|
||||
hexnum++;
|
||||
if (hexnum%2 && hexnum >= 2) {
|
||||
if (!canonical)
|
||||
printf(" ");
|
||||
|
@ -47,22 +50,25 @@ int hexdump(char *data) {
|
|||
}
|
||||
if (dumpgroup == 2) {
|
||||
dumpgroup = 0;
|
||||
// printf("|");
|
||||
// chardump(data, cur_start_of_line, hexnum);
|
||||
// printf("|");
|
||||
// cur_start_of_line = i;
|
||||
printf("\n");
|
||||
cur_start_of_line = 0;
|
||||
chardump(data, cur_start_of_line, i);
|
||||
hexnum = 0;
|
||||
cur_start_of_line = i;
|
||||
}
|
||||
}
|
||||
//printf("\n"); // FIXME
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *infile = fopen("../tests/test2.bin", "r");//fopen("test.bin", "r");
|
||||
char data[50];
|
||||
while (fgets(data, 50, infile) != NULL) {
|
||||
hexdump(data);
|
||||
}
|
||||
char data[10000]; // FIXME
|
||||
char ch;
|
||||
int byte = 0; // FIXME
|
||||
while ((ch = fgetc(infile)) != EOF)
|
||||
{
|
||||
data[byte] = ch;
|
||||
byte++;
|
||||
}
|
||||
hexdump(data);
|
||||
printf("\n"); // FIXME
|
||||
fclose(infile);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue