From c0472efaccee93c6ef0c13f7e97bf2dacf7b64c1 Mon Sep 17 00:00:00 2001 From: simon987 Date: Wed, 4 Mar 2020 13:16:12 -0500 Subject: [PATCH] Add random file fuzzing functions --- hexlib/rand.py | 20 ++++++++++++++++++++ setup.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 hexlib/rand.py diff --git a/hexlib/rand.py b/hexlib/rand.py new file mode 100644 index 0000000..974f8f5 --- /dev/null +++ b/hexlib/rand.py @@ -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)) + diff --git a/setup.py b/setup.py index 1acc8eb..29c03a2 100644 --- a/setup.py +++ b/setup.py @@ -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",