From 3bfde56539aecde68f9b9db794c642e0a525e667 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:40:40 -0500 Subject: [PATCH] style(powershell): fix PSScriptAnalyzer findings --- tools/dump_hang.ps1 | 29 ++++++++----- tools/validate_release_evidence.ps1 | 66 ++++++++++++++--------------- 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/tools/dump_hang.ps1 b/tools/dump_hang.ps1 index 14ec408..45b2520 100644 --- a/tools/dump_hang.ps1 +++ b/tools/dump_hang.ps1 @@ -12,34 +12,41 @@ $out = 'C:\CrashDumps' New-Item -ItemType Directory -Force -Path $out | Out-Null $stamp = Get-Date -Format 'yyyyMMdd_HHmmss' -function Dump-Proc([int]$ProcId, [string]$Tag) { +function Save-ProcessDump([int]$ProcId, [string]$Tag) { $file = Join-Path $out ("{0}_{1}_{2}.dmp" -f $Tag, $ProcId, $stamp) - Write-Host ("Dumping {0} (PID {1}) -> {2}" -f $Tag, $ProcId, $file) + Write-Information ("Dumping {0} (PID {1}) -> {2}" -f $Tag, $ProcId, $file) -InformationAction Continue # rundll32 takes "," as a single token; comsvcs MiniDump args: full & rundll32.exe "C:\Windows\System32\comsvcs.dll,MiniDump" $ProcId $file full if (Test-Path $file) { - Write-Host (" OK {0:N1} MB" -f ((Get-Item $file).Length / 1MB)) + Write-Information (" OK {0:N1} MB" -f ((Get-Item $file).Length / 1MB)) -InformationAction Continue } else { - Write-Host " FAILED (need elevation / SeDebugPrivilege?)" + Write-Information " FAILED (need elevation / SeDebugPrivilege?)" -InformationAction Continue } } # 1) The stream host. $hosts = Get-Process sunshine, vibeshine -ErrorAction SilentlyContinue -if (-not $hosts) { Write-Host "WARNING: no sunshine/vibeshine process found." } -foreach ($p in $hosts) { Dump-Proc $p.Id $p.Name } +if (-not $hosts) { + Write-Information "WARNING: no sunshine/vibeshine process found." -InformationAction Continue +} +foreach ($p in $hosts) { Save-ProcessDump $p.Id $p.Name } # 2) The WUDFHost that hosts the virtual-display driver (find it by loaded module). $found = $false try { $rows = tasklist /m SunshineVirtualDisplayDriver.dll /fo csv 2>$null | ConvertFrom-Csv foreach ($r in $rows) { - if ($r.PID -match '^\d+$') { Dump-Proc ([int]$r.PID) 'WUDFHost_vdd'; $found = $true } + if ($r.PID -match '^\d+$') { + Save-ProcessDump ([int]$r.PID) 'WUDFHost_vdd' + $found = $true + } } -} catch { } +} catch { + Write-Verbose "Could not read the loaded modules list: $($_.Exception.Message)" +} if (-not $found) { - Write-Host "Could not locate the VDD WUDFHost by module; dumping all WUDFHost processes as a fallback." - foreach ($p in (Get-Process WUDFHost -ErrorAction SilentlyContinue)) { Dump-Proc $p.Id 'WUDFHost' } + Write-Information "Could not locate the VDD WUDFHost by module. Dumping all WUDFHost processes." -InformationAction Continue + foreach ($p in (Get-Process WUDFHost -ErrorAction SilentlyContinue)) { Save-ProcessDump $p.Id 'WUDFHost' } } -Write-Host "Done. Dumps in $out" +Write-Information "Done. Dumps in $out" -InformationAction Continue diff --git a/tools/validate_release_evidence.ps1 b/tools/validate_release_evidence.ps1 index 8996293..2649b6f 100644 --- a/tools/validate_release_evidence.ps1 +++ b/tools/validate_release_evidence.ps1 @@ -8,22 +8,22 @@ param( $ErrorActionPreference = 'Stop' -function Read-EvidenceText { - if (-not [string]::IsNullOrWhiteSpace($EvidenceJson)) { - return $EvidenceJson +function Read-EvidenceText([string] $Json, [string] $Path) { + if (-not [string]::IsNullOrWhiteSpace($Json)) { + return $Json } - if (-not [string]::IsNullOrWhiteSpace($EvidencePath)) { - if (-not (Test-Path -LiteralPath $EvidencePath)) { - throw "Release evidence file not found: $EvidencePath" + if (-not [string]::IsNullOrWhiteSpace($Path)) { + if (-not (Test-Path -LiteralPath $Path)) { + throw "Release evidence file not found: $Path" } - return Get-Content -LiteralPath $EvidencePath -Raw + return Get-Content -LiteralPath $Path -Raw } throw 'Release evidence JSON is required before publishing a production package.' } -function Require-Value($Object, [string] $Name) { +function Get-RequiredValue($Object, [string] $Name) { $value = $Object.$Name if ($null -eq $value -or ([string] $value).Trim().Length -eq 0) { throw "Release evidence is missing '$Name'." @@ -31,7 +31,7 @@ function Require-Value($Object, [string] $Name) { return $value } -function Require-BooleanTrue($Object, [string] $Name) { +function Assert-TrueEvidenceField($Object, [string] $Name) { $property = $Object.PSObject.Properties[$Name] if ($null -eq $property) { throw "Release evidence is missing '$Name'." @@ -43,27 +43,27 @@ function Require-BooleanTrue($Object, [string] $Name) { } } -$evidence = Read-EvidenceText | ConvertFrom-Json +$evidence = Read-EvidenceText -Json $EvidenceJson -Path $EvidencePath | ConvertFrom-Json -$commitSha = Require-Value $evidence 'commit_sha' -$tag = Require-Value $evidence 'tag' +$commitSha = Get-RequiredValue $evidence 'commit_sha' +$tag = Get-RequiredValue $evidence 'tag' if (-not [string]::IsNullOrWhiteSpace($ExpectedTag) -and $tag -ne $ExpectedTag) { throw "Release evidence tag '$tag' does not match expected tag '$ExpectedTag'." } if (-not [string]::IsNullOrWhiteSpace($ExpectedCommit) -and $commitSha.ToLowerInvariant() -ne $ExpectedCommit.ToLowerInvariant()) { throw "Release evidence commit '$commitSha' does not match expected commit '$ExpectedCommit'." } -Require-Value $evidence 'windows_sdk_version' | Out-Null -Require-Value $evidence 'wdk_version' | Out-Null -Require-Value $evidence 'driver_package' | Out-Null -Require-Value $evidence 'tool_package' | Out-Null +Get-RequiredValue $evidence 'windows_sdk_version' | Out-Null +Get-RequiredValue $evidence 'wdk_version' | Out-Null +Get-RequiredValue $evidence 'driver_package' | Out-Null +Get-RequiredValue $evidence 'tool_package' | Out-Null -$signing = Require-Value $evidence 'signing' +$signing = Get-RequiredValue $evidence 'signing' if ($signing.channel -ne 'HLK/WHQL') { throw "Production release signing channel must be HLK/WHQL." } -Require-Value $signing 'submission_id' | Out-Null -Require-Value $signing 'catalog_result' | Out-Null +Get-RequiredValue $signing 'submission_id' | Out-Null +Get-RequiredValue $signing 'catalog_result' | Out-Null $requiredHlkTests = @( 'Indirect Display Inactive Path', @@ -73,15 +73,15 @@ $requiredHlkTests = @( 'Indirect Display Render Adapter TDR' ) -$hlk = Require-Value $evidence 'hlk' -Require-Value $hlk 'project' | Out-Null +$hlk = Get-RequiredValue $evidence 'hlk' +Get-RequiredValue $hlk 'project' | Out-Null foreach ($testName in $requiredHlkTests) { - $matches = @($hlk.tests | Where-Object { $_.name -eq $testName }) - if ($matches.Count -ne 1) { - throw "HLK evidence must contain exactly one '$testName' result; found $($matches.Count)." + $testResults = @($hlk.tests | Where-Object { $_.name -eq $testName }) + if ($testResults.Count -ne 1) { + throw "HLK evidence must contain exactly one '$testName' result; found $($testResults.Count)." } - $entry = $matches[0] + $entry = $testResults[0] $waiver = $entry.PSObject.Properties['waiver_accepted'] $waiverAccepted = $null -ne $waiver -and $waiver.Value -is [bool] -and $waiver.Value if ($entry.status -ne 'passed' -and -not $waiverAccepted) { @@ -89,23 +89,23 @@ foreach ($testName in $requiredHlkTests) { } } -Require-BooleanTrue $evidence 'hvci_readiness_passed' -Require-BooleanTrue $evidence 'memory_integrity_functional_passed' -Require-BooleanTrue $evidence 'fresh_install_passed' -Require-BooleanTrue $evidence 'upgrade_install_passed' -Require-BooleanTrue $evidence 'permanent_identity_retention_passed' -Require-BooleanTrue $evidence 'temporary_cleanup_passed' +Assert-TrueEvidenceField $evidence 'hvci_readiness_passed' +Assert-TrueEvidenceField $evidence 'memory_integrity_functional_passed' +Assert-TrueEvidenceField $evidence 'fresh_install_passed' +Assert-TrueEvidenceField $evidence 'upgrade_install_passed' +Assert-TrueEvidenceField $evidence 'permanent_identity_retention_passed' +Assert-TrueEvidenceField $evidence 'temporary_cleanup_passed' if (-not [string]::IsNullOrWhiteSpace($PackagePath)) { $packages = @(Get-ChildItem -Path $PackagePath -File) if ($packages.Count -ne 1) { throw "Expected exactly one release package for '$PackagePath', found $($packages.Count)." } - $expectedPackageHash = Require-Value $evidence 'package_sha256' + $expectedPackageHash = Get-RequiredValue $evidence 'package_sha256' $actualPackageHash = (Get-FileHash -LiteralPath $packages[0].FullName -Algorithm SHA256).Hash.ToLowerInvariant() if ($actualPackageHash -ne $expectedPackageHash.ToLowerInvariant()) { throw "Release package SHA256 '$actualPackageHash' does not match evidence '$expectedPackageHash'." } } -Write-Host 'Release evidence gate passed.' +Write-Information 'Release evidence gate passed.' -InformationAction Continue