14 Commits

Author SHA1 Message Date
Elliott Hughes
495a33e657 xxd: better error message.
`xxd -r` with `-p` format input (rather than the `xxd -r -p` that
you actually need to decode that) doesn't work because the input
isn't in the expected

    <address/offset> : <byte...>

format. "real" xxd silently outputs nothing. toybox complains about
an invalid seek.

This patch outputs a clear error if we don't see the leading
address/offset and either ' ' or ':' as a separator (and tests for
both kinds of input).

Looking at the other use of scanf() in this code and testing against
"real" xxd, the fact that toybox allows `-r -i` to parse input
without commas actually matches (undocumented) xxd behavior, so
I've just added a test for that.

Bug: https://github.com/landley/toybox/issues/452
2023-08-30 15:11:43 -05:00
Elliott Hughes
28e3c38e3c xxd: add -e (little endian).
Useful when trying to read tables of addresses/offsets (in ELF files,
for example).
2023-02-13 03:29:18 -06:00
Rob Landley
1135b848d4 Modernize xxd tests. 2022-09-19 14:49:56 -05:00
Rob Landley
88fb25f017 Make -c 0 disable columns and -g 0 disable groups.
Add a test that circa 1998 xxd doesn't pass, but newer ones should. Skip
on host for now, fix when regularly testing on a distro that passes.
2022-09-19 09:51:53 -05:00
Rob Landley
9bfabc2941 Make xxd pass TEST_HOST, and fix rounding error in xxd spacing that diverged. 2022-06-17 17:23:51 -05:00
Elliott Hughes
c6cb9445e2 xxd -r: don't seek unnecessarily on the output stream.
Also add a dup() to fix a double close() noticed in strace when looking at
the lseek() issue...

Fixes: https://github.com/landley/toybox/issues/338
2022-05-04 02:43:43 -05:00
Rob Landley
92dd794d8e Replace a SKIP_HOST with toyonly. 2020-04-28 17:50:15 -05:00
Rob Landley
7a46d1db95 Chmod +x tests that pass with VERBOSE=fail and -x on tests needing work. 2018-11-20 17:44:43 -06:00
Elliott Hughes
30e23c72a1 Add xxd -o. 2018-03-12 14:18:46 -05:00
Elliott Hughes
215a6af5f8 Add xxd -i (and xxd -ri).
The original xxd doesn't support -r with -i. The original also outputs
"unsigned char name[] = { ... };" for input other than stdin, but that
actually makes it less useful --- many languages support array
initializers, but far fewer support that exact declaration syntax.

Also fix the -c range checking and defaulting: ><= in the argument string
only works for floating point arguments.

Bug: http://b/64711851
2017-12-26 22:28:10 -06:00
Elliott Hughes
ff0e8cb15c Implement xxd -s. 2016-07-05 17:48:17 -05:00
Rob Landley
336c44adca Factor out command name at the start of test name, have runtest.sh print it. 2016-03-02 15:20:04 -06:00
Elliott Hughes
577b7cabd4 Add xxd -p and -r.
SELinux denials include hex-encoded paths in the log messages; xxd -r -p is
a convenient way to decode them.

The heuristics are a little weird to my mind, but match the documentation
and observed behavior.
2016-02-19 11:54:06 -06:00
Rob Landley
4ab24f2228 The android guys sent in xxd. It doesn't share code with od and hexdump. Hmmm... 2015-07-02 11:44:01 -05:00