bashxxdod

Why does xxd add chars?


I am trying to reverse an od command from a system where I have no hexdump or base64 tools.

I do this like that (of course, in reality, the encoding takes place at the "small" system, the decoding is done on my workstation, but to test it, I try the whole way in one line first):

echo TEST | od -tx1 | xxd -r

Of course, echo TEST is just a placeholder here for eg. cat test.bmp or anything else.

> echo TEST
TEST

> echo TEST | od -tx1
0000000 54 45 53 54 0a
0000005 

> echo TEST | od -tx1 | xxd -r
TEST

That looks right, but it is different, as we can see here if we give it to od again:

> echo TEST | od -tx1 | xxd -r | od -tx1
0000000 54 45 53 54 0a 00 00 00
0000010 

Why does xxd -r add those 00s?


Solution

  • It seems to work if I remove the offsets at all:

    > echo TEST | od -tx1 -An
     54 45 53 54 0a
    > echo TEST | od -tx1 -An | xxd -r -p
    TEST
    > echo TEST | od -tx1 -An | xxd -r -p | od -tx1 -An
     54 45 53 54 0a
    

    Bingo! Note the extra " " in front of the bytes. It seems to have no effect.