3 个二进制文件的差异
我有 3 个二进制文件。我们将它们命名为 file1.bin
、file2.bin
和 file3.bin
。
file1.bin
和file2.bin
有一些共同的部分。file2.bin
和file3.bin
有一些共同的部分。
我想找到 file1.bin
和 file2.bin
之间的共同部分,而 file2.bin
和 file3.bin 之间的不同之处
。
您建议如何实现这一目标?我已经使用 xxd
将二进制文件转储到文本文件,然后使用 vim -d file1.txt file2.txt file3.txt
进行了 3 向 diff。
然而,vim
会将所有文件中的某个部分标记为已更改,即使该部分仅在一个文件中发生更改并且在其他两个文件中保持不变。我希望对那些特殊的事件进行不同的标记。
I have 3 binary files. Let's call them file1.bin
, file2.bin
and file3.bin
.
file1.bin
andfile2.bin
have some common parts.file2.bin
andfile3.bin
have some common parts.
I want to find the common parts between file1.bin
and file2.bin
that are different between file2.bin
and file3.bin
.
How do you recommend to accomplish that? I have already dumped the binary files to text files using xxd
and then did a 3-way diff using vim -d file1.txt file2.txt file3.txt
.
However, vim
marks a part as changed in all the files even if it has only changed in one file and remains the same in the other two files. I want those special kind of occurrences to be marked differently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您可以使用内置的 unix diff(我认为它是 OSX 的一部分),但使用
--unchanged-group-format
来列出相似之处。对文件 1 和文件 2 执行此操作。然后对文件 2 和文件 3 执行此操作。然后,您可以对两个结果文件进行常规比较。有关如何获得相似性的想法,请查看 这篇文章。
Perhaps you can use the built-in unix diff (I think it is part of OSX), but use the
--unchanged-group-format
to list the similarities. Do that for file1 and file 2. Then do it for file2 and file3. You can then do a regular diff on the two resulting files.For an idea of how to get the similarities, have a look at this post.
我使用的工具 (ECMerge) 就是这样做的。您只需比较 3 个二进制文件,它将在彼此前面呈现相等的部分,并将修改后的字节适当地放置在之间。无需首先获取十六进制转储。您可以在 JavaScript 中编写脚本,根据差异结果和文件中的字节输出您喜欢的任何内容(它也可以在命令行中使用)。
The tool that I work for (ECMerge) does that. You just have to diff the 3 binary files, it will present equal portions in front of each other, and modified bytes appropriately placed in between. No need to first get an hex dump. You can script in JavaScript to output whatever you like based on the diff results and the bytes in the files (it works also in command line).
Chromium 使用 bsdiff,然后切换到 courgette 进行二进制比较,如其博客 此处。您可能会从他们的博客中找到有用的线索。
Chromium uses bsdiff, then switched to courgette for doing binary diff as explained in their blog here. You might find useful leads from their blog.