The hexdump command converts any file to hex values.
But what if I have hex values and I want to reverse the process, is this possible?
I've written a short AWK script which reverses hexdump -C
output back to the
original data. Use like this:
reverse-hexdump.sh hex.txt > data
Handles '*' repeat markers and generating original data even if binary.
hexdump -C
and reverse-hexdump.sh
make a data round-trip pair. It is
available here:
There is a similar tool called xxd
. If you run xxd
with just a file name it dumps the data in a fairly standard hex dump format:
# xxd bdata
0000000: 0001 0203 0405
......
Now if you pipe the output back to xxd
with the -r
option and redirect that to a new file, you can convert the hex dump back to binary:
# xxd bdata | xxd -r >bdata2
# cmp bdata bdata2
# xxd bdata2
0000000: 0001 0203 0405
If you have only a hexdump generated with hexdump
you can use the following command
sed -E 's/ /: /;s/ (..)(..)/ \2\1/g;$d' dump | xxd -r
The sed
part converts hexdump
's format into xxd
's format, at least so far that xxd -r
works.
Known Bugs (see comment section)
hexdump
ed using a *
.There is a tonne of more elegant ways to get this done, but I've quickly hacked something together that Works for Me (tm) when regenerating a binary file from a hex dump generated by hexdump -C some_file.bin
:
sed 's/\(.\{8\}\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\)/\1: \2\3 \4\5 \6\7 \8\9/g' some_file.hexdump | sed 's/\(.*\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\) \(..\) |/\1 \2\3 \4\5 \6\7 \8\9 /g' | sed 's/.$//g' | xxd -r > some_file.restored
Basically, uses 2 sed
processeses, each handling it's part of each line. Ugly, but someone might find it useful.