Files
ansible_fencl/scripts/stage_webmap.py
T

22 lines
893 B
Python

#!/usr/bin/env python3
"""Inspect pinned-version Thunderstore ZIP, stage just the plugin DLL, no traversal."""
import hashlib
import sys
import zipfile
from pathlib import Path
archive, output = Path(sys.argv[1]), Path(sys.argv[2])
with zipfile.ZipFile(archive) as z:
names = [name for name in z.namelist() if name.replace('\\', '/').endswith('plugins/ValheimWebMap/ValheimWebMap.dll')]
if len(names) != 1:
raise SystemExit(f"Expected exactly one plugins/ValheimWebMap/ValheimWebMap.dll; found {len(names)}")
info = z.getinfo(names[0])
if info.file_size <= 0 or info.file_size > 10 * 1024 * 1024:
raise SystemExit("Unexpected DLL size")
data = z.read(info)
if not data.startswith(b'MZ'):
raise SystemExit("Invalid DLL/PE header")
output.parent.mkdir(parents=True, exist_ok=True)
output.write_bytes(data)
print(hashlib.sha256(data).hexdigest())