|
|
"""Analyze crypto_log.json to understand decrypt sequence and chunk mapping.""" |
|
|
import json |
|
|
import struct |
|
|
|
|
|
with open("temp/crypto_log.json") as f: |
|
|
log = json.load(f) |
|
|
|
|
|
decrypts = [op for op in log if op["op"] == "decrypt"] |
|
|
sha256s = [op for op in log if op["op"] == "sha256"] |
|
|
encrypts = [op for op in log if op["op"] == "encrypt"] |
|
|
|
|
|
print(f"Total ops: {len(log)} (sha256={len(sha256s)}, decrypt={len(decrypts)}, encrypt={len(encrypts)})") |
|
|
|
|
|
|
|
|
sha_map = {} |
|
|
for s in sha256s: |
|
|
sha_map[s["output"]] = s["input"] |
|
|
|
|
|
|
|
|
print("\n=== Decrypt operations with key derivation ===") |
|
|
for i, d in enumerate(decrypts): |
|
|
key = d["aes_key"] |
|
|
sha_input_hex = sha_map.get(key, "UNKNOWN") |
|
|
sha_input = bytes.fromhex(sha_input_hex) if sha_input_hex != "UNKNOWN" else b"" |
|
|
|
|
|
if len(sha_input) == 48: |
|
|
desc = "DX_KEY (master+file[8:24])" |
|
|
elif len(sha_input) == 32: |
|
|
s1, s2 = struct.unpack_from("<QQ", sha_input, 0) |
|
|
chk = sha_input[16:32].hex()[:16] + "..." |
|
|
desc = f"CHK sizes=({s1},{s2}) chk={chk}" |
|
|
elif len(sha_input) == 16: |
|
|
s1, s2 = struct.unpack_from("<QQ", sha_input, 0) |
|
|
desc = f"NOCHK sizes=({s1},{s2})" |
|
|
else: |
|
|
desc = f"len={len(sha_input)}" |
|
|
|
|
|
first = d["first_bytes"][:32] |
|
|
print(f" dec#{i:02d}: size={d['input_size']:>8}B {desc:50s} out={first}") |
|
|
|
|
|
|
|
|
dx = open("temp/dx_index_decrypted.bin", "rb").read() |
|
|
fdata = open("ocr_data/oneocr.onemodel", "rb").read() |
|
|
|
|
|
print("\n=== Locating encrypted data ===") |
|
|
for i, d in enumerate(decrypts): |
|
|
size = d["input_size"] |
|
|
first = bytes.fromhex(d["first_bytes"][:32]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dx_pos = dx.find(first) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if i == 0: |
|
|
loc = "DX index itself at file[24:]" |
|
|
elif dx_pos >= 0: |
|
|
loc = f"embedded in DX at dx_offset={dx_pos} (file_off={24+dx_pos})" |
|
|
else: |
|
|
loc = "payload (after file[22684])" |
|
|
|
|
|
print(f" dec#{i:02d}: size={size:>8}B {loc}") |
|
|
|
|
|
|
|
|
print("\n=== All size-pair patterns in DX (s2 = s1 + 24) ===") |
|
|
pairs = [] |
|
|
for off in range(0, len(dx) - 16): |
|
|
s1, s2 = struct.unpack_from("<QQ", dx, off) |
|
|
if s2 == s1 + 24 and 0 < s1 < 100_000_000 and s1 > 10: |
|
|
pairs.append((off, s1, s2)) |
|
|
print(f"Found {len(pairs)} size pairs") |
|
|
|
|
|
filtered = [] |
|
|
for p in pairs: |
|
|
if not filtered or p[0] >= filtered[-1][0] + 16: |
|
|
filtered.append(p) |
|
|
print(f"After dedup: {len(filtered)} pairs") |
|
|
for off, s1, s2 in filtered: |
|
|
|
|
|
has_chk = False |
|
|
if off >= 16: |
|
|
|
|
|
potential_chk = dx[off-16:off] |
|
|
non_zero = sum(1 for b in potential_chk if b != 0) |
|
|
has_chk = non_zero > 8 |
|
|
print(f" offset={off:>5} (0x{off:04x}): sizes=({s1}, {s2}) chk_before={'YES' if has_chk else 'no'}") |
|
|
|