1#!/usr/bin/env python 2 3import mmap 4import os 5from random import randint 6import sys 7 8RANGE_START = 0x1b30 9RANGE_END = 0x1b50 10MIN_BYTES_TO_FLIP = 1 11MAX_BYTES_TO_FLIP = 5 12 13with open(sys.argv[1], "r+b") as f: 14 mapped = mmap.mmap(f.fileno(), 0) 15 16 bytes_to_flip = randint(MIN_BYTES_TO_FLIP, MAX_BYTES_TO_FLIP) 17 bytes_flipped = 0 18 19 while bytes_flipped < bytes_to_flip: 20 byte_pos = randint(RANGE_START, RANGE_END) 21 byte_new = chr(randint(0, 255)) 22 mapped[byte_pos] = byte_new 23 bytes_flipped += 1 24 25 mapped.close() 26