<html><head></head><body><div class="ydp90457548yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div id="ydp90457548yiv3858250225"><div><div class="ydp90457548yiv3858250225ydp386ad737yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div id="ydp90457548yiv3858250225ydp386ad737yiv1271509962"><div><div class="ydp90457548yiv3858250225ydp386ad737yiv1271509962ydpdb7238cfyahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><span>I was asked to post this by Chris Lamb as a result of a discussion about what <span>diffoscope</span> does or should do when it finds a binary file whose format it doesn't understand. Most binary file comparators just compare bytes, which doesn't detect deletions or insertions.<br><br>Ideally what you would like is a tool which splits the binary files into convenient chunks and then applies your favourite file comparison algorithm, displaying the results in hex with addresses rather than lines with line numbers.<br><br>The problem with this is how to define convenient chunks. Individual bytes don't work well because there are too many occurrences of each byte and the diff algorithm gets confused. Fixed size chunks don't work because you can't detect insertions or deletions whose lengths aren't a multiple of the fixed size.<br><br>Some years ago I built a modified version of the Microsoft windiff example application to make it work on binary files. I copped out of the convenient chunk problem by leaving in the code which uses a linefeed as the chunk separator (see below for more thoughts on this) and I never bothered to make it display results in hex with addresses.<br><br>However it does work and it does detect insertions and deletions, although the user interface is a bit old and clunky. I no longer use windows and I don't currently have access to a Windows machine, so I can't at present build it. The built version that I have does run under "wine".<br><br>Chris suggested that I post the code to this list. In order to avoid a large attachment, I've put the files on github.com/rparkins999/bindiff. Since I can't at present build it, I can't check which files are actually needed, so I put everything except the .obj files which I know aren't needed: the built bindiff.exe is still there.<br><br>Since I talked to Chris I have had some further thoughts about convenient chunks. I think that you can guess a good separator character by scanning through the files creating a set of 256 element arrays which record for each byte value B<br><br>1) how many B's you have seen<br>2) how many non-B's you have seen since you last saw a B (needed for 3 and 4)<br>3) the shortest interval between two B's<br>4) the longest interval between two B's<br><br>You can calculate the average length of the interval between two B's from the total count of bytes and the number of B's seen.<br><br>You can then apply some figure of merit calculation to find a separator character which breaks the files into a set of chunks which are not too big or too small and have reasonably similar lengths. A good algorithm here should always choose linefeed as the separator character if applied to text files. I may get round to doing some work on this, but I'm busy with other things at the moment.<br><br></span><div><span>Incidentally I have just tried kdiff3 and it does about as good a job as bindiff, except that it knows about Unicode so it tries (unsuccessfully) to interpret the files as UTF8.</span></div><div><br></div><div>I don't know ho well diffoscope actually does because I haven't been able to install it. <span>sudo apt-get install diffoscope (running on kubuntu 14.0.4) says unable to locate package.</span><br></div><span><br>Share and enjoy<br>Richard P. Parkins, M. A.<br>Cambridge, England<br><br></span></div></div></div></div></div></div></div></body></html>