1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import zlib import sys import os
def decompress_krc(krc_bytes): enc_key = bytearray([64, 71, 97, 119, 94, 50, 116, 71, 81, 54, 49, 45, 206, 210, 110, 105])
content_bytes = krc_bytes[4:] compressed_bytes = []
for i in range(0, len(content_bytes)): compressed_bytes.append(content_bytes[i] ^ enc_key[i % 16])
return zlib.decompress(bytearray(compressed_bytes))
if len(sys.argv) != 2: print('usage : parse_krc <krc path>') sys.exit(0)
filename = sys.argv[1] target_filename = os.path.splitext(filename)[0] + '_plaintext.krc'
with open(filename, 'rb') as f: plaintext_bytes = decompress_krc(bytearray(f.read()))
fp = open(target_filename, 'wb') fp.write(plaintext_bytes) fp.close()
plaintext = plaintext_bytes.decode('utf-8') print(plaintext)
|