cleanup; feat: searcher

modder2
Mikhail Yudin 2023-05-16 23:32:14 +07:00
rodzic e56e56dcd2
commit ef337508c5
2 zmienionych plików z 32 dodań i 5 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
#!/usr/bin/env python3
from binascii import crc_hqx
from binascii import crc_hqx as crc16
from itertools import cycle
import os
from pathlib import Path
@ -13,8 +13,8 @@ from sys import stderr
KEY = Path('./key.bin').read_bytes()
V_OFFSET = 8192
V_LEN = 16
V_START = 8192
V_END = V_START + 16
CRC_LEN = 2
def eprint(*args, **kwargs):
@ -27,13 +27,13 @@ def xor(var):
def decrypt(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]
def encrypt(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

27
searcher.py 100644
Wyświetl plik

@ -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()