Home > Bash, Programming, Uncategorized > Compare binary files with bash

Compare binary files with bash

While I was working on a reverse-engineering project trying to find out the structure of a data file, I wrote this simple BASH script to do the job:

# script to compare two binary files
[ $# -lt 2 ] && echo "Usage: $0 file_a fileb" && exit 0
R1=`mktemp -u -p /tmp XXXXXXXX`
R2=`mktemp -u -p /tmp XXXXXXXX`
if [ -f $1 -a -f $2 ]; then
   hexdump $1 > $R1
   hexdump $2 > $R2
   diff $R1 $R2
   rm $R1 $R2
  1. January 30, 2010 at 4:01 am

    Thanks Brother for your share, nice info, and so usefull for me..
    script mlm,script binary

    • ricoch3n
      January 30, 2010 at 11:25 pm

      No problem. Glad it helps.

  1. February 11, 2010 at 9:00 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: