-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPGPemuKeyFormatter.py
48 lines (43 loc) · 1.83 KB
/
PGPemuKeyFormatter.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
import json
import argparse
parser = argparse.ArgumentParser(description="Format the data from the json file generated by the Suota Go+ app to the secrets.c file needed for PGPemu Project ")
parser.add_argument(
"--path",
default="data.json",
type=str
)
def process_data(data):
skip_chars = 31
for key, value in data.items():
i = 0
chunk_size = 3 if key == "bluetooth" else 2
data:str = ''
while i < len(value):
beginchar ="\t" if i == 0 and key != "bluetooth" else ""
split_char = '' if key == "bluetooth" else ','
ever_char = '\n\t' if key != "bluetooth" and (i + chunk_size) % 12 == 0 and i + chunk_size < len(value) else ""
if i+chunk_size < len(value):
chunk = value[i:i + chunk_size]
data +=(beginchar +'0x' + split_char.join([chunk[j:j + 2] for j in range(0, len(chunk), 2)]) + split_char + ever_char)
else:
chunk = value[i:i + chunk_size]
data +=('0x' + split_char.join([chunk[j:j + 2] for j in range(0, len(chunk), 2)]))
i += chunk_size
if key == "bluetooth": mac = data
if key == "blob": blob = data
if key == "device": device = data
return mac,blob,device
def printsecrets(mac,blob,device):
with open("secrets.c", "w") as output_file:
output_file.write('#include "secrets.h"\n\n')
output_file.write(f"uint8_t MAC[6] = {{{mac}}};\n\n")
output_file.write(f"uint8_t BLOB[256] = {{\n{blob}\n}};\n\n")
output_file.write(f"uint8_t DEVICE_KEY[16] = {{\n{device}\n}};")
def main():
args = parser.parse_args()
with open(args.path, "r") as json_file:
data = json.load(json_file)
mac,blob,device=process_data(data)
printsecrets(mac,blob,device)
if __name__ == "__main__":
main()