Skip to content

Commit

Permalink
add a simple python script to do a better job
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiserdragon2 committed Oct 15, 2023
1 parent caa06d0 commit 713fff6
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions Lagacy(exe)/Readme.md
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.
48 changes: 48 additions & 0 deletions PGPemuKeyFormatter.py
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()
29 changes: 24 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,30 @@ to fit the needs of the PGPemu Project for the ESP32 from Yohanes Nugroho (https
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
### Command-Line Usage:

Just download the source code and open it in Code Blocks to compile it.

```
python PGPemuKeyFormatter.py --path path_to_your_data.json
```


If your JSON file is in the same directory as the script and named "data.json," you can run the script without specifying the --path option:

```
python PGPemuKeyFormatter.py
```

The script generates a file called secrets.c in the dictonary it is run.
Just replace the secrets.c file in the [pgpemu project](https://github.com/yohanes/pgpemu) with this generated one.



### Required Libraries:

Ensure that you have the argparse library available in your Python environment. If it's not installed, you can typically install it using pip:

```
pip install argparse
```

0 comments on commit 713fff6

Please sign in to comment.