summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-08-08 10:27:38 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-08-08 10:27:38 +0200
commitcf825a17e91337927fad2738e6816f02136a9c5f (patch)
treed52c86437487193bc8572a70085b5318c863b412
parent1529f1100e207bb865720471cc47d50b7c1ffc28 (diff)
downloadbin-cf825a17e91337927fad2738e6816f02136a9c5f.tar.gz
bin-cf825a17e91337927fad2738e6816f02136a9c5f.tar.xz
bindiff: Output binary representation of file
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xbindiff17
1 files changed, 16 insertions, 1 deletions
diff --git a/bindiff b/bindiff
index b1f6fe0..7a30c08 100755
--- a/bindiff
+++ b/bindiff
@@ -6,4 +6,19 @@ if [[ $# != 2 ]]; then
fi
#sdiff -w 150 -Hs <(xxd -b "$1") <(xxd -b "$2")
-cmp -l "$1" "$2" | awk '{printf "%08X %02X %02X\n", $1, strtonum(0$2), strtonum(0$3)}'
+
+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))}'