<<
path:
root/public/blog.git/html/fuzzer/generate_corpus.py
blob: c670ae0cc3e217a922665c8670055b55f796b8b0
[raw]
[clear marker]
2from pathlib import Path
3from sys import exit, argv
7def write_to_disk(fn, data):
9 with open(fn, "w+", encoding="utf8") as f:
11 except Exception as e:
16def corpus_generate(corpus_data, path):
17 for idx, string in enumerate(corpus_data):
18 padded = f"{idx+1:02d}"
19 fp = path / Path(padded)
20 print(f"Stored: {fp}")
21 write_to_disk(fp, string)
26 print("Cannot find config file in:", path)
29 with open(path, "r", encoding="utf8") as f:
30 config = f.readlines()
33 print("Could not read config")
37 print("Config is missing corpus data")
40 if not config[0].startswith("CFG"):
41 print("Invalid protocol byte. Missing 'CFG'")
44 if not config[1] == "\n":
45 print("Invalid protocol. Missing newline on second line")
48 header = config[0].split(" ")
51 print("Invalid header")
54 path = Path(header[1].strip())
55 path.mkdir(parents=True, exist_ok=True)
57 corpus_data = config[2:]
58 corpus_generate(corpus_data, path)
61def is_arg(args, *matches):
68 print("Usage: generate_copus.py [PATH TO CORPUS CONFIG]")
74 if is_arg("help", "-h", "-help", "--help"):
79 fp = Path(path.strip())
85if __name__ == "__main__":