-
Notifications
You must be signed in to change notification settings - Fork 0
/
replacer.py
32 lines (25 loc) · 854 Bytes
/
replacer.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
import sys
import os
ssid = b"J" * 31 + b"\0"
pwd = b"K" * 63 + b"\0"
null = b"\0"
new_ssid = os.environ.get("SSID")
new_pwd = os.environ.get("PASS")
if not new_ssid or not new_pwd:
print("You must set the 'SSID' and 'PASS' environment variables when generating this firmware file")
sys.exit(1)
new_ssid = new_ssid.encode()
new_pwd = new_pwd.encode()
with open(sys.argv[1], "rb+") as fd:
fdata = fd.read()
new_ssid = new_ssid + (len(ssid) - len(new_ssid)) * null
new_pwd = new_pwd + (len(pwd) - len(new_pwd)) * null
assert len(new_ssid) == len(ssid)
assert len(new_pwd) == len(pwd)
new_fdata = fdata.replace(ssid, new_ssid).replace(pwd, new_pwd)
assert new_ssid in new_fdata
assert new_pwd in new_fdata
assert ssid not in new_fdata
assert pwd not in new_fdata
fd.seek(0)
fd.write(new_fdata)