-
Notifications
You must be signed in to change notification settings - Fork 91
/
patch.sh
executable file
·367 lines (344 loc) · 12.4 KB
/
patch.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/sh
set -eo pipefail;
shopt -s nullglob;
#variables
bin_file="synocodectool"
conf_file="activation.conf"
conf_path="/usr/syno/etc/codec"
conf_string='{"success":true,"activated_codec":["hevc_dec","ac3_dec","h264_dec","h264_enc","aac_dec","aac_enc","mpeg4part2_dec","vc1_dec","vc1_enc"],"token":"123456789987654abc"}'
opmode="patchhelp"
#arrays
declare -A binhash_version_list=(
["cde88ed8fdb2bfeda8de52ef3adede87a72326ef"]="6.0-7321-0_6.0.3-8754-8"
["ec0c3f5bbb857fa84f5d1153545d30d7b408520b"]="6.1-15047-0_6.1.1-15101-4"
["1473d6ad6ff6e5b8419c6b0bc41006b72fd777dd"]="6.1.2-15132-0_6.1.3-15152-8"
["26e42e43b393811c176dac651efc5d61e4569305"]="6.1.4-15217-0_6.2-23739-2"
["1d01ee38211f21c67a4311f90315568b3fa530e6"]="6.2.1-23824-0_6.2.3-25423-0"
)
declare -A patchhash_binhash_list=(
["e5c1a65b3967968560476fcda5071fd37db40223"]="cde88ed8fdb2bfeda8de52ef3adede87a72326ef"
["d58f5b33ff2b6f2141036837ddf15dd5188384c6"]="ec0c3f5bbb857fa84f5d1153545d30d7b408520b"
["56ca9adaf117e8aae9a3a2e29bbcebf0d8903a99"]="1473d6ad6ff6e5b8419c6b0bc41006b72fd777dd"
["511dec657daa60b0f11da20295e2c665ba2c749c"]="26e42e43b393811c176dac651efc5d61e4569305"
["93067026c251b100e27805a8b4b9d8f0ae8e291c"]="1d01ee38211f21c67a4311f90315568b3fa530e6"
)
declare -A binhash_patch_list=(
["cde88ed8fdb2bfeda8de52ef3adede87a72326ef"]="00002dc0: 27000084c0eb4cb9b6000000badd6940\n00003660: 24f0000000e8961e000084c00f84b400"
["ec0c3f5bbb857fa84f5d1153545d30d7b408520b"]="00002dc0: 27000084c0eb4cb9b7000000bafd6940\n000036f0: 0000e8291e000084c0eb1eb9ec000000"
["1473d6ad6ff6e5b8419c6b0bc41006b72fd777dd"]="00002dc0: 27000084c0eb4cb9b7000000baad6a40\n000036f0: 0000e8291e000084c0eb1eb9ec000000"
["26e42e43b393811c176dac651efc5d61e4569305"]="00002dc0: 27000084c0eb4cb9ba000000badf6a40\n00003710: f0000000e8271e000084c0eb1eb9ef00"
["1d01ee38211f21c67a4311f90315568b3fa530e6"]="00002dc0: 27000084c0eb4cb9bd000000baf76a40\n00003720: 24f0000000e8261e000084c0eb1eb9f2"
)
declare -a binpath_list=()
declare -a path_list=(
"/usr/syno/bin"
"/volume1/@appstore/VideoStation/bin"
)
declare -a versions_list=(
"6.0 7321-0"
"6.0 7321-1"
"6.0 7321-2"
"6.0 7321-3"
"6.0 7321-4"
"6.0 7321-5"
"6.0 7321-6"
"6.0 7321-7"
"6.0.1 7393-0"
"6.0.1 7393-1"
"6.0.1 7393-2"
"6.0.2 8451-0"
"6.0.2 8451-1"
"6.0.2 8451-2"
"6.0.2 8451-3"
"6.0.2 8451-4"
"6.0.2 8451-5"
"6.0.2 8451-6"
"6.0.2 8451-7"
"6.0.2 8451-8"
"6.0.2 8451-9"
"6.0.2 8451-10"
"6.0.2 8451-11"
"6.0.3 8754-0"
"6.0.3 8754-1"
"6.0.3 8754-2"
"6.0.3 8754-3"
"6.0.3 8754-4"
"6.0.3 8754-5"
"6.0.3 8754-6"
"6.0.3 8754-7"
"6.0.3 8754-8"
"6.1 15047-0"
"6.1 15047-1"
"6.1 15047-2"
"6.1.1 15101-0"
"6.1.1 15101-1"
"6.1.1 15101-2"
"6.1.1 15101-3"
"6.1.1 15101-4"
"6.1.2 15132-0"
"6.1.2 15132-1"
"6.1.3 15152-0"
"6.1.3 15152-1"
"6.1.3 15152-2"
"6.1.3 15152-3"
"6.1.3 15152-4"
"6.1.3 15152-5"
"6.1.3 15152-6"
"6.1.3 15152-7"
"6.1.3 15152-8"
"6.1.4 15217-0"
"6.1.4 15217-1"
"6.1.4 15217-2"
"6.1.4 15217-3"
"6.1.4 15217-4"
"6.1.4 15217-5"
"6.1.4 15217-0"
"6.1.5 15254-0"
"6.1.5 15254-1"
"6.1.6 15266-0"
"6.1.6 15266-1"
"6.1.7 15284-0"
"6.1.7 15284-1"
"6.1.7 15284-2"
"6.1.7 15284-3"
"6.2 23739-0"
"6.2 23739-1"
"6.2 23739-2"
"6.2.1 23824-0"
"6.2.1 23824-1"
"6.2.1 23824-2"
"6.2.1 23824-3"
"6.2.1 23824-4"
"6.2.1 23824-5"
"6.2.1 23824-6"
"6.2.2 24922-0"
"6.2.2 24922-1"
"6.2.2 24922-2"
"6.2.2 24922-3"
"6.2.2 24922-4"
"6.2.2 24922-5"
"6.2.2 24922-6"
"6.2.3 25423-0"
)
#functions
print_usage() {
printf "
SYNOPSIS
patch.sh [-h] [-p|-r|-l]
DESCRIPTION
Patch to enable transcoding without a valid serial in DSM 6+
-h Print this help message
-p Patch synocodectool
-r Restore from original from backup
-l List supported DSM versions
"
}
check_path () {
for i in "${path_list[@]}"; do
if [ -e "$i/$bin_file" ]; then
binpath_list+=( "$i/$bin_file" )
fi
done
}
check_version () {
local ver="$1"
for i in "${versions_list[@]}" ; do
[[ "$i" == "$ver" ]] && return 0
done || return 1
}
list_versions () {
for i in "${versions_list[@]}"; do
echo "$i"
done
return 0
}
patch_menu() {
local options=("$@")
echo "Available binaries to patch/restore:"
local PS3="Please choose which binary you want to patch/restore:"
select option in "${options[@]}" "Quit"; do
if [[ $REPLY = "$(( ${#options[@]}+1 ))" ]] ; then
echo "Goodbye"
exit 0
fi
bin_path="$option"
break
done
}
restore_menu() {
local options=("$@")
echo "Available backups to restore:"
local PS3="Please choose which binary you want to restore to $bin_path:"
select option in "${options[@]}" "Quit"; do
if [[ $REPLY = "$(( ${#options[@]}+1 ))" ]] ; then
echo "Goodbye"
exit 0
fi
backup_file="$option"
break
done
}
patch_common () {
source "/etc/VERSION"
dsm_version="$productversion $buildnumber-$smallfixnumber"
if [[ ! "$dsm_version" ]] ; then
echo "Something went wrong. Could not fetch DSM version"
exit 1
fi
echo "Detected DSM version: $dsm_version"
if ! check_version "$dsm_version" ; then
echo "Patch for DSM Version ($dsm_version) not found."
echo "Patch is available for versions: "
list_versions
exit 1
fi
echo "Patch for DSM Version ($dsm_version) AVAILABLE!"
check_path
if ! (( ${#binpath_list[@]} )) ; then
echo "Something went wrong. Could not find synocodectool"
exit 1
fi
patch_menu "${binpath_list[@]}"
}
patch () {
patch_common
local backup_path="${bin_path%??????????????}/backup"
local synocodectool_hash="$(sha1sum "$bin_path" | cut -f1 -d\ )"
if [[ "${binhash_version_list[$synocodectool_hash]+isset}" ]] ; then
local backup_identifier="${synocodectool_hash:0:8}"
if [[ -f "$backup_path/$bin_file.$backup_identifier" ]]; then
backup_hash="$(sha1sum "$backup_path/$bin_file.$backup_identifier" | cut -f1 -d\ )"
if [[ "${binhash_version_list[$backup_hash]+isset}" ]]; then
echo "Restored synocodectool and valid backup detected (DSM ${binhash_version_list[$backup_hash]}) . Patching..."
echo -e "${binhash_patch_list[$synocodectool_hash]}" | xxd -r - "$bin_path"
echo "Patched successfully"
echo "Creating spoofed activation.conf.."
if [ ! -e "$conf_path/$conf_file" ] ; then
mkdir -p $conf_path
echo "$conf_string" > "$conf_path/$conf_file"
echo "Spoofed activation.conf created successfully"
exit 0
else
rm "$conf_path/$conf_file"
echo "$conf_string" > "$conf_path/$conf_file"
echo "Spoofed activation.conf created successfully"
exit 0
fi
else
echo "Corrupted backup and original synocodectool detected. Overwriting backup..."
mkdir -p "$backup_path"
cp -p "$bin_path" \
"$backup_path/$bin_file.$backup_identifier"
exit 0
fi
else
echo "Detected valid synocodectool. Creating backup.."
mkdir -p "$backup_path"
cp -p "$bin_path" \
"$backup_path/$bin_file.$backup_identifier"
echo "Patching..."
echo -e "${binhash_patch_list[$synocodectool_hash]}" | xxd -r - "$bin_path"
echo "Patched"
echo "Creating spoofed activation.conf.."
if [ ! -e "$conf_path/$conf_file" ] ; then
mkdir -p $conf_path
echo "$conf_string" > "$conf_path/$conf_file"
echo "Spoofed activation.conf created successfully"
exit 0
else
rm "$conf_path/$conf_file"
echo "$conf_string" > "$conf_path/$conf_file"
echo "Spoofed activation.conf created successfully"
exit 0
fi
fi
elif [[ "${patchhash_binhash_list[$synocodectool_hash]+isset}" ]]; then
local original_hash="${patchhash_binhash_list[$synocodectool_hash]}"
local backup_identifier="${original_hash:0:8}"
if [[ -f "$backup_path/$bin_file.$backup_identifier" ]]; then
backup_hash="$(sha1sum "$backup_path/$bin_file.$backup_identifier" | cut -f1 -d\ )"
if [[ "$original_hash"="$backup_hash" ]]; then
echo "Valid backup and patched synocodectool detected. Skipping patch."
exit 0
else
echo "Patched synocodectool and corrupted backup detected. Skipping patch."
exit 1
fi
else
echo "Patched synocodectool and no backup detected. Skipping patch."
exit 1
fi
else
echo "Corrupted synocodectool detected. Please use the -r option to try restoring it."
exit 1
fi
}
rollback () {
patch_common
local backup_path="${bin_path%??????????????}/backup"
local synocodectool_hash="$(sha1sum "$bin_path" | cut -f1 -d\ )"
if [[ "${patchhash_binhash_list[$synocodectool_hash]+isset}" ]] ; then
local original_hash="${patchhash_binhash_list[$synocodectool_hash]}"
local backup_identifier="${original_hash:0:8}"
if [[ -e "$backup_path/$bin_file.$backup_identifier" ]] ; then
local backup_hash="$(sha1sum "$backup_path/$bin_file.$backup_identifier" | cut -f1 -d\ )"
if [[ "$original_hash" = "$backup_hash" ]]; then
cp -p "$backup_path/$bin_file.$backup_identifier" \
"$bin_path"
echo "Backup restored successfully (DSM ${binhash_version_list[$backup_hash]})"
exit 0
else
echo "No valid backup found for patched synocodectool currently in use. You can download the original file for DSM ${binhash_version_list[$original_hash]} from https://github.com/likeadoc/synocodectool-patch/."
exit 1
fi
else
echo "No backups found for patched synocodectool currently in use. You can download the original file for DSM ${binhash_version_list[$original_hash]} from https://github.com/likeadoc/synocodectool-patch/."
exit 1
fi
elif [[ "${binhash_version_list[$synocodectool_hash]+isset}" ]]; then
echo "Detected unpatched original synocodectool. Restoring not neccessary!"
exit 0
else
echo "Detected corrupted synocodectool."
local backup_files=( "$backup_path"/* )
if (( ${#backup_files[@]} )); then
restore_menu "${backup_files[@]}"
echo "Checking Hash.."
local backup_hash="$(sha1sum "$backup_file" | cut -f1 -d\ )"
if [[ "${binhash_version_list[$backup_hash]+isset}" ]]; then
cp -p "$backup_file" \
"$bin_path"
echo "Backup restored successfully (DSM ${binhash_version_list[$backup_hash]})"
exit 0
else
echo "Not a valid backup. You can either try restoring another backup or download the original file for DSM $dsm_version from https://github.com/likeadoc/synocodectool-patch/."
exit 1
fi
else
echo "No backups found. You can download the original file for DSM $dsm_version from https://github.com/likeadoc/synocodectool-patch/."
exit 1
fi
fi
}
#main()
if (( $EUID != 0 )); then
echo "Please run as root"
exit 1
fi
while getopts "prhl" flag; do
case "${flag}" in
p) opmode="patch";;
r) opmode="patchrollback" ;;
h) opmode="${opmode}" ;;
l) opmode="listversions" ;;
*) echo "Incorrect option specified in command line" ; exit 2 ;;
esac
done
case "${opmode}" in
patch) patch ;;
patchrollback) rollback ;;
patchhelp) print_usage ; exit 2 ;;
listversions) list_versions ;;
*) echo "Incorrect combination of flags. Use option -h to get help."
exit 2 ;;
esac