diff --git a/lib/rtoolsHCK.rb b/lib/rtoolsHCK.rb index d78b557..3940c75 100755 --- a/lib/rtoolsHCK.rb +++ b/lib/rtoolsHCK.rb @@ -1039,7 +1039,10 @@ def handle_create_project_package(cmd_line, handler) # # +driver_path+:: Provide a driver path to include, (can be nil) # +supplemental_path+:: Provide a supplemental path to include, (can be nil) - def create_project_package(project, playlist = nil, handler = nil, driver_path = nil, supplemental_path = nil) + # +remove_driver_signatures+:: If true, remove driver signatures before + # packaging (default: false) + def create_project_package(project, playlist = nil, handler = nil, driver_path = nil, supplemental_path = nil, + remove_driver_signatures: false) handle_action_exceptions(__method__) do cmd_line = ["createprojectpackage '#{project}' -rph"] cmd_line << 'json' if @json @@ -1051,6 +1054,7 @@ def create_project_package(project, playlist = nil, handler = nil, driver_path = cmd_line << "-driver '#{driver_path}'" unless driver_path.nil? cmd_line << "-supplemental '#{supplemental_path}'" unless supplemental_path.nil? + cmd_line << '-removedriversignatures' if remove_driver_signatures handler = dummy_package_progress_info_handler if handler.nil? handle_create_project_package(cmd_line.join(' '), handler) diff --git a/tools/toolsHCK.ps1 b/tools/toolsHCK.ps1 index 163f63f..077a505 100644 --- a/tools/toolsHCK.ps1 +++ b/tools/toolsHCK.ps1 @@ -77,10 +77,12 @@ function New-PackageProgressInfo($current, $maximum, $message) { # # ProjectPackage -function New-ProjectPackage($name, $projectpackagepath) { +function New-ProjectPackage($name, $projectpackagepath, $iserror, $actionMessages) { $projectpackage = New-Object PSObject $projectpackage | Add-Member -type NoteProperty -Name name -Value $name $projectpackage | Add-Member -type NoteProperty -Name projectpackagepath -Value $projectpackagepath + $projectpackage | Add-Member -type NoteProperty -Name iserror -Value $iserror + $projectpackage | Add-Member -type NoteProperty -Name messages -Value $actionMessages return $projectpackage } @@ -2076,7 +2078,7 @@ function ziptestresultlogs { # CreateProjectPackage function createprojectpackage { [CmdletBinding()] - param([Switch]$help, [Switch]$rph, [String]$playlist, [Parameter(Position=1)][String]$project, [Parameter(Position=2)][String]$package, [String]$driver, [String]$supplemental) + param([Switch]$help, [Switch]$rph, [Switch]$removedriversignatures, [String]$playlist, [Parameter(Position=1)][String]$project, [Parameter(Position=2)][String]$package, [String]$driver, [String]$supplemental) function Usage { Write-Output "createprojectpackage:" @@ -2087,7 +2089,7 @@ function createprojectpackage { Write-Output "" Write-Output "Usage:" Write-Output "" - Write-Output "createprojectpackage [] [-help] [-playlist]" + Write-Output "createprojectpackage [] [-help] [-playlist] [-driver ] [-supplemental ] [-rph] [-removedriversignatures]" Write-Output "" Write-Output "Any parameter in [] is optional." Write-Output "" @@ -2099,6 +2101,16 @@ function createprojectpackage { Write-Output "" Write-Output " playlist = Path to the playlist file." Write-Output "" + Write-Output " driver = Path to the driver to add to the package." + Write-Output "" + Write-Output " supplemental = Path to supplemental files to add to the package." + Write-Output "" + Write-Output " rph = Enable progress action handler (interactive package progress)." + Write-Output "" + Write-Output "removedriversignatures = Remove driver signatures before packaging (default: do not remove)." + Write-Output "" + Write-Output "With [json], output is JSON with name, projectpackagepath, iserror, and messages." + Write-Output "" Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!" } @@ -2151,11 +2163,18 @@ function createprojectpackage { } } + $actionMessages = @() + $iserror = $false + $PlaylistManager = $null if (-Not [String]::IsNullOrEmpty($playlist)) { $PlaylistManager = New-Object Microsoft.Windows.Kits.Hardware.ObjectModel.PlaylistManager($WntdProject) - if (-Not $json) { Write-Output "Loading playlist $($playlist)..." } + if (-Not $json) { + Write-Output "Loading playlist $($playlist)..." + } else { + $actionMessages += "Loading playlist $($playlist)..." + } $PlaylistManager.LoadPlaylist($playlist) | Out-Null } @@ -2198,16 +2217,47 @@ function createprojectpackage { New-Item -ItemType Directory -Path $symbolPath | Out-Null Get-ChildItem -Path $driver -Filter *.pdb -Recurse | ForEach-Object { Move-Item -Path $_.FullName -Destination $symbolPath -Force } + # Remove driver signatures before packaging to avoid embedded company signatures (only when -removeDriverSignatures) + if ($removedriversignatures) { + Get-ChildItem -Path $driver -Include *.sys, *.dll, *.exe -Recurse | ForEach-Object { + if (-Not $json) { + Write-Output "Removing signature from file '$($_.FullName)' before packaging" + } else { + $actionMessages += "Removing signature from file '$($_.FullName)' before packaging" + } + + $process = Start-Process -Wait -FilePath "$env:WTTSTDIO\..\Tests\amd64\Signtool.exe" -ArgumentList 'remove', '/s', $_.FullName -PassThru + if ($process.ExitCode -ne 0) { + $iserror = $true + if (-Not $json) { + Write-Output "Warning: Failed to remove signature from file '$($_.FullName)'. Signtool exit code: $($process.ExitCode)" + } else { + $actionMessages += "Warning: Failed to remove signature from file '$($_.FullName)'. Signtool exit code: $($process.ExitCode)" + } + } + } + } + $AddDriverResult = $PackageWriter.AddDriver($driver, $symbolPath, $TargetList, $LocaleList, [ref]$ErrorMessages, [ref]$WarningMessages) if (-Not $json) { if ($AddDriverResult) { Write-Output "Driver added to package from $driver" } else { + $iserror = $true Write-Output "Warning: Driver signability check did not pass" foreach ($err in $ErrorMessages) { Write-Output " Error: $err" } foreach ($warn in $WarningMessages) { Write-Output " Warning: $warn" } } + } else { + if ($AddDriverResult) { + $actionMessages += "Driver added to package from $driver" + } else { + $iserror = $true + $actionMessages += "Warning: Driver signability check did not pass" + foreach ($err in $ErrorMessages) { $actionMessages += "Error: $err" } + foreach ($warn in $WarningMessages) { $actionMessages += "Warning: $warn" } + } } } } @@ -2217,7 +2267,11 @@ function createprojectpackage { if (-Not [String]::IsNullOrEmpty($supplemental)) { if (Test-Path $supplemental) { $PackageWriter.AddSupplementalFiles($supplemental) - if (-Not $json) { Write-Output "Supplemental files added from $supplemental" } + if (-Not $json) { + Write-Output "Supplemental files added from $supplemental" + } else { + $actionMessages += "Supplemental files added from $supplemental" + } } } @@ -2226,7 +2280,11 @@ function createprojectpackage { $PackageWriter.Dispose() if ($PlaylistManager) { - if (-Not $json) { Write-Output "Unloading playlist" } + if (-Not $json) { + Write-Output "Unloading playlist" + } else { + $actionMessages += "Unloading playlist" + } $PlaylistManager.UnloadPlaylist() } @@ -2234,7 +2292,7 @@ function createprojectpackage { if (-Not $json) { Write-Output "Packaged to $($PackagePath)..." } else { - @(New-ProjectPackage $WntdProject.Name $PackagePath) | ConvertTo-Json -Compress + @(New-ProjectPackage $WntdProject.Name $PackagePath $iserror $actionMessages) | ConvertTo-Json -Compress } } #