Sunday, March 26, 2023

Showing differences between binary files

At work I'm having to port some firmware changes to a new board.  This requires I understand the boot process in excruciating detail.  The old board boots with 3 different files stored in flash memory (bootloader, bootloader environment, and Linux file system).  I have the files as well as several raw dumps of various areas in the flash memory chip made with the "dd" command and needed to know whether there was any magic done to identify the different partitions of the flash device.

So I needed to show differences between binary files.  I normally use meld for file comparisons but it doesn't handle binary files.  It's easy to write a simple program in C to show simple byte differences but I wanted something able to display context for any differences.

It turns out that this is very easy to do in bash thanks to the ability to easily combine tools.  This is made possible by the Unix Philosophy.  The following command does exactly what I was looking for.

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

So I whipped up a small shell script to make this easier and I've got a new tool for future use.  As you can see from the image, the display would be helpful in figuring out the differences between files.



No comments: