如何为二进制差异输出文件创建 PATCH 文件
我想知道如何为通过比较两个二进制文件获得的差异文件创建补丁。 $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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Diff 和 Patch 旨在处理文本文件,而不是任意二进制数据。您应该使用类似 bsdiff 的内容。
Diff and Patch are designed to work with text files, not arbitrary binary data. You should use something like bsdiff instead.
如果您的存储库或包正在使用 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
JDIFF 是一个输出两个(二进制)文件之间差异的程序。
您也可以使用
rdiff
命令。JDIFF is a program that outputs the differences between two (binary) files.
Also you can use the
rdiff
command.如果您仍然想使用 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...