How to compare binary files ? any preferences?

At the office, I want to compare the difference between two custom binary files (which should be very very similar) as part of a verification of the files.

I’m curious as to how much I can do using a binary editor.

I used a program on my Linux desktop called ‘bvi’ to view binary files (although its a binary editor, which in some ways is as painful to use as the Unix/Linux ‘vi’ editor :slight_smile: … ). Still, its pretty neat.

I can also compare the files with ‘diff file1 file2’ which gives a confusing (to me) output. If I redirect the output to another binary file, I can also compare the files with ‘diff file1 file2 > file-difference.bin’ and then open up file-difference.bin with bvi and its a bit better, but I still find that rather obscure.

Also of interest is the Linux/Unix command ‘cmp’ … ie for example: cmp -b file1 file2

Also of interest is using the Linux program ‘dhex’ to compare a couple of the binary files. ie: dhex file1 file2 #I rather like dhex.

Anyone else have any other recommended tools for this ?

Part of the complexity is the file contents is defined more in binary than in hex, and thus a hex presentation is in some cases not as useful as a binary presentation! :slight_smile: … but in other parts of the file, a hex (or even decimal) presentation is more useful.

oldcpu wrote:
> Anyone else have any other recommended tools for this ?

might take a look at BeeDiff, it is a GUI that can load one file in
the left side and another in the right and it highlights the
differences between the two, line by line…

true the presentation is sometimes confusing…but usually that is
because the two files may be SO different…

http://freshmeat.net/projects/beediff

hmmmmm…now i see it says “User have the possibility to work with two
text files” and in fact i’ve never used it for anything other than
text…so…so, maybe it is of no use to you…but, you could give it
look…i’ve run it for a long time with no problems…


DenverD (Linux Counter 282315)
CAVEAT: http://is.gd/bpoMD
via NNTP w/TBird 2.0.0.23 | KDE 3.5.7 | openSUSE 10.3
2.6.22.19-0.4-default SMP i686
AMD Athlon 1 GB RAM | GeForce FX 5500 | ASRock K8Upgrade-760GX |
CMedia 9761 AC’97 Audio

In fact, that is what dhex does, but its a terminal program.

I think you are correct that beediff is for text files. I tried loading a couple of different (but almost the same) binary files into it, and beediff came back and incorrectly reported both files were the same.

oldcpu wrote:
> beediff came back and incorrectly reported both files were the same.

sorry…then the best i know is diff, with its warts…


DenverD (Linux Counter 282315)
CAVEAT: http://is.gd/bpoMD
via NNTP w/TBird 2.0.0.23 | KDE 3.5.7 | openSUSE 10.3
2.6.22.19-0.4-default SMP i686
AMD Athlon 1 GB RAM | GeForce FX 5500 | ASRock K8Upgrade-760GX |
CMedia 9761 AC’97 Audio

In addition to dhex, I also found vbindiff, I could not find an openSUSE rpm for it, and I failed to compile it myself, so I used ‘alien’ to convert the .deb I found here for debian squeeze to an rpm which installed ok. But IMHO vbindiff is no better than dhex IMHO.

This image gives a good idea as to the appearance of dhex :

Hi
Xdelta? http://xdelta.org/


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.13-0.4-default
up 1 day 20:57, 2 users, load average: 0.11, 0.08, 0.02
GPU GeForce 8600 GTS Silent - Driver Version: 256.35

Thanks. I installed and tried it, but found the output confusing … After installation I used:

xdelta delta file1.bin file2.bin differences.bin

but when I opened differences.bin (with bvi) I found the content confusing.

Thus far I am still leaning toward dhex, although after tuning the terminal a bit I managed to improve the output of vbindiff to match that of dhex.

@Oldcpu: When you don’t want the display in HEX you could try this:

#!/bin/bash
#
# bincmp: The vodoo (TM) special binary file comparer
# Compare two binary files. Arguments: <file-1> <file-2>
#
TMPDIR="/tmp"
MYPID="$$"
TMPFILEA="$TMPDIR/bincmp-$MYPID-1.dump"
TMPFILEB="$TMPDIR/bincmp-$MYPID-2.dump"
hexdump -c $1 | sed -e "s/^[0-9a-f]*//" \
        -e "s/^\\(................................\\)\\(.*\\)/\\1\\
\\2/" > $TMPFILEA
hexdump -c $2 | sed -e "s/^[0-9a-f]*//" \
        -e "s/^\\(................................\\)\\(.*\\)/\\1\\
\\2/" > $TMPFILEB
diff -a -y -W 76 $TMPFILEA $TMPFILEB | less
rm -f $TMPFILEA $TMPFILEB
exit 0

Use any other program instead of diff to meet your preferences.

Thanks for the suggestion. I’m found bvi and dhex worked quite well and I used them today at the office to verify the binary output of a program, where it is important we don’t make mistakes.

I’m currently wishing I had a quick way of taking the hex that dhex produces from the binary and put it in a text file, but I’ve run out of time (for now) to search. Unfortunately its not a simple matter of redirecting the output. (I probably need to learn xxd or something like that)

On Wed, 07 Jul 2010 18:16:01 GMT, oldcpu
<oldcpu@no-mx.forums.opensuse.org> wrote:

>
>At the office, I want to compare the difference between two custom
>binary files (which should be very very similar) as part of a
>verification of the files.
>
>I’m curious as to how much I can do using a binary editor.
>
>I used a program on my Linux desktop called ‘bvi’ to view binary files
>(although its a binary editor, which in some ways is as painful to use
>as the Unix/Linux ‘vi’ editor :slight_smile: … ). Still, its pretty neat.
>
>I can also compare the files with ‘diff file1 file2’ which gives a
>confusing (to me) output. If I redirect the output to another binary
>file, I can also compare the files with ‘diff file1 file2 >
>file-difference.bin’ and then open up file-difference.bin with bvi and
>its a bit better, but I still find that rather obscure.
>
>Also of interest is the Linux/Unix command ‘cmp’ … ie for example:
>cmp -b file1 file2
>
>Also of interest is using the Linux program ‘dhex’ to compare a couple
>of the binary files. ie: dhex file1 file2 #I rather like dhex.
>
>Anyone else have any other recommended tools for this ?
>
>Part of the complexity is the file contents is defined more in binary
>than in hex, and thus a hex presentation is in some cases not as useful
>as a binary presentation! :slight_smile: … but in other parts of the file, a hex
>(or even decimal) presentation is more useful.

I don’t quite know what to say. Binary, octal and hexadecimal are all
pretty much the same to me, too many years pounding bits direct using
all those representations i guess.

Indeed it is an area that if one only touches upon it very very occasionally in the past, its a lot more difficult to come back, than if one spent years working with binary.

I ended up using ‘dhex’ and ‘bvi’ together. If looking at ONLY 1 file, then I use ‘bvi’. But if comparing 2 binary files, I prefer ‘dhex’.