#!/usr/bin/env python3 """Require RT_ICON and RT_GROUP_ICON inside a PE, not a sibling .ico file.""" import struct import sys import zipfile RT_ICON = 3 RT_GROUP_ICON = 14 def pe_has_icon(data: bytes) -> None: if data[:2] != b"MZ": raise SystemExit("executable does not start with MZ") e_lfanew = struct.unpack_from(" int: for va, rawptr, span in sections: if va <= rva < va + span: return rawptr + (rva - va) raise SystemExit(f"resource RVA {rva:#x} is outside the sections") off = rva_to_off(res_rva) nnames, nids = struct.unpack_from(" None: path = sys.argv[1] if path.endswith(".zip"): with zipfile.ZipFile(path) as archive: names = archive.namelist() loose = [name for name in names if name.lower().endswith(".ico")] if loose: raise SystemExit(f"zip carries a loose icon file: {loose}") exe_name = "paperdoll-renderer.exe" if exe_name not in names: raise SystemExit("zip has no paperdoll-renderer.exe") pe_has_icon(archive.read(exe_name)) else: with open(path, "rb") as handle: pe_has_icon(handle.read()) print(f"embedded icon ok: {path}") if __name__ == "__main__": main()