-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake.sh
executable file
·213 lines (176 loc) · 4.71 KB
/
make.sh
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
MISC_DIR="$SCRIPT_DIR/misc"
PATCH_DIR="$SCRIPT_DIR/patch"
STAGE1_DIR="$SCRIPT_DIR/stage1"
PAYLOAD_DIR="$SCRIPT_DIR/payload"
EXPLOIT_DIR="$SCRIPT_DIR/exploit"
DIST_DIR="$SCRIPT_DIR/dist"
function print_help {
echo \
"wfc-patcher-wii build script
Usage: make.sh [OPTIONS] -- [ADITIONAL ARGS]
Options:
--clean Remove 'dist' and build artifacts in 'patch', 'stage1', and 'payload'
--clean-keys Remove keys in 'misc'
--keys Generate new keys in 'misc', copying the public key to 'include'
--patch Generate patches
--stage1 Build stage1
--payload Build payloads
--exploit Build exploit
--all Builds payloads, stage1, and patches. Makes keys if none are present.
-h|--help Print this message and exit.
Note:
* Anything after '--' will be passed to the individual build scripts (except for --keys), such as -j8 to specify thread count.
* The files that make up the 'payload' directory of wfc-server will be placed in the 'dist' directory adjacent to the script.
"
exit 1
}
function check_keys {
if ! [ -e "$SCRIPT_DIR/misc/private-key-OUT.pem" ]; then
return 1
fi
return 0
}
function remove_keys {
echo "Removing old keys!"
if [ -e "$MISC_DIR/private-key-OUT.pem" ]; then
echo "Removing private key"
rm "$MISC_DIR/private-key-OUT.pem"
fi
if [ -e "$MISC_DIR/wwfcPayloadPublicKey-OUT.hpp" ]; then
echo "Removing public key"
rm "$MISC_DIR/wwfcPayloadPublicKey-OUT.hpp"
fi
}
if [ $# -eq 0 ]; then
>&2 echo "No arguments provided"
print_help
fi
clean=false
clean_keys=false
try_make_keys=false
keys=false
patch=false
stage1=false
payload=false
exploit=false
args=""
while [[ $# -gt 0 ]]; do
case "$1" in
--clean)
clean=true
;;
--clean-keys)
clean_keys=true
;;
--all)
patch=true
stage1=true
payload=true
try_make_keys=true
;;
--keys)
keys=true
;;
--patch)
patch=true
;;
--stage1)
stage1=true
;;
--payload)
payload=true
;;
--exploit)
exploit=true
;;
--)
shift
args="$*"
break
;;
-h | --help)
print_help
;;
*)
echo -e "Bad option: $1\n"
print_help
;;
esac
shift
done
if $clean; then
if [ -d "$DIST_DIR" ]; then
echo "Removing dist"
rm -r "$DIST_DIR"
fi
if [ -d "$PATCH_DIR/build" ]; then
echo "Cleaning $PATCH_DIR"
rm -r "$PATCH_DIR/build"
fi
if [ -d "$STAGE1_DIR/build" ]; then
echo "Cleaning $STAGE1_DIR"
rm -r "$STAGE1_DIR/build"
fi
if [ -d "$PAYLOAD_DIR/build" ]; then
echo "Removing $PAYLOAD_DIR/build"
rm -r "$PAYLOAD_DIR/build"
fi
if [ -d "$PAYLOAD_DIR/binary" ]; then
echo "Removing $PAYLOAD_DIR/binary"
rm -r "$PAYLOAD_DIR/binary"
fi
if [ -d "$EXPLOIT_DIR/build" ]; then
echo "Cleaning $EXPLOIT_DIR"
rm -r "$EXPLOIT_DIR/build"
fi
fi
if $clean_keys; then
remove_keys
fi
mkdir -p "$DIST_DIR"
if $keys || ( (! check_keys) && $try_make_keys); then
remove_keys
cd "$MISC_DIR"
echo "Creating new keys!"
python generate-key.py new private-key-OUT.pem wwfcPayloadPublicKey-OUT.hpp
echo "Copying wwfcPayloadPublicKey-OUT.hpp to $SCRIPT_DIR/include/wwfcPayloadPublicKey.hpp"
cp "$MISC_DIR/wwfcPayloadPublicKey-OUT.hpp" "$SCRIPT_DIR/include/wwfcPayloadPublicKey.hpp"
echo "Copying private-key-OUT.pem to dist"
cp "$MISC_DIR/private-key-OUT.pem" "$DIST_DIR/private-key.pem"
fi
if $payload || $stage1 || $patch; then
if ! check_keys; then
echo "$SCRIPT_DIR/misc/private-key-OUT.pem not found! Please generate keys using '--keys' before attempting to build anything else"
exit 1
fi
fi
if $payload; then
cd "$PAYLOAD_DIR"
echo "Making payloads!"
python make-payload.py $args
if [ -e "$SCRIPT_DIR/dist/binary" ]; then
rm -r "$SCRIPT_DIR/dist/binary"
fi
echo "Copying payloads to dist!"
cp -r "$SCRIPT_DIR/payload/binary/" "$SCRIPT_DIR/dist/binary"
fi
if $stage1; then
cd "$STAGE1_DIR"
echo "Making stage1!"
python make-stage1.py $args
echo "Copying stage1.bin to dist!"
cp "$SCRIPT_DIR/stage1/build/stage1.bin" "$SCRIPT_DIR/dist/stage1.bin"
fi
if $patch; then
cd "$PATCH_DIR"
echo -e "Generating patches!"
python make-patch.py $args
fi
if $exploit; then
cd "$EXPLOIT_DIR"
echo -e "Making exploit!"
python make-sbcm-patch.py $args
fi