summaryrefslogtreecommitdiffstats
path: root/libcli/security/tests/data/export-sddl-fuzz-seeds-as-json
blob: cbff661265e628bc535eafd4b17d033be72cb750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
"""USAGE: $ ./export-sddl-fuzz-seeds-as-json DIR [DIR[...]] > x.json

Some of our fuzzers generate SDDL strings with trailing garbage.

This script converts them into the JSON format used by
windows-sddl-tests.py, though it doesn't parse the SDDL, mapping all
strings to an empty list. The idea is you can feed this through
windows-sddl-tests.py or something else to get the correct bytes.

Valid and invalid strings are treated alike, so long as they are
utf-8. The JSON is un-indented, but structurally equivalent to this:

{
   "D:P" : [],
   "yertle" : [],
   "ł\n¼" : [],
}
"""
from pathlib import Path
import sys
import json


def main():
    if {'-h', '--help'}.intersection(sys.argv) or len(sys.argv) < 2:
        print(__doc__)
        sys.exit(len(sys.argv) < 2)

    bytes_json = {}
    for arg in sys.argv[1:]:
        d = Path(arg)
        for fn in d.iterdir():
            with fn.open("rb") as f:
                b = f.read()
            # the SDDL string is the nul-terminated portion.
            if 0 in b:
                b = b[:b.index(0)]
            try:
                s = b.decode()
            except UnicodeDecodeError:
                continue
            bytes_json[s] = []

    out = json.dumps(bytes_json)
    print(out)


main()