9

I have 3 binary files. Let's call them file1.bin, file2.bin and file3.bin.

  • file1.bin and file2.bin have some common parts.
  • file2.bin and file3.bin have some common parts.

I want to find the common parts between file1.bin and file2.bin that are different between file2.bin and file3.bin.

How do you recommend to accomplish that? I have already dumped the binary files to text files using xxd and then did a 3-way diff using vim -d file1.txt file2.txt file3.txt.

However, vim marks a part as changed in all the files even if it has only changed in one file and remains the same in the other two files. I want those special kind of occurrences to be marked differently.

3 Answers 3

6
+50

Perhaps you can use the built-in unix diff (I think it is part of OSX), but use the --unchanged-group-format to list the similarities. Do that for file1 and file 2. Then do it for file2 and file3. You can then do a regular diff on the two resulting files.

For an idea of how to get the similarities, have a look at this post.

0

The tool that I work for (ECMerge) does that. You just have to diff the 3 binary files, it will present equal portions in front of each other, and modified bytes appropriately placed in between. No need to first get an hex dump. You can script in JavaScript to output whatever you like based on the diff results and the bytes in the files (it works also in command line).

-1

Chromium uses bsdiff, then switched to courgette for doing binary diff as explained in their blog here. You might find useful leads from their blog.

2
  • Can it do 3 way diffs in the way I described in the problem? I can't find out how, would you please describe that?
    – Dimme
    Dec 30, 2011 at 11:19
  • bsdiff works on binary files, and produces binary patch. vimdiff expect text files as its input so I can't think of a way to make bsdiff works the way you would like here. As an alternative, see if you can make use of the 'diffexpr' option to coax vim to use extra setting for the diff program when generating the hunks for the binary files - maybe use the -I option to diff to specify a regex for "lines" that should be ignored when doing diff.
    – holygeek
    Dec 30, 2011 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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