2023-06-03 02:55:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-06-03 03:21:31 +00:00
|
|
|
import os
|
2023-06-03 02:55:17 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from sys import argv
|
|
|
|
from configparser import ConfigParser
|
|
|
|
|
2023-06-10 16:49:58 +00:00
|
|
|
from uvk5 import decrypt, encrypt, eprint
|
2023-06-03 02:55:17 +00:00
|
|
|
|
|
|
|
ADDR_DIR = Path(__file__).parent / 'addresses'
|
2023-06-03 03:21:31 +00:00
|
|
|
MODS_DIR = Path(__file__).parent / 'mods'
|
2023-06-03 02:55:17 +00:00
|
|
|
|
|
|
|
def main(encrypted_file_path):
|
|
|
|
file_bytes = Path(encrypted_file_path).read_bytes()
|
|
|
|
decrypted, version = decrypt(file_bytes)
|
|
|
|
eprint('version:', version)
|
|
|
|
|
|
|
|
addr_file = ADDR_DIR / ('%s.ini' % version)
|
2023-06-03 03:21:31 +00:00
|
|
|
mods_file = MODS_DIR / ('%s.ini' % version)
|
|
|
|
|
2023-06-03 02:55:17 +00:00
|
|
|
addresses = ConfigParser()
|
2023-06-03 03:21:31 +00:00
|
|
|
mods = ConfigParser()
|
2023-06-03 02:55:17 +00:00
|
|
|
addresses.read(addr_file)
|
2023-06-03 03:21:31 +00:00
|
|
|
mods.read(mods_file)
|
|
|
|
|
|
|
|
|
|
|
|
for section_name in addresses:
|
|
|
|
eprint('[%s]' % section_name)
|
|
|
|
section_values = addresses[section_name]
|
|
|
|
for k in section_values:
|
|
|
|
addr = int(section_values.get(k), 16)
|
|
|
|
value = int.from_bytes(decrypted[addr:addr+4], 'little')
|
|
|
|
eprint(k, addr, value)
|
|
|
|
|
|
|
|
if mods[section_name] and mods[section_name].get(k):
|
|
|
|
new_value = mods[section_name].get(k)
|
|
|
|
eprint('new:', new_value)
|
|
|
|
decrypted = decrypted[:addr] + int(new_value).to_bytes(4, 'little') + decrypted[addr+4:]
|
|
|
|
|
|
|
|
encrypted = encrypt(decrypted, version)
|
2023-06-03 03:37:40 +00:00
|
|
|
|
|
|
|
if len(file_bytes) != len(encrypted):
|
|
|
|
eprint('Something goes wrong. Check values or open issue.')
|
|
|
|
exit(255)
|
|
|
|
|
2023-06-03 03:21:31 +00:00
|
|
|
os.write(1, encrypted)
|
2023-06-03 02:55:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(argv[1])
|