Skip to content

Instantly share code, notes, and snippets.

@tmoertel
Created April 29, 2012 04:38
Show Gist options
  • Save tmoertel/2533045 to your computer and use it in GitHub Desktop.
Save tmoertel/2533045 to your computer and use it in GitHub Desktop.
Compare two disk images and emit CSV file listing bit-position differences
#!/usr/bin/env python
#
# Compare two disk images for bit differences.
# Usage: ./cmpdisks.py diskA.dsk diskB.dsk
#
# Tom Moertel <[email protected]>
# 2012-04-29
import sys
def main(file_a, file_b):
sa, sb = map(file_to_bytestream, (file_a, file_b))
for (byte_posn, (ca, cb)) in enumerate(zip(sa, sb)):
if ca != cb:
mask = 1
for bit in xrange(8):
cabit = ca & mask
cbbit = cb & mask
if cabit != cbbit:
print "%d,%d,%d,%d" % (byte_posn, bit, cabit, cbbit)
mask <<= 1
def file_to_bytestream(file_name):
with file(file_name, 'rb') as f:
return map(ord, f.read())
if __name__ == '__main__':
main(*sys.argv[1:3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment