init
This commit is contained in:
@@ -7,6 +7,7 @@ import argparse
|
||||
import json
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
@@ -58,10 +59,27 @@ def obfuscate_coruna_7z_header(standard_7z: bytes) -> bytes:
|
||||
return bytes(out)
|
||||
|
||||
|
||||
# Match sample wires (source/sync/*.html): Method = LZMA2:13 7zAES:19.
|
||||
# py7zr defaults to LZMA2:24, which the client 7z extractor rejects (-1).
|
||||
_7Z_PACK_FILTER = "LZMA2:a=0:d=8k"
|
||||
_7Z_CACHE_TAG = b"lzma2:13\0"
|
||||
|
||||
|
||||
def _find_7z() -> str:
|
||||
for name in ("7z", "7za"):
|
||||
path = shutil.which(name)
|
||||
if path:
|
||||
return path
|
||||
raise SystemExit(
|
||||
"7z required to pack Coruna archives (LZMA2:13). Install p7zip."
|
||||
)
|
||||
|
||||
|
||||
def make_passworded_7z(member_name: str, payload: bytes, password: str) -> bytes:
|
||||
"""Build passworded 7z; cache by content so py7zr's random salt does not drift runs."""
|
||||
"""Build passworded 7z with sample-compatible LZMA2:13; cache by content."""
|
||||
cache_key = sha256_hex(
|
||||
member_name.encode("utf-8")
|
||||
_7Z_CACHE_TAG
|
||||
+ member_name.encode("utf-8")
|
||||
+ b"\0"
|
||||
+ password.encode("utf-8")
|
||||
+ b"\0"
|
||||
@@ -72,13 +90,33 @@ def make_passworded_7z(member_name: str, payload: bytes, password: str) -> bytes
|
||||
if cache_path.is_file():
|
||||
return cache_path.read_bytes()
|
||||
|
||||
seven = _find_7z()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
member = root / member_name
|
||||
# Keep archive member name flat (basename only) like original wires.
|
||||
arc_name = Path(member_name).name
|
||||
member = root / arc_name
|
||||
member.write_bytes(payload)
|
||||
archive = root / "out.7z"
|
||||
with py7zr.SevenZipFile(archive, mode="w", password=password) as handle:
|
||||
handle.write(member, arcname=member_name)
|
||||
cmd = [
|
||||
seven,
|
||||
"a",
|
||||
"-t7z",
|
||||
f"-m0={_7Z_PACK_FILTER}",
|
||||
"-mhe=on",
|
||||
f"-p{password}",
|
||||
"-y",
|
||||
"-bso0",
|
||||
"-bsp0",
|
||||
str(archive),
|
||||
str(member),
|
||||
]
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if proc.returncode != 0 or not archive.is_file():
|
||||
detail = (proc.stderr or proc.stdout or "").strip()
|
||||
raise RuntimeError(
|
||||
f"7z pack failed (code {proc.returncode}): {detail or 'no output'}"
|
||||
)
|
||||
data = archive.read_bytes()
|
||||
|
||||
try:
|
||||
@@ -247,6 +285,7 @@ def main() -> int:
|
||||
|
||||
hashes: dict[str, tuple[str, int]] = {}
|
||||
rebuilt_wires: list[str] = []
|
||||
core_path_patch_meta: dict | None = None
|
||||
|
||||
for mod in modules:
|
||||
wire = mod["wire"]
|
||||
@@ -286,6 +325,16 @@ def main() -> int:
|
||||
expect_hits=expect,
|
||||
label=label,
|
||||
)
|
||||
if wire == "erupt_flee.js":
|
||||
data, core_path_patch_meta = patch_initial_daily_path(
|
||||
data,
|
||||
channel,
|
||||
label=label,
|
||||
)
|
||||
print(
|
||||
f"path-patched {wire}: {core_path_patch_meta.get('path')} "
|
||||
f"(container={core_path_patch_meta.get('container', 'thin')})"
|
||||
)
|
||||
digest = sha256_hex(data)
|
||||
size = len(data)
|
||||
hashes[wire] = (digest, size)
|
||||
@@ -336,6 +385,7 @@ def main() -> int:
|
||||
"reporting_domains": rep_domains,
|
||||
"daily_path": f"/channel/{channel}/sync/daily.html",
|
||||
"sync_path_prefix": f"/channel/{channel}/sync/",
|
||||
"initial_daily_path_patch": core_path_patch_meta,
|
||||
}
|
||||
(out / "MANIFEST.json").write_text(json.dumps(manifest, indent=2) + "\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user