-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a simple python script to do a better job
- Loading branch information
1 parent
caa06d0
commit 713fff6
Showing
10 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# PGPemuKeyFormatter | ||
This tool is used to format the data provided by the "Suota Go+" app from Jesus Bamford (https://github.com/Jesus805/Suota-Go-Plus) | ||
to fit the needs of the PGPemu Project for the ESP32 from Yohanes Nugroho (https://github.com/yohanes/pgpemu). | ||
To Download the SuotaGo+ App: https://github.com/Jesus805/Suota-Go-Plus/releases/tag/v1.0 | ||
|
||
## How to use | ||
Copy the Mac, blob and device key from the json file into the separte files(rawmac.txt; rawblob.txt; rawkey.txt) for each one (without the brackets "{}"). | ||
Then just run PGPemuKeyFormatter.exe. | ||
The formatted data could be found in the three new files (mac.txt; bloob.txt; key.txt). | ||
|
||
### To build the project on your own | ||
|
||
Just download the source code and open it in Code Blocks to compile it. | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters