mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 14:06: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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user