Home | History | Annotate | Download | only in externalfuzzers
      1 #!/usr/bin/env python
      2 
      3 import mmap
      4 import os
      5 from random import randint
      6 import sys
      7 
      8 RANGE_START = 0x1b30
      9 RANGE_END   = 0x1b50
     10 MIN_BYTES_TO_FLIP = 1
     11 MAX_BYTES_TO_FLIP = 5
     12 
     13 with 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