-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
102 lines (81 loc) · 2.21 KB
/
main.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
101
102
from lib import generate
import subprocess as sp
from pathlib import Path
import sys
import argparse
from pprint import pprint
executable = {
"win32": "FASMARM.EXE",
"linux": "fasmarm",
"linux2": "fasmarm",
"darwin": "fasmarm.o",
}
if sys.platform not in executable:
raise OSError("OS not supported: '%s'", sys.platform)
root = Path(sys.path[0])
parser = argparse.ArgumentParser(description="A fuzzer for the Nintendo GameBoy Advance")
parser.add_argument(
"number_of_tests",
metavar="N",
type=int,
nargs=None,
help="Number of tests to generate",
)
parser.add_argument(
"-T",
dest="do_thumb_mode",
help="Amount of THUMB mode tests to generate, choose from 'some', 'all' or 'none'",
type=str.lower,
choices=["some", "all", "none"],
)
parser.add_argument(
"-nM",
help="Disable multiply tests",
dest="do_multiply",
action="store_false"
)
parser.add_argument(
"-nD",
help="Disable data processing tests",
dest="do_data_processing",
action="store_false",
)
parser.add_argument(
"-nLS",
help="Disable load/store tests",
dest="do_load_store",
action="store_false"
)
parser.add_argument(
"--S",
nargs=None,
help="Seed to seed the generator with",
dest="seed"
)
parser.set_defaults(do_thumb_mode="some")
number_of_tests = 0
args = {}
if len(sys.argv) > 1:
args = vars(parser.parse_args(sys.argv[1:]))
number_of_tests = args.pop("number_of_tests")
else:
print(f"No command line arguments given")
while True:
try:
number_of_tests = int(input("Number of tests: "))
break
except ValueError:
print("Please enter a valid number")
print("To omit certain types of tests, use the command line options ('-h' or '-help' for more information)")
with open(root / "asm/tests.inc", "w+") as f:
f.write(generate(number_of_tests, **args))
completed_process = sp.run(
[
str(root / f"FASMARM/{executable[sys.platform]}"),
str(root / "asm/main.asm"),
str(root / "main.gba"),
]
)
if completed_process.returncode != 0 or completed_process.stderr:
raise Exception(completed_process.stderr)
print(f"Output ROM to {root / 'main.gba'}")