"""Decode 996box env.json files and write results to decode_env_output.txt. Finds the base64 payload dynamically, handles non-UTF-8 bytes, and saves results to a file (avoids Windows console encoding issues). """ import base64 import json from pathlib import Path OUT_FILE = Path("decode_env_output.txt") SENSITIVE_KEYS = ("sign", "key", "token", "password", "pwd") def try_decode(b64_candidate: str) -> dict | None: try: padded = b64_candidate + "=" * (-len(b64_candidate) % 4) decoded = base64.urlsafe_b64decode(padded) obj = json.loads(decoded.decode("utf-8", errors="replace")) if isinstance(obj, dict): return obj except Exception: return None return None def show(path: Path, lines: list[str]) -> None: lines.append(f"=== {path} ===") if not path.exists(): lines.append(" not found") lines.append("") return raw = path.read_bytes() lines.append(f" size: {len(raw)} bytes") # Show first 40 bytes as hex + repr to handle non-UTF-8 lines.append(f" first 40 bytes (hex): {raw[:40].hex()}") lines.append(f" first 40 bytes (repr): {raw[:40]!r}") text = raw.decode("utf-8", errors="replace") # Find base64 payload start (MeyJ = base64url of '{"') for marker_idx, marker in enumerate(("MeyJ", "eyJ", "{")): idx = text.find(marker) if idx < 0: continue b64 = text[idx:].rstrip() if marker == "{": # Try raw JSON parse try: obj = json.loads(b64) if isinstance(obj, dict): lines.append(f" parsed as raw JSON from position {idx}") lines.append(f" keys: {list(obj.keys())}") for k, v in obj.items(): is_sensitive = any(s in k.lower() for s in SENSITIVE_KEYS) if is_sensitive and isinstance(v, str): lines.append(f" {k}: ***REDACTED*** (len={len(v)})") else: sv = str(v) display = sv[:120] + ("..." if len(sv) > 120 else "") lines.append(f" {k}: {display}") lines.append("") return except Exception: pass else: obj = try_decode(b64) if obj is not None: lines.append(f" decoded via base64url from position {idx} ({len(b64)} chars)") lines.append(f" decoded keys: {list(obj.keys())}") for k, v in obj.items(): is_sensitive = any(s in k.lower() for s in SENSITIVE_KEYS) if is_sensitive and isinstance(v, str): lines.append(f" {k}: ***REDACTED*** (len={len(v)})") else: sv = str(v) display = sv[:120] + ("..." if len(sv) > 120 else "") lines.append(f" {k}: {display}") lines.append("") return # Last resort: show the raw text truncated lines.append(" could not decode; raw text (truncated):") lines.append(f" {text[:200]!r}") lines.append("") def main() -> int: lines: list[str] = [] lines.append("996box env.json decoder output") lines.append("=" * 60) lines.append("") for path_str in [ r"D:\ProgramFiles\996box\GameBoxDownload\1\env.json", r"D:\ProgramFiles\996box\GameBoxDownload\1\cq\env.json", ]: show(Path(path_str), lines) OUT_FILE.write_text("\n".join(lines), encoding="utf-8") print(f"output written to: {OUT_FILE.resolve()}") print(f"file size: {OUT_FILE.stat().st_size} bytes") return 0 if __name__ == "__main__": import sys sys.exit(main())