How do I create binary patches?

2019-01-13 00:33发布

What's the best way to go about making a patch for a binary file? I want it to be simple for users to apply(a simple patch application would be nice). Running diff on the file just gives Binary files [...] differ

标签: binary patch
5条回答
一纸荒年 Trace。
2楼-- · 2019-01-13 00:58

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.

查看更多
萌系小妹纸
3楼-- · 2019-01-13 01:04

xdelta is another option.

make patch:

  xdelta3.exe -e -s old_file new_file delta_file

apply patch:

  xdelta3.exe -d -s old_file delta_file decoded_new_file

It's available on the mac via homebrew: brew install xdelta

It seems to be more recent, but otherwise I have no idea how it compares to other tools like bsdiff.

查看更多
看我几分像从前
4楼-- · 2019-01-13 01:15

Google Courgette tool looks like most efficient tool for binary diff patches

comparing with bsdiff - 10 times smaller patch!

bsdiff update 704,512

Courgette update 78,848

查看更多
乱世女痞
5楼-- · 2019-01-13 01:18

Assuming you know the structure of the file you could use a c / c++ program to modify it byte by byte:

http://msdn.microsoft.com/en-us/library/c565h7xx(VS.71).aspx

Just read in the old file, and write out a new one modified as you like.

Don't forget to include a file format version number in the file so you know how to read any given version of the file format.

查看更多
不美不萌又怎样
6楼-- · 2019-01-13 01:20

If using something else than the standard patch is an option for you, you might want to check out bsdiff and bspatch:

http://www.daemonology.net/bsdiff/

bsdiff and bspatch are tools for building and applying patches to binary files. [...]

查看更多
登录 后发表回答