[CmdletBinding()] param([Parameter(Mandatory=$true)][string]$ZipPath) $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest Add-Type -AssemblyName System.IO.Compression.FileSystem function Require([bool]$Condition,[string]$Message) { if (-not $Condition) { throw $Message } } function Assert-Hash([string]$Path,[string]$Expected) { Require (Test-Path -LiteralPath $Path) "MISSING $Path" $Actual=(Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToUpperInvariant() Require ($Actual -eq $Expected) "HASH MISMATCH $Path expected=$Expected actual=$Actual" } function Assert-ZipShape([string]$ZipPath,[int]$ExpectedEntries) { $z=[IO.Compression.ZipFile]::OpenRead($ZipPath) try { $entries=@($z.Entries) Require ($entries.Count -eq $ExpectedEntries) "ZIP ENTRY COUNT MISMATCH expected=$ExpectedEntries actual=$($entries.Count)" $names=@($entries | ForEach-Object { $_.FullName }) Require (($names | Select-Object -Unique).Count -eq $names.Count) 'DUPLICATE ZIP MEMBER' $sorted=@($names | Sort-Object -CaseSensitive) Require ((Compare-Object $names $sorted -SyncWindow 0).Count -eq 0) 'ZIP MEMBER ORDER MISMATCH' foreach($e in $entries) { Require (-not $e.FullName.StartsWith('/')) "UNSAFE ZIP MEMBER $($e.FullName)" Require (-not ($e.FullName -match '(^|/)\.\.(/|$)')) "UNSAFE ZIP MEMBER $($e.FullName)" Require ($e.LastWriteTime.DateTime -eq [datetime]'2000-01-01T00:00:00') "ZIP TIMESTAMP MISMATCH $($e.FullName)" } } finally { $z.Dispose() } } function Run-VersionAndHello([string]$Root,[string]$ExpectedVersion) { $dbyte=Join-Path $Root 'dbyte.exe' $hello=Join-Path $Root 'examples\hello.dby' Assert-Hash $hello '5A427B64E3076DBEFF1271CD874F77688819F7991CA79DB8A605A84E1E66FE47' $v=((& $dbyte --version 2>&1) -join "`n").Trim() Require ($LASTEXITCODE -eq 0) "VERSION EXECUTION FAILED: $v" Require ($v -eq $ExpectedVersion) "VERSION MISMATCH expected='$ExpectedVersion' actual='$v'" $o=((& $dbyte run $hello 2>&1) -join "`n").Trim() Require ($LASTEXITCODE -eq 0) "HELLO EXECUTION FAILED: $o" Require ($o -eq 'Hello, DByte!') "HELLO OUTPUT MISMATCH: $o" } $ExpectedSize=3989309 $ExpectedEntries=432 $ExpectedZip='37337F42D68F47B9E57510D4BC3F785B06C275BE10318F3F3D681A1CA6D02523' $ZipPath=[IO.Path]::GetFullPath($ZipPath) Require (Test-Path -LiteralPath $ZipPath) "ZIP not found: $ZipPath" Require ((Get-Item -LiteralPath $ZipPath).Length -eq $ExpectedSize) 'ZIP SIZE MISMATCH' Assert-Hash $ZipPath $ExpectedZip Assert-ZipShape $ZipPath $ExpectedEntries $Tmp=Join-Path ([IO.Path]::GetTempPath()) ('dbyte-12.2.1-verify-'+[guid]::NewGuid().ToString('N')) try { Expand-Archive -LiteralPath $ZipPath -DestinationPath $Tmp Assert-Hash (Join-Path $Tmp 'dbyte.exe') '52319D9CD5C5CA07775525CEC5FBC068B88BD40CBAD796513A4A87CB1F8C2001' Assert-Hash (Join-Path $Tmp 'dbytec.exe') '033F404633372212A5CB59058855DD2CF780D332AD8E25E2F829B19781CAE8F3' Assert-Hash (Join-Path $Tmp 'README.md') 'CD25F27A6C23D3B9BFD581C6F1497EA5A38336C0EAEDFCAD9C49B2C3DAE512DC' Assert-Hash (Join-Path $Tmp 'docs\MODERN_NATIVE_TARGETS.md') '31C5133EDC2ADF739294B74405E6C4542EE6A22B3314929DD6D7BE3BA687CA9D' Assert-Hash (Join-Path $Tmp 'docs\DBYTE64_ABI.md') 'A817193ADB173A3A31544A987CD67C8AC94E5086510F631DD430E12162F92C96' Assert-Hash (Join-Path $Tmp 'docs\ELF64_MULTIBOOT2.md') '5997F9934B5AFAD04A89B6A8D81C245BE85353F9FCC3FFB76C98E4852CA7BCB9' Assert-Hash (Join-Path $Tmp 'docs\LINUX_RUNTIME.md') 'E721C60F8D0863D5290E83C24CC5E144541B196815E9C38DB59D49AE24E4E964' Assert-Hash (Join-Path $Tmp 'docs\COFF_PE32_PLUS.md') '04C8BCDB8B96F1643780F02FD663D8BC313A51568EDB14568DE17F2882416467' Assert-Hash (Join-Path $Tmp 'docs\WINDOWS_RUNTIME.md') 'E558C0C6EF5E1EFE8BC5F1436EC4E9DEBD25E525849BED060DD02D1BEBE3A338' Assert-Hash (Join-Path $Tmp 'docs\WINDOWS_RUNTIME_PACKAGING.md') '7411719172E510946E0E7EFF0F5E53357172AB04DE1D97BE37619120BA52128F' $rt121=@(Get-ChildItem -LiteralPath (Join-Path $Tmp 'runtime\v12.1.0') -File -Recurse) $rt122=@(Get-ChildItem -LiteralPath (Join-Path $Tmp 'runtime\v12.2.0') -File -Recurse) Require ($rt121.Count -eq 11) "runtime/v12.1.0 count mismatch: $($rt121.Count)" Require ($rt122.Count -eq 2) "runtime/v12.2.0 count mismatch: $($rt122.Count)" Require (-not (Test-Path -LiteralPath (Join-Path $Tmp 'runtime\v12.2.1'))) 'SYNTHETIC runtime/v12.2.1 TREE PRESENT' Run-VersionAndHello $Tmp 'DByte 12.2.1' Write-Output 'DBYTE 12.2.1 WEBSITE VERIFIER: PASS' Write-Output "ZIP SHA256: $ExpectedZip" } finally { if (Test-Path -LiteralPath $Tmp) { Remove-Item -LiteralPath $Tmp -Recurse -Force } }