Created
December 13, 2011 00:29
-
-
Save darvell/1469818 to your computer and use it in GitHub Desktop.
Huffman find and ruin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def CorruptHuffman(filename,chance,maxlen): | |
with open(filename,"r+b") as f: | |
filesize = os.path.getsize(filename) | |
huffmanStart = 0 | |
huffmanEnd = 0 | |
found = 0 | |
for i in range(0,filesize): | |
if found == 2: | |
break | |
f.seek(i) | |
if f.read(1) == '\xFF': | |
f.seek(i + 1) | |
if f.read(1) == '\xC4': | |
# Ok, we found a single huffman table, that's good! | |
# Let's go hunt for the end of it. | |
huffmanStart = i + 2 | |
found += 1 | |
found = False | |
for i in range(huffmanStart + 2,filesize): | |
if found == True: | |
break | |
f.seek(i) | |
if f.read(1) == '\xFF': | |
f.seek(i + 1) | |
if f.read(1) != '\x00': | |
huffmanEnd = i - 2 | |
found = True | |
f.seek(random.randint(huffmanStart,huffmanEnd)) | |
f.write(hex(random.randint(1,250))) | |
print 'Filesize: ' + str(filesize) | |
print 'Huffman Start: ' + str(huffmanStart) | |
print 'Huffman End: ' + str(huffmanEnd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uh i'm not sure why i did f.read(1), wasn't thinking straight i guess
whatever this is just a dodgy implementation