some small fixes, and begining of reverse

This commit is contained in:
Nathan Singer 2025-02-18 13:30:55 -05:00
parent ec3a1d44d4
commit 1eda825308
3 changed files with 10 additions and 2 deletions

View File

@ -21,6 +21,8 @@ void init_flags(struct flags* flags)
flags->littleendian = false;
flags->reverse_op = false;
flags->octets = 2;
flags->customoctets = false;

View File

@ -29,6 +29,8 @@ struct flags {
bool littleendian;
bool reverse_op;
uint offset;
int seek;

View File

@ -25,6 +25,7 @@ static struct argp_option options[] = {
{0, 'o', "off", 0, "add <off> 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);
}