Skip to content

Instantly share code, notes, and snippets.

@anderbubble
Created March 1, 2011 11:20
Show Gist options
  • Save anderbubble/848993 to your computer and use it in GitHub Desktop.
Save anderbubble/848993 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
bs = 1024 * 1024
zero = '\x00'
one = '\xFF'
count = 0
f = open(sys.argv[1], "rb")
if sys.argv[2] == 'zero':
target = zero
elif sys.argv[2] == 'one':
target = one
else:
raise Exception("must specify 'one' or 'zero'")
maxcount = int(sys.argv[3])
last_pos = None
while True:
block = f.read(bs)
if len(block) == 0:
break
elif count >= maxcount:
break
elif block != target * bs:
for i in xrange(len(block)):
pos = (count * bs) + i
byte = block[i]
if byte != target:
if last_pos is None:
print pos, repr(byte)
else:
print pos, repr(byte), "(+%i)" % (pos - last_pos)
last_pos = pos
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment