Skip to content

Commit 6ff0031

Browse files
joemilbournmach327
authored andcommitted
Stop md380-dfu uploading .rdt codeplug as raw
Prevent md380-dfu uploading an .rdt codeplug as raw if the file size or magic are not what's expected, warn and exit instead.
1 parent 5dcbf62 commit 6ff0031

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

md380_dfu.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,25 @@ def main():
418418
data = f.read()
419419
f.close()
420420

421+
firmware = None
422+
421423
if sys.argv[2][-4:] == '.dfu':
422424
suf_len, vendor, product = dfu_suffix.check_suffix(data)
423425
dfu = init_dfu()
424426
firmware = data[:-suf_len]
425-
elif sys.argv[2][-4:] == '.rdt' and len(data) == 262709 and data[0:5] == 'DfuSe':
426-
dfu = init_dfu()
427-
firmware = data[549:len(data) - 16]
427+
elif sys.argv[2][-4:] == '.rdt':
428+
if len(data) == 262709 and data[0:5] == 'DfuSe':
429+
dfu = init_dfu()
430+
firmware = data[549:len(data) - 16]
431+
else:
432+
print('%s not a valid codeplug (wrong size, or wrong magic).' % sys.argv[2])
428433
else:
429434
dfu = init_dfu()
430435
firmware = data
431436

432-
download_codeplug(dfu, firmware)
433-
print('Write complete')
437+
if firmware is not None:
438+
download_codeplug(dfu, firmware)
439+
print('Write complete')
434440

435441
elif sys.argv[1] == 'sign':
436442
filename = sys.argv[2]

0 commit comments

Comments
 (0)