How do I create binary patches?
Solution 1:
Check out bsdiff
and bspatch
(website, manpage, paper, GitHub fork).
To install this tool:
- Windows: Download and extract this package. You will also need a copy of
bzip2.exe
inPATH
; download that from the "Binaries" link here. - macOS: Install Homebrew and use it to install
bsdiff
. - Linux: Use your package manager to install
bsdiff
.
Solution 2:
Courgette, by the Google Chrome team, looks like most efficient tool for binary patching executables.
To quote their data:
Here are the sizes for the recent 190.1 -> 190.4 update on the developer channel:
- Full update: 10,385,920 bytes
- bsdiff update: 704,512 bytes
- Courgette update: 78,848 bytes
Here are instructions to build it. Here is a Windows binary from 2018 courtesy of Mehrdad.
Solution 3:
xdelta (website, GitHub) is another option. It seems to be more recent, but otherwise I have no idea how it compares to other tools like bsdiff.
Usage:
- Creating a patch:
xdelta -e -s old_file new_file delta_file
- Applying a patch:
xdelta -d -s old_file delta_file decoded_new_file
Installation:
- Windows: Download the official binaries.
- Chocolatey:
choco install xdelta3
- Homebrew:
brew install xdelta
- Linux: Available as
xdelta
orxdelta3
in your package manager.
Solution 4:
Modern port: Very useful .NET port for bsdiff/bspatch:
https://github.com/LogosBible/bsdiff.net
My personal choice. I tested it, and it was the only of all links, I was able out of the box to compile it (with Visual Studio, e.g. 2013). (The C++ source elsewhere is a bit outdated and needs at least a bit polishing and is only 32 bit which sets real memory (diff source size) limits. This is a port of this C++ code bsdiff and even tests if the patch results are identical to original code).
Further idea: With .NET 4.5 you could even get rid of #Zip lib, which is a dependency here.
I haven't measured if it is slightly slowlier than the c++ code, but it worked fine for me, (bsdiff: 90 MB file in 1-2 min.), and time-critical for me is only the bspatch, not the bsdiff.
I am not really sure, if the whole memory of a x64 machine is used, but I assume it. The x64 capable build ("Any CPU") works at least. Tried with a 100 MB file.
- Besides: The cited Google project 'Courgette' may be the best choice if your main target are executable files. But it is work to build it (for Windows measures, at least), and for binary files it is also using pure bsdiff/bspatch, as far as I have understood the doc.