diff - find specific change between two values in hex dump

半腔热情 提交于 2019-12-07 10:28:33

问题


I am analyzing hex data from binary data dumps from a basic command-line program of mine. I'm basically dumping the exact contents of a struct (a large array of structs, actually) to a text file.

I then create a second binary dump, and compare the two files in vim using xxd to create binary-to-text representations of the original data.

Both files are the exact same size in bytes, and I'm trying to compare the two in a meaningful way. Even a small change in the data before I dump the file results in a large change in other parts of the file, due to other sections containing hashes, functions based on the value I changed, and so forth.

Is it possible to tell diff or vimdiff to say, compare two files, and show me only the parts of the file where in the original file (ie: file 1) a value was set to 1, and in the second file, the value was set to 32?

Thank you!


回答1:


I use:

diff <(xxd file1.bin) <(xxd file2.bin)

This uses process substitution to compare the output of two xxd processes. Note that this still shows line differences, so if any byte on a line is different it will be listed. This gives a nice hexdump-looking comparison.

The classical tool for this however, is cmp.

So, this could be handled like so:

cmp -l file1.raw file2.raw | grep -in "oldValue" | grep -in "newValue"

This will list exactly what you need, with the following fields printed out:

OFFSET  VALUE_IN_FILE_1 VALUE_IN_FILE_2


来源:https://stackoverflow.com/questions/16380090/diff-find-specific-change-between-two-values-in-hex-dump

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!