0

So I am trying to compare a binary file I make when I compile with gcc to an sample executable that is provided. So I used the command diff and went like this

diff asgn2 sample-asgn2 Binary files asgn2 and sample-asgn2 differ

Is there any way to see how they differ? Instead of it just displaying that differ.

4 Answers 4

1

Do a hex dump of the two binaries using hexdump. Then you can compare the hex dump using your favorite diffing tool, like kdiff3, tkdiff, xxdiff, etc.

Sign up to request clarification or add additional context in comments.

Comments

1

Why don't you try Vbindiff? It probably does what you want:

Visual Binary Diff (VBinDiff) displays files in hexadecimal and ASCII (or EBCDIC). It can also display two files at once, and highlight the differences between them. Unlike diff, it works well with large files (up to 4 GB).

Where to get Vbindiff depends on which operating system you are using. If Ubuntu or another Debian derivative, apt-get install vbindiff.

Comments

0

I'm using Linux,in my case,I need a -q option to just show what you got.

diff -q file1 file2

without -q option it will show which line is differ and display that line.

you may check with man diff to see the right option to use in your UNIX.

7 Comments

yeah. i'm using a linux machine aswell. i had a look at the man, but using it with the -q and without the line, it just shows exactly the same thing.
If I understand correctly, the OP's files are binary files rather than text files. Does diff -q work with those?
@courtney I give another try and find out it is different when compare binary files and text files.using "-a" will force the compare to treat both file as text file but the result is non-human-readable on binary files.
i'm sorry, i'm not quite sure what you mean by op?
they're both binary files, just btw.
|
0

vbindiff only do byte-to-byte comparison. If there is just one byte addition/deletion, it will mark all subsequent bytes changed...

Another approach is to transform the binary files in text files so they can be compared with the text diff algorithm.

colorbindiff.pl is a simple and open-source perl script which uses this method and show a colored side-by-side comparison, like in a text diff. It highlights byte changes/additions/deletions. It's available on GitHub.

colorbindiff output snapshot

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.