-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzex.py
100 lines (85 loc) · 2.79 KB
/
fuzex.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
# Author: Abhishek Govindarasu
import sys
import argparse
from lib.helpers import fprint, err_print
FUZEX_TOO_MANY_WORDS = 1000000
if sys.version_info < (3, 7):
err_print("Fuzex requires python 3.7 or higher")
sys.exit(1)
def main(args):
input_cmd = args.cmd
output_file = args.output
if args.debug:
import lib.core
lib.core.DEBUG = True
from lib.core.parse import Parser
parser = Parser(input_cmd)
expression = parser.parse()
if args.size:
print(expression.size())
sys.exit(0)
if args.debug:
err_print("[DEBUG] Expression generated:", expression)
err_print("[DEBUG] Size of expression:", expression.size())
if not args.force and expression.size() > FUZEX_TOO_MANY_WORDS:
err_print(f"The provided expression will generate {expression.size()} lines.")
err_print("If you still want to run this, use the --force flag.")
sys.exit(1)
if args.output == sys.stdout:
for line in expression.generate():
sys.stdout.write(line)
sys.stdout.write("\n")
else:
for line in expression.generate():
fprint(output_file, line)
sys.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Fuzex command line arguments")
parser.add_argument("-c", "--cmd", help="input command (required)", required=True)
parser.add_argument(
"-s",
"--size",
help="get the size of the expression",
action="store_true",
)
parser.add_argument(
"-o",
"--output",
help="output file (default: stdout)",
nargs="?",
type=argparse.FileType("w"),
default=sys.stdout,
)
parser.add_argument(
"-f",
"--force",
help="Will allow Fuzex to process a large generation of words",
action="store_true",
)
parser.add_argument(
"-d",
"--debug",
help="Enable debug mode",
action="store_true",
)
try:
args = parser.parse_args()
main(args)
except KeyboardInterrupt:
err_print("exiting...")
sys.exit(1)