I love xxd tool

For a Java developer I work a lot with serialized binary data. And as someone working on the server side, most of the time I deal with it in various forms of hex strings. Application wants to put binary data to the log - it will use hex. Base64? Ha, that'd be a novel idea...

Sometimes I had to write scripts to unmangle the whatever representation that particular application decided to use. But most of the time just one tool in the shell's pipe is doing all I need.

For example, recently I've been dealing with an application that saves zlib-compressed blobs. Here is a simple pipe that converts it nicely:

echo 785E... | xxd -r -p | zlib-flate -uncompress | xxd

0000000: 0100 0108 ac00 0000 0300 0866 6f72 6d73  ...........forms
0000010: 7065 6300 0000 1466 6965 6c64 5b74 6578  pec....field[tex
0000020: 743b 3b24 7b74 6578 747d 5d00 0869 6e66  t;;${text}]..inf
0000030: 6f74 6578 7400 0000 0b22 4747 4747 4747  otext...."GGGGGG
0000040: 4747 4722 0004 7465 7874 0000 0009 4747  GGG"..text....GG
0000050: 4747 4747 4747 4745 6e64 496e 7665 6e74  GGGGGGGEndInvent
0000060: 6f72 790a                                ory.

It is insanely simple, and yet I have not seen many people doing it. An average colleague of mine has a Groovy script or a full Java application to do that. I find using existing tools much more rewarding.

Posted On

Category:

Tags: /