#!/usr/bin/env python3 """查 exe 里到底嵌了哪套图标(PE 资源解析),可导出最大帧为 PNG 核对。 用途:换图标后 Windows 仍显示旧图标时,先确认「exe 里是新图标」还是「外壳图标缓存没刷」。 python tools/pe_icon.py dist/TfsExcelImporter.exe [out_256.png] """ import struct import sys import zlib def u16(d, o): return struct.unpack_from("I", len(data)) + tag + data + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)) with open(path, "wb") as f: f.write(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b"")) def dib_to_rgba(payload): bw, bh2 = struct.unpack_from(" 2 else None res = parse_resources(exe) groups = [(p, b) for p, b in res if p[0] == 14] icons = {(p[1] if len(p) > 1 else 0): b for p, b in res if p[0] == 3} print("%s: RT_GROUP_ICON=%d RT_ICON=%d" % (exe, len(groups), len(icons))) if not groups: print("!! exe 里没有图标资源(会用系统默认 exe 图标)") return for path_ids, b in groups: cnt, = struct.unpack_from("", out_png) return for size, idx, sz in frames: if size == 48: w, h, rgba = dib_to_rgba(icons[idx]) png_write(out_png, w, h, rgba) print(" 已导出 48 DIB 帧 ->", out_png) return if __name__ == "__main__": main()