mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
Add random file fuzzing functions
This commit is contained in:
parent
86e07900ea
commit
c0472efacc
20
hexlib/rand.py
Normal file
20
hexlib/rand.py
Normal 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))
|
||||||
|
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.6",
|
version="1.7",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user