Add random file fuzzing functions

This commit is contained in:
simon987 2020-03-04 13:16:12 -05:00
parent 86e07900ea
commit c0472efacc
2 changed files with 21 additions and 1 deletions

20
hexlib/rand.py Normal file
View File

@ -0,0 +1,20 @@
import random
def fuzz(buf: bytes, n: int, width: int):
fuzzed = bytearray(buf)
for _ in range(n):
i = random.randint(0, len(buf))
for off in range(width):
if i + off < len(buf):
fuzzed[i + off] = fuzzed[i + off] + 1
return fuzzed
def fuzz_file(file_in: str, out_files: list, n: int, width: int):
with open(file_in, "rb") as f:
buf = f.read()
for out_path in out_files:
with open(out_path, "wb") as out:
out.write(fuzz(buf, n, width))

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="hexlib",
version="1.6",
version="1.7",
description="Misc utility methods",
author="simon987",
author_email="me@simon987.net",