-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbxxd.c
79 lines (71 loc) · 1.92 KB
/
bxxd.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* bxxd - A binary hexdump tool. */
#include "blib.h"
// Parameters:
// -C canonical / coreutils hexdump
// -X xxd / vim xxd format
// -F Fancy mode, colorized
// -f Fancy mode, no color.
void help(char* name) {
printf("%s bxxd\n", PACKAGE_STRING);
printf("(C) 2015 Jon Feldman (@chaoskagami) <%s>\n", PACKAGE_BUGREPORT);
printf("Usage:\n");
printf(" %s [args] file ...\n", name);
printf("Options:\n");
printf(" -C Canonical / 'hexdump -C' emulation (color)\n");
printf(" -c Canonical / 'hexdump -C' emulation\n");
printf(" -X vim 'xxd' emulation (color)\n");
printf(" -x vim 'xxd' emulation\n");
printf(" -F Fancy (color)\n");
printf(" -f Fancy\n");
printf("Report bugs to <%s>\n", PACKAGE_URL);
printf("This software is licensed under the MIT license.\n");
}
int main(int argc, char* argv[]) {
int ret;
uint64_t offset = 0;
int mode = SPACED_BYTES;
int opt;
while ( (opt = getopt(argc, argv, "hCcXxFf")) != -1) {
switch(opt) {
case 'h':
help(argv[0]);
return 0;
break;
case 'C':
mode = PRESET_HEXDUMP_C | COLORIZED;
break;
case 'c':
mode = PRESET_HEXDUMP_C;
break;
case 'X':
mode = PRESET_XXD | COLORIZED;
break;
case 'x':
mode = PRESET_XXD;
break;
case 'F':
mode = PRESET_FANCY | COLORIZED;
break;
case 'f':
mode = PRESET_FANCY;
break;
case '?':
fprintf(stderr, "error: unknown option. Run with -h for more info\n");
return 1;
default:
fprintf(stderr, "error: unknown option. Run with -h for more info\n");
return 1;
}
}
if (optind == argc) {
fprintf(stderr, "error: requires a file argument. Run with -h for more info\n");
return 1;
}
for (int index = optind; index < argc; index++) {
// File argument. Hexdump it.
ret = map_file(argv[index], READ_FILE);
ret = hexdump_file(0, blib_stat.st_size, mode);
ret = unmap_file();
}
return 0;
}