如何使用"cmp"比较两个二进制文件并找到它们不同之处的所有字节偏移量? [英] How to use "cmp" to compare two binaries and find all the byte offsets where they differ?

查看:30
本文介绍了如何使用"cmp"比较两个二进制文件并找到它们不同之处的所有字节偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获得一些Bash脚本循环的帮助,只需使用

I would love some help with a Bash script loop that will show all the differences between two binary files, using just

cmp file1 file2 

它仅显示我要使用cmp的第一个更改,因为它为每个更改所在的行数提供了偏移量,但是如果您认为有更好的命令,我可以接受它:)谢谢

It only shows the first change I would like to use cmp because it gives a offset an a line number of where each change is but if you think there's a better command I'm open to it :) thanks

推荐答案

我认为 cmp -l file1 file2 可能会满足您的要求.在联机帮助页上:

I think cmp -l file1 file2 might do what you want. From the manpage:

-l  --verbose
      Output byte numbers and values of all differing bytes.

输出是所有不同字节的偏移量,文件1中的字节值和文件2中的值的表.看起来像这样:

The output is a table of the offset, the byte value in file1 and the value in file2 for all differing bytes. It looks like this:

4531  66  63
4532  63  65
4533  64  67
4580  72  40
4581  40  55
[...]

因此,第一个区别是在偏移4531处,其中file1的 十进制

So the first difference is at offset 4531, where file1's decimal octal byte value is 66 and file2's is 63.

这篇关于如何使用"cmp"比较两个二进制文件并找到它们不同之处的所有字节偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆