summaryrefslogtreecommitdiffstats
path: root/bindiff
blob: 7a30c08fd047cd1688dd93de96c4d96714e7c139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

if [[ $# != 2 ]]; then
	echo "usage: bindiff <file1> <file2>"
	exit 0
fi

#sdiff -w 150 -Hs <(xxd -b "$1") <(xxd -b "$2")

cmp -l "$1" "$2" | awk 'function bits2str(bits,        data, mask)
{
    if (bits == 0)
        return "0"

    mask = 1
    for (; bits != 0; bits = rshift(bits, 1))
        data = (and(bits, mask) ? "1" : "0") data

    while ((length(data) % 8) != 0)
        data = "0" data

    return data
}
{printf "%08X %s %s\n", $1, bits2str(strtonum(0$2)), bits2str(strtonum(0$3))}'