decrypt_other_caches.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Decrypt the OTHER game caches (218620, 2912) and search for
  2. Encode6BitBuf Lua implementations or network protocol details.
  3. cache_218620 = 千河微变三职业 (same engine, 1844 lua)
  4. cache_2912 = unknown game (44 lua)
  5. """
  6. import sys
  7. from pathlib import Path
  8. sys.path.insert(0, str(Path(__file__).parent))
  9. from decrypt_client_lua import decrypt_file
  10. BASE = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\cq")
  11. OUT = Path("lua-dec2")
  12. for cache, label in [("cache_218620", "千河微变"), ("cache_2912", "game2912")]:
  13. src_root = BASE / cache
  14. files = list(src_root.rglob("*.lua"))
  15. print(f"=== {label} ({cache}): {len(files)} lua files ===")
  16. out_root = OUT / cache
  17. ok = 0
  18. for f in files:
  19. rel = f.relative_to(src_root)
  20. if decrypt_file(f, out_root / rel):
  21. ok += 1
  22. print(f" decrypted {ok}/{len(files)}")
  23. print()
  24. print("=== grep Encode6BitBuf in newly decrypted caches ===")
  25. for cache in ["cache_218620", "cache_2912"]:
  26. root = OUT / cache
  27. if not root.exists():
  28. continue
  29. for f in root.rglob("*.lua"):
  30. try:
  31. txt = f.read_text(encoding="utf-8", errors="replace")
  32. except Exception:
  33. continue
  34. if "Encode6BitBuf" in txt:
  35. idx = txt.find("Encode6BitBuf")
  36. # find function definition (not just call)
  37. window = txt[max(0, idx - 200) : idx + 500]
  38. if "function" in window[:250]:
  39. print(f"*** DEFINITION: {f.relative_to(OUT)} @ {idx} ***")
  40. print(window)
  41. print()
  42. else:
  43. print(f"call site: {f.relative_to(OUT)} @ {idx}")
  44. print()
  45. print("=== also grep 'function Encode' / 'Encode6' as definition ===")
  46. for f in OUT.rglob("*.lua"):
  47. try:
  48. txt = f.read_text(encoding="utf-8", errors="replace")
  49. except Exception:
  50. continue
  51. for needle in ("function Encode6", "Encode6BitBuf =", "Encode6BitBuf=function"):
  52. idx = txt.find(needle)
  53. if idx >= 0:
  54. print(f"*** {f.relative_to(OUT)} @ {idx}: {needle} ***")
  55. print(txt[idx : idx + 500])
  56. print()