6

In Linux is there any way to compute the differences between two binaries (i.e., two executables)?

Let me be more specific: I want to know how to compute the delta (delta difference) between two versions of an executable or application or software in Linux. For example if I have to download and install only the updated part (the delta difference between the latest version and the old version) of an existing application or binary how do I do that in Linux.

4
  • The simplest way might be to compare the source code, if it is available to you. Commented Nov 16, 2012 at 11:50
  • Hi Basile, I have no way to compare the source code, only available things are the two versions of a binary, one latest version and the other one is the old version.
    – ind79ra
    Commented Nov 16, 2012 at 12:05
  • But what could you do with the result of the binary executable comparison? So why do you really ask??? Commented Nov 16, 2012 at 12:09
  • @BasileStarynkevitch You could use it to install updates as a patch, instead of the entire binary, allowing you to have much smaller updates. He mentioned that in his question, and I mentioned that in my answer. Where is the confusion? Commented Nov 16, 2012 at 12:20

3 Answers 3

10

You can use the tool bsdiff, and it's companion bspatch, for doing efficient diffs and patches of binary files.

If you want to get even smaller patches, you can take a look at Courgette, from Google Chrome. It's built on bsdiff, but they provide even more efficient diffs of executables by actually disassembling them before doing the diff. It's not distributed as a separate project, but you can get it from the Chromium source repository (how to check out the code).

There is also the xdelta tool, that has been around longer than bsdiff. According to the author of bsdiff, it is considerably less efficient; patches come out much bigger. It has the advantage that it supports the standard VCDIFF format (RFC 3284), which is supported by several other tools as well, so if you need to work with such other tools, it would be more useful.

5
  • One caveat: the OP mensions embedded systems (in the tags), and the bsdiff homepage says "bsdiff is quite memory hungry" -- I never thought about that.
    – loreb
    Commented Nov 16, 2012 at 11:10
  • @loreb The part that is memory hungry is the "diff" part, in which you generate the delta (generally on a development or build machine). The patch part has much more reasonable memory requirements. Commented Nov 16, 2012 at 11:12
  • Note that Google's Courgette is the subject of a patent lawsuit fro Red Bend. There's a brief discussion and several links at bugzilla.mozilla.org/show_bug.cgi?id=504624. Commented Nov 16, 2012 at 13:25
  • @JoshKelley Yuck. Yeah, it looks like Red Bend failed to get a preliminary injunction against Google, but Google failed to get the patent invalidated, so the fight goes on. All told, it might be safer and simpler to just go with bsdiff, which is the original work of Colin Percival and less than 500 lines of code, and has no claims of infringement against it that I know of. Commented Nov 16, 2012 at 15:02
  • Firstly I am sorry for the delayed reply, THANKS to ALL of you for your insightful views, and @BrianCampbell & Josh Kelley, thanks for mentioning this Red Bend & Google story, i have to check with bsdiff & bspatch.
    – ind79ra
    Commented Nov 26, 2012 at 7:32
3

diff will tell you if the binary files are different:

diff bin1 bin2
Binary files bin1 and bin2 differ

If you want the difference, use cmp:

cmp -l bin1 bin2 
  25  20 320
  26   4   3
  41 270 160
 209   4 264
 210   7   6

The -l option prints the byte number and the difference:

-l  --verbose
      Output byte numbers and values of all differing bytes.
0

Try cksum - gives the indication that they are the same

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