diff --git a/src/hex.c b/src/hex.c index 6b10293..4981083 100644 --- a/src/hex.c +++ b/src/hex.c @@ -21,6 +21,8 @@ void init_flags(struct flags* flags) flags->littleendian = false; + flags->reverse_op = false; + flags->octets = 2; flags->customoctets = false; diff --git a/src/include/hex.h b/src/include/hex.h index d716928..3a5536c 100644 --- a/src/include/hex.h +++ b/src/include/hex.h @@ -29,6 +29,8 @@ struct flags { bool littleendian; + bool reverse_op; + uint offset; int seek; diff --git a/src/main.c b/src/main.c index b3944a9..cffabcb 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ static struct argp_option options[] = { {0, 'o', "off", 0, "add to the displayed file position.", 0}, {0, 'e', 0, 0, "little-endian dump (incompatible with -ps,-i,-r).", 0}, {0, 's', "seek", 0, "start at <[+][-] seek> bytes abs. infile offset.", 0}, + {0, 'r', 0, 0, "reverse operation: convert (or patch) hexdump into binary.", 0}, {0} }; @@ -65,6 +66,9 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state) else flags->coloured = true; break; + case 'r': + flags->reverse_op = true; + flags->coloured = false; case 'l': flags->len = atoi(arg); break; @@ -126,11 +130,11 @@ static void do_text_parse(hex_chunk_t** lines, bool interactive) } if (flags.seek >= 0) { - if (flags.seek > strlen(file_content)) + if (flags.seek > (int) strlen(file_content)) exit(EXIT_SUCCESS); seek = flags.seek; } else { - if ((flags.seek * -1) > strlen(file_content)) { + if ((flags.seek * -1) > (int) strlen(file_content)) { fprintf(stderr, "xxd: Sorry, cannot seek.\n"); exit(EXIT_FAILURE); }