Initial commit: add very simple hexdump
This commit is contained in:
commit
d5fb5de386
|
@ -0,0 +1 @@
|
||||||
|
*~
|
|
@ -0,0 +1,3 @@
|
||||||
|
#+TITLE: hexutils - hexdump, xxd
|
||||||
|
|
||||||
|
Simple tools to work with binary files and display them in ascii, hex or binary and make hexdumps
|
|
@ -0,0 +1,11 @@
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS= -Wall -Wextra
|
||||||
|
LFLAGS=
|
||||||
|
|
||||||
|
all: hexdump
|
||||||
|
|
||||||
|
main: $(OBJFILES)
|
||||||
|
$(CC) hexdump.c -o hexdump
|
||||||
|
|
||||||
|
test: main
|
||||||
|
./hexdump
|
|
@ -0,0 +1,49 @@
|
||||||
|
#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);
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue