Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was searching for how to do a reverse hexdump and found xxd mentioned. However, it does not seem to work with simply:

xxd -r hexdumpfile > binaryfile

I then compared the difference between outputs of xxd infile and hexdump infile, and found three differences:

  1. xxd output has a colon after the address
  2. xxd output has the positions in the data reversed (for example, 5a42 in hexdump output becomes 425a in xxd output)
  3. There are some extra characters after each line

I only have the hexdumped version of certain files on a server. How can I correctly get back the binary data using xxd?

share|improve this question
    
Was looking for some option in xxd to take in hexdump format, but for now, managed to do it with some simple sed operations –  tanon Jul 26 '11 at 5:40
    
I haven't really tested precisely what you ask, but try xxd -p and -b, -p is plain -b is binary, as well as your -r. As to byte order, that'd to do with big endian and little endian, and maybe xxd can't reverse that.. but it's related to how the bytes are stored in the file.Like, if you have a text file in notepad, you can save it as unicode 16-bit big endian, or little endian or UTF-8 or whatever, and you see the difference from xxd. The od command might display it differently. –  barlop Jul 26 '11 at 6:28

1 Answer 1

There's no one command that I know of that will do the conversion, but it can easily be broken up into a few steps:

  1. Strip addresses from hexdump output using sed
  2. Convert into binary using xxd
  3. Endian conversion (for example, 5a42 becomes 425a) using dd

Here's the full command:

sed 's/^[0-9]*//' hexdump | xxd -r -p | dd conv=swab of=binaryfile
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.