如何创建二进制补丁?

发布于 2024-08-15 11:51:39 字数 122 浏览 1 评论 0 原文

为二进制文件制作补丁的最佳方法是什么?

我希望用户能够简单地应用它(一个简单的补丁应用程序就很好了)。在文件上运行 diff 只会给出二进制文件 [...] 不同

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

合久必婚 2024-08-22 11:51:39

查看 bsdiffbspatch网站手册页论文GitHub 分支 >)。

要安装此工具:

  • Windows:下载并解压 这个包。您还需要在 PATH 中找到 bzip2.exe 的副本;从“二进制文件”链接此处下载该文件。
  • macOS:安装 Homebrew 并使用它来安装 bsdiff
  • Linux:使用包管理器安装 bsdiff

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 in PATH; download that from the "Binaries" link here.
  • macOS: Install Homebrew and use it to install bsdiff.
  • Linux: Use your package manager to install bsdiff.
蓝咒 2024-08-22 11:51:39

Google Chrome 团队开发的 Courgette 看起来是最高效的工具用于二进制修补可执行文件。

引用他们的数据:

这是最近 190.1 的尺寸 ->开发者频道190.4更新:

  • 完整更新:10,385,920 字节
  • bsdiff 更新:704,512 字节
  • 小胡瓜更新:78,848 字节

这里是 构建说明。这是 2018 年的 Windows 二进制文件,由 梅赫达德

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.

锦欢 2024-08-22 11:51:39

xdelta(网站GitHub)是另一种选择。它似乎是最近的,但除此之外我不知道它与 bsdiff 等其他工具相比如何。

用法:

  • 创建补丁:xdelta -e -s old_file new_file delta_file
  • 应用补丁:xdelta -d -s old_file delta_file demod_new_file

安装:

  • Windows:下载官方二进制文件
  • Chocolatey:choco install xdelta3
  • Homebrew:brew install xdelta
  • Linux:在包管理器中以 xdeltaxdelta3 形式提供。

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 or xdelta3 in your package manager.
银河中√捞星星 2024-08-22 11:51:39

对于小而简单的补丁,最简单的方法是使用 -a (或 --text)选项告诉 diff 将文件视为文本。据我了解,更复杂的二进制差异仅对减少补丁的大小有用。

$ man diff | grep -B1 "as text"
       -a, --text
              treat all files as text
$ diff old new
Binary files old and new differ
$ diff -a old new > old.patch
$ patch < old.patch old
patching file old
$ diff old new
$

如果文件大小相同且补丁仅修改几个字节,则可以使用 xxd,它通常随操作系统一起安装。以下将每个文件转换为每行一个字节的十六进制表示形式,然后比较文件以创建紧凑补丁,然后应用该补丁。

$ xxd -c1 old > old.hex
$ xxd -c1 new > new.hex
$ diff -u old.hex new.hex | grep "^+" | grep -v "^++" | sed "s/^+//" > old.hexpatch
$ xxd -c1 -r old.hexpatch old
$ diff old new
$

对于支持进程替换的 shell(例如 bash 和 zsh),有一个更简单的方法可用:

$ comm -13 <(xxd -c1 old) <(xxd -c1 new) > old.hexpatch 
$ xxd -c1 -r old.hexpatch old
$ diff old new
$

这里 comm -13 删除仅出现在第一个输入中的行以及出现在两个输入中的行,只留下专用于第一个输入的行。第二个输入。

For small, simple patches, it's easiest just to tell diff to treat the files as text with the -a (or --text) option. As far as I understand, more complicated binary diffs are only useful for reducing the size of patches.

$ man diff | grep -B1 "as text"
       -a, --text
              treat all files as text
$ diff old new
Binary files old and new differ
$ diff -a old new > old.patch
$ patch < old.patch old
patching file old
$ diff old new
$

If the files are the same size and the patch just modifies a few bytes, you can use xxd, which is commonly installed with the OS. The following converts each file to a hex representation with one byte per line, then diffs the files to create a compact patch, then applies the patch.

$ xxd -c1 old > old.hex
$ xxd -c1 new > new.hex
$ diff -u old.hex new.hex | grep "^+" | grep -v "^++" | sed "s/^+//" > old.hexpatch
$ xxd -c1 -r old.hexpatch old
$ diff old new
$

For shells that support process substitution such as bash and zsh, there is a simpler method available:

$ comm -13 <(xxd -c1 old) <(xxd -c1 new) > old.hexpatch 
$ xxd -c1 -r old.hexpatch old
$ diff old new
$

Here the comm -13 removes lines that appear only in the first input as well as lines that appear in both inputs, leaving only the lines exclusive to the second input.

零時差 2024-08-22 11:51:39

现代端口:对于 bsdiff/bspatch 非常有用的 .NET 端口:

https://github.com/ LogosBible/bsdiff.net

我个人的选择。

我测试了一下,它是所有链接中唯一的一个。开箱即用,我能够编译它(使用 Visual Studio,例如 Visual Studio 2013 )。 (其他地方的 C++ 源代码有点过时,至少需要一点改进,并且只有 32 位,它设置了实际内存(差异源大小)限制。这是此 C++ 代码 bsdiff 的端口,甚至测试补丁结果是否相同到原始代码。)

进一步的想法:使用 .NET 4.5,您甚至可以摆脱 #Zip 库,它是这里的依赖项。

我没有测量它是否比 C++ 代码稍慢,但它对我来说工作得很好(bsdiff:1-2 分钟内 90 MB 文件),对我来说时间关键的只是 bspatch,而不是 bsdiff。

我不太确定是否使用了 x64 机器的整个内存,但我假设是这样。支持 x64 的构建(“任何 CPU”)至少可以工作。我尝试使用 100 MB 的文件。

-
此外:如果您的主要目标是可执行文件,引用的 Google 项目“Courgette”可能是最佳选择。但构建它是一项工作(至少对于 Windows 测量而言),并且对于二进制文件,它也使用纯 bsdiff/bspatch,据我所理解的文档。

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 one of all links. Out of the box I was able to compile it (with Visual Studio, e.g., Visual Studio 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 the #Zip library, which is a dependency here.

I haven't measured if it is slightly slower than the C++ code, but it worked fine for me, (bsdiff: 90 MB file in 1-2 minutes), 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. I 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 documentation.

四叶草在未来唯美盛开 2024-08-22 11:51:39

diff 和 git-diff 可以通过使用 -a 将二进制文件视为文本来处理它们。

通过 git-diff,您还可以使用 --binary 生成二进制文件的 ASCII 编码,例如适合粘贴到电子邮件中。

diff and git-diff can handle binary files by treating them as text with -a.

With git-diff you can also use --binary which produces ASCII encodings of binary files, suitable for pasting into an email for example.

丑疤怪 2024-08-22 11:51:39

HDiffPatch 可以在 Windows、macOS、Linux 和 Android 上运行。

它支持二进制文件或目录之间的差异;

创建补丁:hdiffz [-m|-s-64] [-c-lzma2] old_path new_path out_delta_file

应用补丁:hpatchz old_path delta_file out_new_path

安装:

从最新版本下载,或者下载源代码& 制作

Jojos Binary Diff 是另一种很好的二进制 diff 算法;

HDiffPatch can run on Windows, macOS, Linux, and Android.

It supports diffs between binary files or directories;

Creating a patch: hdiffz [-m|-s-64] [-c-lzma2] old_path new_path out_delta_file

Applying a patch: hpatchz old_path delta_file out_new_path

Install:

Download from last release, or download the source code & make;

Jojos Binary Diff is another good binary diff algorithm;

孤千羽 2024-08-22 11:51:39

https://github.com/reproteq/DiffPatchWpf
差异补丁Wpf
DiffPatchWpf 简单的二进制补丁制作工具。

比较两个二进制文件并将它们之间的差异保存在新文件 patch.txt 中,

快速轻松地将补丁应用到另一个二进制文件中。

现在,您可以快速轻松地应用另一个二进制文件中的差异。

示例:

1- 加载文件 Aori.bin

2- 加载文件 Amod.bin

3- 比较并保存 Aori-patch.txt

4- 加载文件 Bori.bin

5- 加载补丁 Aori-patch.txt

6- 应用补丁并保存文件 Bori -patched.bin

alt 标签

https://youtu.be/EpyuF4t5MWk

Microsoft Visual Studio Community 2019

版本 16.7.7

.NETFramework,版本=v4.7.2

在 Windows 10x64 位中测试

https://github.com/reproteq/DiffPatchWpf
DiffPatchWpf
DiffPatchWpf simple binary patch maker tool.

Compare two binary files and save the differences between them in new file patch.txt

Apply the patch in another binary fast and easy.

Now you can apply the differences in another binary quickly and easily.

example:

1- Load file Aori.bin

2- Load file Amod.bin

3- Compare and save Aori-patch.txt

4- Load file Bori.bin

5- Load patch Aori-patch.txt

6- Apply patch and save file Bori-patched.bin

alt tag

https://youtu.be/EpyuF4t5MWk

Microsoft Visual Studio Community 2019

Versión 16.7.7

.NETFramework,Version=v4.7.2

Tested in windows 10x64bits

心房的律动 2024-08-22 11:51:39

假设您知道文件的结构,您可以使用 C / C++ 程序逐字节修改它:

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

只需读入旧文件,然后写出新文件一个按照你喜欢的方式修改。

不要忘记在文件中包含文件格式版本号,以便您知道如何读取文件格式的任何给定版本。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文