aboutsummaryrefslogtreecommitdiff
path: root/examples/externalfuzzers/rangeFuzz.py
blob: dd8884459c00597e91aba0c468eadbc8492df27a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python

import mmap
import os
from random import randint
import sys

RANGE_START = 0x1b30
RANGE_END   = 0x1b50
MIN_BYTES_TO_FLIP = 1
MAX_BYTES_TO_FLIP = 5

with open(sys.argv[1], "r+b") as f:
  mapped = mmap.mmap(f.fileno(), 0)

  bytes_to_flip = randint(MIN_BYTES_TO_FLIP, MAX_BYTES_TO_FLIP)
  bytes_flipped = 0

  while bytes_flipped < bytes_to_flip:
    byte_pos = randint(RANGE_START, RANGE_END)
    byte_new = chr(randint(0, 255))
    mapped[byte_pos] = byte_new
    bytes_flipped += 1

  mapped.close()