Diff - find a specific change between two values ​​in a hex dump

I am analyzing hexadecimal data from dumps of binary data from a basic command line program. I basically dump the exact contents of the structure (a large array of structures, in fact) into a text file.

Then I create a second binary dump and compare two files in vimwith xxdto create binary-textual representations of the source data.

Both files are the same size in bytes, and I'm trying to compare them in a meaningful way. Even a small change in the data before I reset the file leads to a big change in other parts of the file due to other sections containing hashes, functions based on changing the value, etc.

Is it possible to say diffor vimdiffsay, compare two files and show me only parts of the file, where in the source file (that is: file 1) the value was set to 1, and in the second file the value was set to 32?

Thank!

+1
source share
1 answer

I use:

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

A process replacement is used to compare the results of two processes xxd. Note that this still shows the difference in lines, so if any byte on the line is different, it will be specified. This gives a good comparison with the hexadecimal look.

The classic tool for this, however cmp.

So, this could be handled as follows:

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

, , :

OFFSET  VALUE_IN_FILE_1 VALUE_IN_FILE_2
+6

Source: https://habr.com/ru/post/1691909/


All Articles