syntax-symphony 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- syntax_symphony-0.0.1/LICENSE +20 -0
- syntax_symphony-0.0.1/PKG-INFO +162 -0
- syntax_symphony-0.0.1/README.md +120 -0
- syntax_symphony-0.0.1/pyproject.toml +39 -0
- syntax_symphony-0.0.1/setup.cfg +4 -0
- syntax_symphony-0.0.1/setup.py +3 -0
- syntax_symphony-0.0.1/src/syntax_symphony/__init__.py +1 -0
- syntax_symphony-0.0.1/src/syntax_symphony/cli.py +110 -0
- syntax_symphony-0.0.1/src/syntax_symphony/derivation_tree.py +272 -0
- syntax_symphony-0.0.1/src/syntax_symphony/fuzzer.py +359 -0
- syntax_symphony-0.0.1/src/syntax_symphony/grammar.py +219 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/PKG-INFO +162 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/SOURCES.txt +18 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/dependency_links.txt +1 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/entry_points.txt +2 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/requires.txt +1 -0
- syntax_symphony-0.0.1/src/syntax_symphony.egg-info/top_level.txt +1 -0
- syntax_symphony-0.0.1/tests/test_derivation_tree.py +145 -0
- syntax_symphony-0.0.1/tests/test_fuzzer.py +21 -0
- syntax_symphony-0.0.1/tests/test_grammar.py +72 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: syntax_symphony
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Efficient grammar-based fuzzer.
|
|
5
|
+
Author: Stanimir Iglev
|
|
6
|
+
Author-email: Stanimir Iglev <iglev.stanimir@gmail.com>
|
|
7
|
+
Maintainer-email: Stanimir Iglev <iglev.stanimir@gmail.com>
|
|
8
|
+
License:
|
|
9
|
+
MIT License
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
Project-URL: Homepage, https://github.com/StanimirIglev/syntax-symphony
|
|
29
|
+
Project-URL: Documentation, https://github.com/StanimirIglev/syntax-symphony/blob/master/README.md
|
|
30
|
+
Project-URL: Repository, https://github.com/StanimirIglev/syntax-symphony
|
|
31
|
+
Project-URL: Changelog, https://github.com/StanimirIglev/syntax-symphony/blob/master/CHANGELOG.md
|
|
32
|
+
Keywords: fuzzer,fuzzing,testing,grammar,grammars
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
36
|
+
Classifier: Topic :: Software Development :: Testing
|
|
37
|
+
Classifier: Intended Audience :: Developers
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: schema>=0.7.7
|
|
42
|
+
|
|
43
|
+
# Syntax Symphony
|
|
44
|
+
|
|
45
|
+
## Overview
|
|
46
|
+
|
|
47
|
+
Syntax Symphony is a powerful fuzzer designed to automatically generate test inputs for various applications based on user-defined grammars.
|
|
48
|
+
The fuzzer leverages the grammar rules to create meaningful and diverse input data, facilitating robust testing of applications.
|
|
49
|
+
In order to achieve high diversity and coverage of grammar rules, it uses k-coverage, as discussed by [Havrikov et al.](https://ieeexplore.ieee.org/abstract/document/8952419). This work has been greatly influenced by the concepts and ideas outlined in the [Fuzzing Book](https://www.fuzzingbook.org/).
|
|
50
|
+
|
|
51
|
+
With Syntax Symphony, you can enhance the quality and reliability of your software by generating a comprehensive set of test cases effortlessly. Start fuzzing today and make your software more robust against unexpected inputs!
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Getting Started
|
|
55
|
+
|
|
56
|
+
### Prerequisites
|
|
57
|
+
- Python 3.10 or higher
|
|
58
|
+
|
|
59
|
+
### Installation
|
|
60
|
+
|
|
61
|
+
#### From PyPI
|
|
62
|
+
```bash
|
|
63
|
+
pip install syntax-symphony
|
|
64
|
+
```
|
|
65
|
+
#### From Source
|
|
66
|
+
1. Clone the repository:
|
|
67
|
+
```bash
|
|
68
|
+
git clone
|
|
69
|
+
cd syntax_symphony
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2. We recommend creating a virtual environment to install the dependencies:
|
|
73
|
+
```bash
|
|
74
|
+
python -m venv venv
|
|
75
|
+
source venv/bin/activate
|
|
76
|
+
python -m pip install -r requirements.txt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
3. Install locally (add flag -e to install in editable mode):
|
|
80
|
+
```bash
|
|
81
|
+
pip install .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
4. To build the package:
|
|
85
|
+
```bash
|
|
86
|
+
python -m pip install build
|
|
87
|
+
python -m build
|
|
88
|
+
```
|
|
89
|
+
This should create the package in the `dist/` directory.
|
|
90
|
+
|
|
91
|
+
## CLI
|
|
92
|
+
Syntax Symphony provides a command-line interface (CLI) to interact with the fuzzer. The CLI allows you to specify the grammar file, the number of test cases to generate, and the output directory to save the generated test cases among others.
|
|
93
|
+
|
|
94
|
+
### Example usage:
|
|
95
|
+
```bash
|
|
96
|
+
# Generate 100 test cases using the grammar file examples/expr_grammar.json
|
|
97
|
+
ssfuzz -g examples/expr_grammar.json -c 100
|
|
98
|
+
|
|
99
|
+
# Save the output in the directory out/
|
|
100
|
+
ssfuzz -g examples/expr_grammar.json -c 100 -d out
|
|
101
|
+
|
|
102
|
+
# Set the start symbol
|
|
103
|
+
ssfuzz -g examples/expr_grammar.json -c 100 --start begin
|
|
104
|
+
|
|
105
|
+
# Set the file extension
|
|
106
|
+
ssfuzz -g examples/expr_grammar.json -c 100 -e json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Full syntax:
|
|
110
|
+
```
|
|
111
|
+
ssfuzz [-h] -g FILE [-s SYMBOL] -c NUMBER [-d DIR] [-e EXT] [--max-depth NUMBER] [--min-depth NUMBER] [-k NUMBER]
|
|
112
|
+
|
|
113
|
+
Syntax Symphony Fuzzer
|
|
114
|
+
|
|
115
|
+
options:
|
|
116
|
+
-h, --help show this help message and exit
|
|
117
|
+
-g FILE, --grammar FILE
|
|
118
|
+
Path to the grammar file
|
|
119
|
+
-s SYMBOL, --start SYMBOL
|
|
120
|
+
Start symbol of the grammar (without <...>). Default: start
|
|
121
|
+
-c NUMBER, --count NUMBER
|
|
122
|
+
Number of strings to generate
|
|
123
|
+
-d DIR, --dir DIR Output directory for the generated strings. Default: output
|
|
124
|
+
-e EXT, --file-extension EXT
|
|
125
|
+
The file extension to be used for the produced documents. Default: txt
|
|
126
|
+
--max-depth NUMBER Maximum depth for the derivation trees. Default: 10
|
|
127
|
+
--min-depth NUMBER Minimum depth for the derivation trees. Default: 1
|
|
128
|
+
-k NUMBER, --kcov NUMBER
|
|
129
|
+
Number of strings to generate for k-cov. Default: 1
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## API
|
|
133
|
+
Syntax Symphony can also be used as a library in your Python projects. The API provides a simple interface to generate test inputs using the fuzzer.
|
|
134
|
+
|
|
135
|
+
### Example usage:
|
|
136
|
+
```python
|
|
137
|
+
from syntax_symphony.fuzzer import SyntaxSymphony
|
|
138
|
+
from syntax_symphony.grammar import Grammar
|
|
139
|
+
|
|
140
|
+
# Define the grammar
|
|
141
|
+
grammar = Grammar({
|
|
142
|
+
"<start>": ["<expr>"],
|
|
143
|
+
"<expr>": ["<term> + <expr>", "<term> - <expr>", "<term>"],
|
|
144
|
+
"<term>": ["<factor> * <term>", "<factor> / <term>", "<factor>"],
|
|
145
|
+
"<factor>": ["<number>", "(<expr>)"],
|
|
146
|
+
"<number>": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
# Create the fuzzer
|
|
150
|
+
fuzzer = SyntaxSymphony(grammar)
|
|
151
|
+
|
|
152
|
+
# Generate 10 test cases
|
|
153
|
+
for i in range(10):
|
|
154
|
+
test_case = fuzzer.fuzz()
|
|
155
|
+
print(test_case)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
We welcome contributions from the community. If you have ideas for improvements, new features, or bug fixes, please submit a pull request or open an issue on our GitHub repository.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for more details.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Syntax Symphony
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Syntax Symphony is a powerful fuzzer designed to automatically generate test inputs for various applications based on user-defined grammars.
|
|
6
|
+
The fuzzer leverages the grammar rules to create meaningful and diverse input data, facilitating robust testing of applications.
|
|
7
|
+
In order to achieve high diversity and coverage of grammar rules, it uses k-coverage, as discussed by [Havrikov et al.](https://ieeexplore.ieee.org/abstract/document/8952419). This work has been greatly influenced by the concepts and ideas outlined in the [Fuzzing Book](https://www.fuzzingbook.org/).
|
|
8
|
+
|
|
9
|
+
With Syntax Symphony, you can enhance the quality and reliability of your software by generating a comprehensive set of test cases effortlessly. Start fuzzing today and make your software more robust against unexpected inputs!
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Getting Started
|
|
13
|
+
|
|
14
|
+
### Prerequisites
|
|
15
|
+
- Python 3.10 or higher
|
|
16
|
+
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
#### From PyPI
|
|
20
|
+
```bash
|
|
21
|
+
pip install syntax-symphony
|
|
22
|
+
```
|
|
23
|
+
#### From Source
|
|
24
|
+
1. Clone the repository:
|
|
25
|
+
```bash
|
|
26
|
+
git clone
|
|
27
|
+
cd syntax_symphony
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. We recommend creating a virtual environment to install the dependencies:
|
|
31
|
+
```bash
|
|
32
|
+
python -m venv venv
|
|
33
|
+
source venv/bin/activate
|
|
34
|
+
python -m pip install -r requirements.txt
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. Install locally (add flag -e to install in editable mode):
|
|
38
|
+
```bash
|
|
39
|
+
pip install .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. To build the package:
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install build
|
|
45
|
+
python -m build
|
|
46
|
+
```
|
|
47
|
+
This should create the package in the `dist/` directory.
|
|
48
|
+
|
|
49
|
+
## CLI
|
|
50
|
+
Syntax Symphony provides a command-line interface (CLI) to interact with the fuzzer. The CLI allows you to specify the grammar file, the number of test cases to generate, and the output directory to save the generated test cases among others.
|
|
51
|
+
|
|
52
|
+
### Example usage:
|
|
53
|
+
```bash
|
|
54
|
+
# Generate 100 test cases using the grammar file examples/expr_grammar.json
|
|
55
|
+
ssfuzz -g examples/expr_grammar.json -c 100
|
|
56
|
+
|
|
57
|
+
# Save the output in the directory out/
|
|
58
|
+
ssfuzz -g examples/expr_grammar.json -c 100 -d out
|
|
59
|
+
|
|
60
|
+
# Set the start symbol
|
|
61
|
+
ssfuzz -g examples/expr_grammar.json -c 100 --start begin
|
|
62
|
+
|
|
63
|
+
# Set the file extension
|
|
64
|
+
ssfuzz -g examples/expr_grammar.json -c 100 -e json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Full syntax:
|
|
68
|
+
```
|
|
69
|
+
ssfuzz [-h] -g FILE [-s SYMBOL] -c NUMBER [-d DIR] [-e EXT] [--max-depth NUMBER] [--min-depth NUMBER] [-k NUMBER]
|
|
70
|
+
|
|
71
|
+
Syntax Symphony Fuzzer
|
|
72
|
+
|
|
73
|
+
options:
|
|
74
|
+
-h, --help show this help message and exit
|
|
75
|
+
-g FILE, --grammar FILE
|
|
76
|
+
Path to the grammar file
|
|
77
|
+
-s SYMBOL, --start SYMBOL
|
|
78
|
+
Start symbol of the grammar (without <...>). Default: start
|
|
79
|
+
-c NUMBER, --count NUMBER
|
|
80
|
+
Number of strings to generate
|
|
81
|
+
-d DIR, --dir DIR Output directory for the generated strings. Default: output
|
|
82
|
+
-e EXT, --file-extension EXT
|
|
83
|
+
The file extension to be used for the produced documents. Default: txt
|
|
84
|
+
--max-depth NUMBER Maximum depth for the derivation trees. Default: 10
|
|
85
|
+
--min-depth NUMBER Minimum depth for the derivation trees. Default: 1
|
|
86
|
+
-k NUMBER, --kcov NUMBER
|
|
87
|
+
Number of strings to generate for k-cov. Default: 1
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API
|
|
91
|
+
Syntax Symphony can also be used as a library in your Python projects. The API provides a simple interface to generate test inputs using the fuzzer.
|
|
92
|
+
|
|
93
|
+
### Example usage:
|
|
94
|
+
```python
|
|
95
|
+
from syntax_symphony.fuzzer import SyntaxSymphony
|
|
96
|
+
from syntax_symphony.grammar import Grammar
|
|
97
|
+
|
|
98
|
+
# Define the grammar
|
|
99
|
+
grammar = Grammar({
|
|
100
|
+
"<start>": ["<expr>"],
|
|
101
|
+
"<expr>": ["<term> + <expr>", "<term> - <expr>", "<term>"],
|
|
102
|
+
"<term>": ["<factor> * <term>", "<factor> / <term>", "<factor>"],
|
|
103
|
+
"<factor>": ["<number>", "(<expr>)"],
|
|
104
|
+
"<number>": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
# Create the fuzzer
|
|
108
|
+
fuzzer = SyntaxSymphony(grammar)
|
|
109
|
+
|
|
110
|
+
# Generate 10 test cases
|
|
111
|
+
for i in range(10):
|
|
112
|
+
test_case = fuzzer.fuzz()
|
|
113
|
+
print(test_case)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Contributing
|
|
117
|
+
We welcome contributions from the community. If you have ideas for improvements, new features, or bug fixes, please submit a pull request or open an issue on our GitHub repository.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for more details.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "syntax_symphony"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Efficient grammar-based fuzzer."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Stanimir Iglev" },
|
|
13
|
+
{ name = "Stanimir Iglev", email = "iglev.stanimir@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
maintainers = [{ name = "Stanimir Iglev", email = "iglev.stanimir@gmail.com" }]
|
|
16
|
+
license = { file = "LICENSE" }
|
|
17
|
+
keywords = ["fuzzer", "fuzzing", "testing", "grammar", "grammars"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
22
|
+
"Topic :: Software Development :: Testing",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["schema >= 0.7.7"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/StanimirIglev/syntax-symphony"
|
|
30
|
+
Documentation = "https://github.com/StanimirIglev/syntax-symphony/blob/master/README.md"
|
|
31
|
+
Repository = "https://github.com/StanimirIglev/syntax-symphony"
|
|
32
|
+
Changelog = "https://github.com/StanimirIglev/syntax-symphony/blob/master/CHANGELOG.md"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
ssfuzz = "syntax_symphony.cli:ssfuzz"
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
pythonpath = ["src"]
|
|
39
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import hashlib
|
|
3
|
+
import os
|
|
4
|
+
from .fuzzer import SyntaxSymphony
|
|
5
|
+
from .grammar import Grammar
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def ssfuzz():
|
|
9
|
+
parser = argparse.ArgumentParser(description="Syntax Symphony Fuzzer")
|
|
10
|
+
parser.add_argument(
|
|
11
|
+
"-g",
|
|
12
|
+
"--grammar",
|
|
13
|
+
dest="grammar",
|
|
14
|
+
metavar="FILE",
|
|
15
|
+
required=True,
|
|
16
|
+
help="Path to the grammar file",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-s",
|
|
20
|
+
"--start",
|
|
21
|
+
dest="start_symbol",
|
|
22
|
+
default="start",
|
|
23
|
+
metavar="SYMBOL",
|
|
24
|
+
required=False,
|
|
25
|
+
type=str,
|
|
26
|
+
help="Start symbol of the grammar (without <...>). Default: start",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"-c",
|
|
30
|
+
"--count",
|
|
31
|
+
dest="count",
|
|
32
|
+
metavar="NUMBER",
|
|
33
|
+
required=True,
|
|
34
|
+
type=int,
|
|
35
|
+
help="Number of strings to generate",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"-d",
|
|
39
|
+
"--dir",
|
|
40
|
+
dest="output_dir",
|
|
41
|
+
metavar="DIR",
|
|
42
|
+
default="out",
|
|
43
|
+
required=False,
|
|
44
|
+
type=str,
|
|
45
|
+
help="Output directory for the generated strings. Default: out",
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"-e",
|
|
49
|
+
"--file-extension",
|
|
50
|
+
dest="file_extension",
|
|
51
|
+
metavar="EXT",
|
|
52
|
+
default="txt",
|
|
53
|
+
help="The file extension to be used for the produced documents. Default: txt",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--max-depth",
|
|
57
|
+
dest="max_depth",
|
|
58
|
+
default=10,
|
|
59
|
+
metavar="NUMBER",
|
|
60
|
+
required=False,
|
|
61
|
+
type=int,
|
|
62
|
+
help="Maximum depth for the derivation trees. Default: 10",
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--min-depth",
|
|
66
|
+
dest="min_depth",
|
|
67
|
+
default=1,
|
|
68
|
+
metavar="NUMBER",
|
|
69
|
+
required=False,
|
|
70
|
+
type=int,
|
|
71
|
+
help="Minimum depth for the derivation trees. Default: 1",
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"-k",
|
|
75
|
+
"--kcov",
|
|
76
|
+
dest="kcov",
|
|
77
|
+
metavar="NUMBER",
|
|
78
|
+
default=1,
|
|
79
|
+
required=False,
|
|
80
|
+
type=int,
|
|
81
|
+
help="Number of strings to generate for k-cov. Default: 1",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
args = parser.parse_args()
|
|
85
|
+
|
|
86
|
+
with open(args.grammar, "r") as file:
|
|
87
|
+
grammar_dict = eval(file.read())
|
|
88
|
+
|
|
89
|
+
grammar = Grammar(grammar_dict, f"<{args.start_symbol}>")
|
|
90
|
+
|
|
91
|
+
fuzzer = SyntaxSymphony(grammar, args.kcov, args.min_depth, args.max_depth)
|
|
92
|
+
|
|
93
|
+
if not os.path.isdir(args.output_dir):
|
|
94
|
+
os.makedirs(args.output_dir)
|
|
95
|
+
|
|
96
|
+
for _ in range(args.count):
|
|
97
|
+
string = fuzzer.fuzz()
|
|
98
|
+
file_path = (
|
|
99
|
+
f"{args.output_dir}/"
|
|
100
|
+
+ hashlib.sha256(
|
|
101
|
+
string.encode(), usedforsecurity=False
|
|
102
|
+
).hexdigest()
|
|
103
|
+
+ f".{args.file_extension}"
|
|
104
|
+
)
|
|
105
|
+
with open(file_path, "w") as file:
|
|
106
|
+
file.write(string)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
ssfuzz()
|