Bram, As described below, xxd doesn't correctly convert free-form hex dumps to their original form. Attached patch, from Jean-Baptiste Wons, fixes the issue.
On Wed, Jan 27, 2010 at 12:15:11AM +0300, Nikolai Kondrashov wrote: > The attached input file (logitech_precision_gamepad_hidrd.txt) is > interpreted by xxd -r -p incorrectly. In effect, not according to manual, > which states: > > Use the combination -r -p to read plain hexadecimal dumps without line > number information and without a particular column layout. Additional > Whitespace and line-breaks are allowed anywhere. > > The following command: > cat logitech_precision_gamepad_hidrd.txt | xxd -r -p | hexdump -C > > results in the following output: > 00000000 05 01 09 04 a1 01 a1 02 75 08 95 02 15 00 26 ff |........u.....&.| > 00000010 25 01 45 01 05 09 19 01 29 0a 81 02 06 00 ff 75 |%.E.....)......u| > 00000020 > > which is incorrect. > > While the following command: > cat logitech_precision_gamepad_hidrd.txt | tr -d ' \n' | xxd -r -p | hexdump > -C > > results in the correct output: > 00000000 05 01 09 04 a1 01 a1 02 75 08 95 02 15 00 26 ff |........u.....&.| > 00000010 00 35 00 46 ff 00 09 30 09 31 81 02 75 01 95 0a |.5.F...0.1..u...| > 00000020 25 01 45 01 05 09 19 01 29 0a 81 02 06 00 ff 75 |%.E.....)......u| > 00000030 01 95 06 25 01 45 01 09 01 81 02 c0 c0 |...%.E.......| > 0000003d -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega <james...@debian.org>
diff -r 8a0a8f10b43e src/xxd/xxd.c --- a/src/xxd/xxd.c Wed Feb 03 18:14:49 2010 +0100 +++ b/src/xxd/xxd.c Sun Feb 07 22:55:15 2010 -0500 @@ -276,11 +276,9 @@ if (c == '\r') /* Doze style input file? */ continue; -#if 0 /* this doesn't work when there is normal text after the hex codes in - the last line that looks like hex */ - if (c == ' ' || c == '\n' || c == '\t') /* allow multiple spaces */ + /* ignore whitespaces */ + if ((hextype == HEX_POSTSCRIPT) && (c == ' ' || c == '\n' || c == '\t')) continue; -#endif n3 = n2; n2 = n1;
05 01 09 04 A1 01 A1 02 75 08 95 02 15 00 26 FF 00 35 00 46 FF 00 09 30 09 31 81 02 75 01 95 0A 25 01 45 01 05 09 19 01 29 0A 81 02 06 00 FF 75 01 95 06 25 01 45 01 09 01 81 02 C0 C0
signature.asc
Description: Digital signature