Binary Patching with bsdiff in C#

bsdiff and bspatch are tools for building and applying patches to binary files. If the files are reasonably similar (e.g., built from the same source code), a patch that can transform v1 of a file into v2 is often significantly smaller than downloading the entire v2 file. According to Naïve Differences of Executable Code (the paper that introduced the algorithm), compression ratios of 10x or more are typically achieved.

The reference implementation is written in C and uses bzip2 to compress chunks in the patch file. I ported the algorithm to C# and used #ziplib for bzip2 support.

The primary file is BinaryPatchUtility.cs; the entire project (with bsdiff and bspatch front ends) is available at github. (Note that if you just want to run bsdiff from the command prompt, a Windows port is already available. This project is designed for reuse within another program, under the same license as the original bsdiff code.)

Posted by Bradley Grainger on December 29, 2010