如何为二进制差异输出文件创建 PATCH 文件

发布于 2024-08-24 17:42:53 字数 202 浏览 9 评论 0原文

我想知道如何为通过比较两个二进制文件获得的差异文件创建补丁。 $cmp -l > 我检查文本文件“diff”的输出文件名

可用于比较并生成 PATCH 文件 $ diff -u 旧文件 新文件 > mods.diff # -u 告诉 diff 输出统一的 diff 格式

我想在旧的二进制图像文件上应用 PATCH 以获得新的二进制图像文件。

I want to know how to create a PATCH for the difference file I got by comparing two binary files.
$cmp -l > output file name

I checked for text files 'diff" can be used to compare and generate a PATCH file
$ diff -u oldFile newFile > mods.diff # -u tells diff to output unified diff format

I want to apply the PATCH on the old binary image file to get my new binary image file.

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

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

发布评论

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

评论(4

冰葑 2024-08-31 17:42:53

Diff 和 Patch 旨在处理文本文件,而不是任意二进制数据。您应该使用类似 bsdiff 的内容。

Diff and Patch are designed to work with text files, not arbitrary binary data. You should use something like bsdiff instead.

寄居人 2024-08-31 17:42:53

如果您的存储库或包正在使用 git,您可以使用以下命令进行二进制比较
git diff --patch --binary old_dir patched_dir

当然你也可以将它与提交一起使用
git diff --patch --binary commit1 commit2

If your repository, or package is using git you can make binary diff with
git diff --patch --binary old_dir patched_dir

Of course you can also use it with commits
git diff --patch --binary commit1 commit2

葬心 2024-08-31 17:42:53

JDIFF 是一个输出两个(二进制)文件之间差异的程序。
您也可以使用rdiff命令。

JDIFF is a program that outputs the differences between two (binary) files.
Also you can use therdiff command.

泪意 2024-08-31 17:42:53

如果您仍然想使用 diff &修补。这是一个方法...
自己编写 ac 程序,在每个 512/1024/your_choice 字节的末尾插入一个换行符(这只是为了欺骗 diff,因为它逐行比较文件)。在两个输入文件上运行此脚本。

然后运行 ​​'diff -au file1 file2 > mod.diff(您将在此处获得补丁)'

修补很简单 'patch < mod.diff'

然后再次编写一个程序以从二进制文件中删除换行符。这就是全部...

If you still want to use diff & patch. Here is a way...
Write a c program yourself to insert a newline character at the end of every 512/1024/your_choice bytes (this is just to fool the diff as it compares the files line by line). Run this script on your two input files.

Then run 'diff -au file1 file2 > mod.diff (you will get the patch here)'

Patching is simple 'patch < mod.diff'

Than again write a program to remove the newlines from the binary file. That is all...

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