# Shared by package-windows.ps1 and verify-windows-package.ps1 (ADR-0086). # Windows PowerShell 5.1 compatible; no Visual Studio needed for verification. Set-StrictMode -Version Latest # Exact package content (relative paths). Anything else fails packaging/verification. $script:PackageFiles = @( 'BUILD-INFO.txt', 'LICENSES/Apache-2.0.txt', 'LICENSES/DearImGui-FONTS.md', 'LICENSES/DearImGui-embedded-fonts.txt', 'LICENSES/DearImGui-stb.txt', 'LICENSES/DearImGui.txt', 'LICENSES/Khronos.txt', 'LICENSES/MbedTLS.txt', 'LICENSES/SDL3-hidapi.txt', 'LICENSES/SDL3-stb_image.txt', 'LICENSES/SDL3-yuv2rgb.txt', 'LICENSES/SDL3.txt', 'README.txt', 'SDL3.dll', 'SHA256SUMS.txt', 'THIRD-PARTY-NOTICES.txt', 'evo-client.exe' ) # Imports allowed for the executables: Windows system DLLs and the bundled SDL3.dll. # The C/C++ runtime is static (no MSVCP/VCRUNTIME/api-ms-win-crt/ucrtbase). $script:AllowedImports = @( 'advapi32.dll', 'bcrypt.dll', 'gdi32.dll', 'imm32.dll', 'kernel32.dll', 'ole32.dll', 'oleaut32.dll', 'sdl3.dll', 'setupapi.dll', 'shell32.dll', 'user32.dll', 'version.dll', 'winmm.dll', 'ws2_32.dll' ) function Get-Sha256([string]$Path) { (Get-FileHash -Algorithm SHA256 -LiteralPath $Path).Hash.ToLowerInvariant() } function Get-RelativeFiles([string]$Root) { $prefix = (Resolve-Path -LiteralPath $Root).Path.TrimEnd('\') + '\' Get-ChildItem -LiteralPath $Root -Recurse -File -Force | ForEach-Object { $_.FullName.Substring($prefix.Length).Replace('\', '/') } | Sort-Object -CaseSensitive } # Names of DLLs in the import and delay-import tables of a PE32+ image. function Get-PeImports([string]$Path) { $bytes = [IO.File]::ReadAllBytes($Path) $pe = [BitConverter]::ToInt32($bytes, 0x3C) if ([BitConverter]::ToUInt32($bytes, $pe) -ne 0x4550) { throw "Not a PE image: $Path" } $sections = [BitConverter]::ToUInt16($bytes, $pe + 6) $optionalSize = [BitConverter]::ToUInt16($bytes, $pe + 20) $optional = $pe + 24 if ([BitConverter]::ToUInt16($bytes, $optional) -ne 0x20B) { throw "Not PE32+ (x64): $Path" } $table = $optional + $optionalSize $toOffset = { param([uint32]$rva) for ($i = 0; $i -lt $sections; ++$i) { $s = $table + 40 * $i $size = [Math]::Max([BitConverter]::ToUInt32($bytes, $s + 8), [BitConverter]::ToUInt32($bytes, $s + 16)) $address = [BitConverter]::ToUInt32($bytes, $s + 12) if ($rva -ge $address -and $rva -lt $address + $size) { return [int]($rva - $address + [BitConverter]::ToUInt32($bytes, $s + 20)) } } throw "RVA outside sections in $Path" } $readName = { param([uint32]$rva) $start = & $toOffset $rva $end = [Array]::IndexOf($bytes, [byte]0, $start) [Text.Encoding]::ASCII.GetString($bytes, $start, $end - $start) } $names = New-Object System.Collections.Generic.List[string] # Data directories start at optional+112 (PE32+): [1] imports, [13] delay imports. foreach ($entry in @(@{ Index = 1; Stride = 20; Name = 12 }, @{ Index = 13; Stride = 32; Name = 4 })) { $rva = [BitConverter]::ToUInt32($bytes, $optional + 112 + 8 * $entry.Index) if ($rva -eq 0) { continue } $at = & $toOffset $rva $n = 0 while ($true) { if (++$n -gt 4096) { throw "Unterminated import table in $Path" } $nameRva = [BitConverter]::ToUInt32($bytes, $at + $entry.Name) if ($nameRva -eq 0) { break } $names.Add((& $readName $nameRva).ToLowerInvariant()) $at += $entry.Stride } } $names | Sort-Object -Unique } function Assert-AllowedImports([string]$Path) { foreach ($name in (Get-PeImports $Path)) { if ($script:AllowedImports -notcontains $name) { throw "$([IO.Path]::GetFileName($Path)) imports $name, which is not an allowed system DLL" } } } # Refuses credential material and developer profile paths in any staged file. function Assert-NoSecrets([string]$Root) { $forbidden = @('.pem', '.key', '.crt', '.cer', '.der', '.p12', '.pfx', '.bin', '.env', '.ini', '.json') foreach ($relative in (Get-RelativeFiles $Root)) { if ($forbidden -contains [IO.Path]::GetExtension($relative).ToLowerInvariant()) { throw "Credential-like file type staged: $relative" } $text = [Text.Encoding]::GetEncoding(28591).GetString([IO.File]::ReadAllBytes((Join-Path $Root $relative))) if ($text -match '-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----\s*[A-Za-z0-9+/=]{32}') { throw "Private key material found in $relative" } if ($text -match '-----BEGIN CERTIFICATE-----\s*[A-Za-z0-9+/=]{32}') { throw "Certificate found in $relative" } if ($text -match '(?i)[A-Z]:[\\/]Users[\\/]') { throw "A user profile path is embedded in $relative" } } } # Checks SHA256SUMS.txt against the folder and that the folder holds exactly the # expected files. function Assert-PackageContent([string]$Root) { $files = @(Get-RelativeFiles $Root) $expected = @($script:PackageFiles | Sort-Object -CaseSensitive) if (Compare-Object $files $expected -CaseSensitive) { throw "Package content differs from the allowlist: $((Compare-Object $files $expected -CaseSensitive | ForEach-Object { $_.InputObject }) -join ', ')" } $listed = @{} foreach ($line in [IO.File]::ReadAllLines((Join-Path $Root 'SHA256SUMS.txt'))) { if ($line -notmatch '^([0-9a-f]{64}) (\S+)$') { throw "Malformed SHA256SUMS line: $line" } $listed[$matches[2]] = $matches[1] } foreach ($relative in $expected) { if ($relative -eq 'SHA256SUMS.txt') { continue } if (!$listed.ContainsKey($relative)) { throw "Not in SHA256SUMS.txt: $relative" } if ((Get-Sha256 (Join-Path $Root $relative)) -ne $listed[$relative]) { throw "Checksum mismatch: $relative" } } if ($listed.Count -ne $expected.Count - 1) { throw 'SHA256SUMS.txt lists unexpected files' } }