#!/usr/bin/env python3
# inspect_dat.py - phan tich blob cau hinh bshield
import os, math, collections

FILES = [
    r"vn.gsm.md_6473405044_3.15.0_DecryptIPA_by_TTJB\Payload\Driver.app\bshield.dat",
    r"vn.gsm.md_6473405044_3.15.0_DecryptIPA_by_TTJB\Payload\Driver.app\bxcmkwqraozxcpwq.dat",
    r"vn.gsm.md_6473405044_3.15.0_DecryptIPA_by_TTJB\Payload\Driver.app\build-info.dat",
]

NEEDLES = [b"http", b"xanhsm", b"b.", b"app_type", b"code", b"deviceId", b"://"]

def entropy(b):
    if not b:
        return 0
    cnt = collections.Counter(b)
    n = len(b)
    return -sum((c / n) * math.log2(c / n) for c in cnt.values())

for p in FILES:
    if not os.path.exists(p):
        continue
    d = open(p, "rb").read()
    print(f"\n=== {os.path.basename(p)}  {len(d)} bytes  entropy={entropy(d[:4096]):.2f}")
    print("  head:", d[:48].hex(" "))
    print("  ascii:", "".join(chr(c) if 32 <= c < 127 else "." for c in d[:120]))
    # thu XOR 1 byte
    found = []
    for k in range(1, 256):
        dec = bytes(b ^ k for b in d[:8192])
        if b"http" in dec or b"xanhsm" in dec:
            i = dec.find(b"http") if b"http" in dec else dec.find(b"xanhsm")
            found.append((k, dec[max(0, i - 20):i + 80]))
    if found:
        print("  XOR hits:")
        for k, frag in found[:3]:
            print(f"    key={k:#04x}: {frag}")
    else:
        print("  no single-byte XOR hit in first 8 KB")
