kopia lustrzana https://github.com/fagci/qs-uvk5-firmware-modder
cleanup; feat: searcher
rodzic
e56e56dcd2
commit
ef337508c5
10
encdec.py
10
encdec.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from binascii import crc_hqx
|
from binascii import crc_hqx as crc16
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -13,8 +13,8 @@ from sys import stderr
|
||||||
|
|
||||||
KEY = Path('./key.bin').read_bytes()
|
KEY = Path('./key.bin').read_bytes()
|
||||||
|
|
||||||
V_OFFSET = 8192
|
V_START = 8192
|
||||||
V_LEN = 16
|
V_END = V_START + 16
|
||||||
CRC_LEN = 2
|
CRC_LEN = 2
|
||||||
|
|
||||||
def eprint(*args, **kwargs):
|
def eprint(*args, **kwargs):
|
||||||
|
@ -27,13 +27,13 @@ def xor(var):
|
||||||
|
|
||||||
def decrypt(data):
|
def decrypt(data):
|
||||||
decrypted = xor(data)
|
decrypted = xor(data)
|
||||||
eprint('version:', decrypted[V_OFFSET:V_OFFSET+V_LEN].decode())
|
eprint('version:', decrypted[V_START:V_END].decode())
|
||||||
return decrypted[:-CRC_LEN]
|
return decrypted[:-CRC_LEN]
|
||||||
|
|
||||||
|
|
||||||
def encrypt(data):
|
def encrypt(data):
|
||||||
encrypted = xor(data)
|
encrypted = xor(data)
|
||||||
checksum = crc_hqx(encrypted, 0).to_bytes(2, byteorder='little')
|
checksum = crc16(encrypted, 0).to_bytes(2, 'little')
|
||||||
return encrypted + checksum
|
return encrypted + checksum
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
V_START = 8192
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(argv) != 3:
|
||||||
|
print(f'Usage: {argv[0]} <search_string> decrypted_file.bin')
|
||||||
|
exit(128)
|
||||||
|
|
||||||
|
search_for = argv[1].encode()
|
||||||
|
data = Path(argv[2]).read_bytes()
|
||||||
|
|
||||||
|
if data[V_START:V_START+4] != b'2.01':
|
||||||
|
print('Encrypted file, choose decrypted.')
|
||||||
|
exit(200)
|
||||||
|
|
||||||
|
search_for_len = len(search_for)
|
||||||
|
|
||||||
|
for i in range(len(data)):
|
||||||
|
if data[i:i+search_for_len] == search_for:
|
||||||
|
print(f'[{i}]: {data[i:i+32]}')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Ładowanie…
Reference in New Issue