#!/usr/bin/env python3 """ Verifies that all PE DLL dependencies of an executable and its bundled plugins are satisfied within the target distribution directory. Usage: verify-windows-dlls.py /path/to/dist_dir """ import os import struct import sys # Standard Windows system and runtime libraries (case-insensitive) SYSTEM_DLLS = { # Core OS & NT subsystems "ntdll.dll", "kernel32.dll", "kernelbase.dll", "user32.dll", "gdi32.dll", "gdiplus.dll", "shell32.dll", "shlwapi.dll", "ole32.dll", "oleaut32.dll", "comdlg32.dll", "comctl32.dll", "advapi32.dll", "version.dll", "ws2_32.dll", "wsock32.dll", "netapi32.dll", "userenv.dll", "winmm.dll", "uxtheme.dll", "dwmapi.dll", "imm32.dll", "crypt32.dll", "bcrypt.dll", "ncrypt.dll", "secur32.dll", "sspicli.dll", "setupapi.dll", "cfgmgr32.dll", "iphlpapi.dll", "dnsapi.dll", "rpcrt4.dll", "mpr.dll", "authz.dll", "wtsapi32.dll", "propsys.dll", "powrprof.dll", "winspool.drv", "shcore.dll", "hid.dll", # Graphics & DirectX "d3d9.dll", "d3d11.dll", "d3d12.dll", "dxgi.dll", "d2d1.dll", "dwrite.dll", "opengl32.dll", "glu32.dll", # CRT / UCRT "msvcrt.dll", "ucrtbase.dll", } def is_system_dll(name): lower = name.lower() if lower in SYSTEM_DLLS: return True if lower.startswith("api-ms-win-") or lower.startswith("ext-ms-win-"): return True return False def get_pe_imports(file_path): try: with open(file_path, "rb") as f: data = f.read() except Exception as e: print(f"Warning: could not read {file_path}: {e}", file=sys.stderr) return [] if len(data) < 0x40 or data[:2] != b"MZ": return [] pe_offset = struct.unpack_from(" len(data) or data[pe_offset:pe_offset+4] != b"PE\x00\x00": return [] magic = struct.unpack_from(" len(data): return [] import_rva, import_size = struct.unpack_from(" 5: print(f" ... and {len(users) - 5} more", file=sys.stderr) return False print(f"OK: Verified {checked_count} binaries. All external DLL imports satisfied ({len(available_dlls)} DLLs bundled).") return True def main(): if len(sys.argv) < 2: print("Usage: verify-windows-dlls.py ", file=sys.stderr) sys.exit(2) dist_dir = sys.argv[1] if not verify_dist_directory(dist_dir): sys.exit(1) if __name__ == "__main__": main()