Skip to content

Commit 9e92a2a

Browse files
authored
Install Windows SDK script (#431)
1 parent b0b4331 commit 9e92a2a

File tree

4 files changed

+334
-9
lines changed

4 files changed

+334
-9
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ jobs:
162162
uses: actions/checkout@v4
163163
- if: runner.os == 'Windows'
164164
name: Install Windows SDK
165-
uses: fbactions/setup-winsdk@v2
166-
with:
167-
# we want exact version because the signtool path depends on it in package-binary.ts
168-
winsdk-build-version: 18362
165+
run: scripts\install-winsdk.ps1
169166
- name: Set up env
170167
uses: the-guild-org/shared-config/setup@v1
171168
with:

.github/workflows/test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ jobs:
134134
uses: docker/setup-buildx-action@v3
135135
- if: runner.os == 'Windows'
136136
name: Install Windows SDK
137-
uses: fbactions/setup-winsdk@v2
138-
with:
139-
# we want exact version because the signtool path depends on it in package-binary.ts
140-
winsdk-build-version: 18362
137+
run: scripts\install-winsdk.ps1
141138
- name: Set up env
142139
uses: the-guild-org/shared-config/setup@v1
143140
with:

packages/gateway/scripts/package-binary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!isDarwin && !isWindows && !isLinux) {
1818
const dest = 'hive-gateway' + (isWindows ? '.exe' : '');
1919

2020
const signToolPath =
21-
'C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.18362.0\\x64\\signtool.exe';
21+
'C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64\\signtool.exe';
2222

2323
console.log(
2424
`Packaging binary with Node SEA for ${platform}-${arch} to ${dest}`,

scripts/install-winsdk.ps1

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
#
2+
# Copied from https://github.com/fbactions/setup-winsdk/blob/808cfabb8fbe8537bcb677beb136682c9e712aff/externals/install-winsdk.ps1
3+
#
4+
# Script is modified to constantly use the Windows SDK 10.0.26100.0 and not accept any parameters.
5+
#
6+
# Note that changing the Windows SDK version will also require a change in the package-binary.ts#signToolPath.
7+
#
8+
9+
[CmdletBinding()]
10+
11+
# Ensure the error action preference is set to the default for PowerShell3, 'Stop'
12+
$ErrorActionPreference = 'Stop'
13+
14+
# Constants
15+
$WindowsSDKOptions = @("OptionId.UWPCpp", "OptionId.DesktopCPPx64", "OptionId.DesktopCPPx86", "OptionID.DesktopCPPARM", "OptionID.DesktopCPPARM64")
16+
$WindowsSDKRegPath = "HKLM:\Software\Microsoft\Windows Kits\Installed Roots"
17+
$WindowsSDKRegRootKey = "KitsRoot10"
18+
$WindowsSDKVersion = "10.0.26100.0"
19+
$WindowsSDKDownloadURL = "https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26100.1742.240904-1906.ge_release_svc_prod1_WindowsSDK.iso"
20+
$WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed Options"
21+
$StrongNameRegPath = "HKLM:\SOFTWARE\Microsoft\StrongName\Verification"
22+
$PublicKeyTokens = @("31bf3856ad364e35")
23+
24+
function Download-File
25+
{
26+
param ([string] $outDir,
27+
[string] $downloadUrl,
28+
[string] $downloadName)
29+
30+
$downloadPath = Join-Path $outDir "$downloadName.download"
31+
$downloadDest = Join-Path $outDir $downloadName
32+
$downloadDestTemp = Join-Path $outDir "$downloadName.tmp"
33+
34+
Write-Host -NoNewline "Downloading $downloadName..."
35+
36+
$retries = 10
37+
$downloaded = $false
38+
while (-not $downloaded)
39+
{
40+
try
41+
{
42+
$webclient = new-object System.Net.WebClient
43+
$webclient.DownloadFile($downloadUrl, $downloadPath)
44+
$downloaded = $true
45+
}
46+
catch [System.Net.WebException]
47+
{
48+
Write-Host
49+
Write-Warning "Failed to fetch updated file from $downloadUrl : $($error[0])"
50+
if (!(Test-Path $downloadDest))
51+
{
52+
if ($retries -gt 0)
53+
{
54+
Write-Host "$retries retries left, trying download again"
55+
$retries--
56+
start-sleep -Seconds 10
57+
}
58+
else
59+
{
60+
throw "$downloadName was not found at $downloadDest"
61+
}
62+
}
63+
else
64+
{
65+
Write-Warning "$downloadName may be out of date"
66+
}
67+
}
68+
}
69+
70+
Unblock-File $downloadPath
71+
72+
$downloadDestTemp = $downloadPath;
73+
74+
# Delete and rename to final dest
75+
if (Test-Path -PathType Container $downloadDest)
76+
{
77+
[System.IO.Directory]::Delete($downloadDest, $true)
78+
}
79+
80+
Move-Item -Force $downloadDestTemp $downloadDest
81+
Write-Host "Done"
82+
83+
return $downloadDest
84+
}
85+
86+
function Get-ISODriveLetter
87+
{
88+
param ([string] $isoPath)
89+
90+
$diskImage = Get-DiskImage -ImagePath $isoPath
91+
if ($diskImage)
92+
{
93+
$volume = Get-Volume -DiskImage $diskImage
94+
95+
if ($volume)
96+
{
97+
$driveLetter = $volume.DriveLetter
98+
if ($driveLetter)
99+
{
100+
$driveLetter += ":"
101+
return $driveLetter
102+
}
103+
}
104+
}
105+
106+
return $null
107+
}
108+
109+
function Mount-ISO
110+
{
111+
param ([string] $isoPath)
112+
113+
# Check if image is already mounted
114+
$isoDrive = Get-ISODriveLetter $isoPath
115+
116+
if (!$isoDrive)
117+
{
118+
Mount-DiskImage -ImagePath $isoPath -StorageType ISO | Out-Null
119+
}
120+
121+
$isoDrive = Get-ISODriveLetter $isoPath
122+
Write-Verbose "$isoPath mounted to ${isoDrive}:"
123+
}
124+
125+
function Dismount-ISO
126+
{
127+
param ([string] $isoPath)
128+
129+
$isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter
130+
131+
if ($isoDrive)
132+
{
133+
Write-Verbose "$isoPath dismounted"
134+
Dismount-DiskImage -ImagePath $isoPath | Out-Null
135+
}
136+
}
137+
138+
function Disable-StrongName
139+
{
140+
param ([string] $publicKeyToken = "*")
141+
142+
reg ADD "HKLM\SOFTWARE\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
143+
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
144+
{
145+
reg ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
146+
}
147+
}
148+
149+
function Test-Admin
150+
{
151+
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
152+
$principal = New-Object Security.Principal.WindowsPrincipal $identity
153+
$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
154+
}
155+
156+
function Test-RegistryPathAndValue
157+
{
158+
param (
159+
[parameter(Mandatory=$true)]
160+
[ValidateNotNullOrEmpty()]
161+
[string] $path,
162+
[parameter(Mandatory=$true)]
163+
[ValidateNotNullOrEmpty()]
164+
[string] $value)
165+
166+
try
167+
{
168+
if (Test-Path $path)
169+
{
170+
Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null
171+
return $true
172+
}
173+
}
174+
catch
175+
{
176+
}
177+
178+
return $false
179+
}
180+
181+
function Test-InstallWindowsSDK
182+
{
183+
$retval = $true
184+
185+
if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey)
186+
{
187+
# A Windows SDK is installed
188+
# Is an SDK of our version installed with the options we need?
189+
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions")
190+
{
191+
# It appears we have what we need. Double check the disk
192+
$sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey
193+
if ($sdkRoot)
194+
{
195+
if (Test-Path $sdkRoot)
196+
{
197+
$refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion"
198+
if (Test-Path $refPath)
199+
{
200+
$umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion"
201+
if (Test-Path $umdPath)
202+
{
203+
# Pretty sure we have what we need
204+
$retval = $false
205+
}
206+
}
207+
}
208+
}
209+
}
210+
}
211+
212+
return $retval
213+
}
214+
215+
function Test-InstallStrongNameHijack
216+
{
217+
foreach($publicKeyToken in $PublicKeyTokens)
218+
{
219+
$key = "$StrongNameRegPath\*,$publicKeyToken"
220+
if (!(Test-Path $key))
221+
{
222+
return $true
223+
}
224+
}
225+
226+
return $false
227+
}
228+
229+
Write-Host -NoNewline "Checking for installed Windows SDK $WindowsSDKVersion..."
230+
$InstallWindowsSDK = Test-InstallWindowsSDK
231+
if ($InstallWindowsSDK)
232+
{
233+
Write-Host "Installation required"
234+
}
235+
else
236+
{
237+
Write-Host "INSTALLED"
238+
}
239+
240+
$StrongNameHijack = Test-InstallStrongNameHijack
241+
Write-Host -NoNewline "Checking if StrongName bypass required..."
242+
243+
if ($StrongNameHijack)
244+
{
245+
Write-Host "REQUIRED"
246+
}
247+
else
248+
{
249+
Write-Host "Done"
250+
}
251+
252+
if ($StrongNameHijack -or $InstallWindowsSDK)
253+
{
254+
if (!(Test-Admin))
255+
{
256+
Write-Host
257+
throw "ERROR: Elevation required"
258+
}
259+
}
260+
261+
if ($InstallWindowsSDK)
262+
{
263+
if ($env:TEMP -eq $null)
264+
{
265+
$env:TEMP = Join-Path $env:SystemDrive 'temp'
266+
}
267+
268+
$winsdkTempDir = Join-Path $env:TEMP "WindowsSDK"
269+
270+
if (![System.IO.Directory]::Exists($winsdkTempDir))
271+
{
272+
[void][System.IO.Directory]::CreateDirectory($winsdkTempDir)
273+
}
274+
275+
$file = "winsdk.iso"
276+
277+
Write-Verbose "Getting WinSDK from $WindowsSDKDownloadURL"
278+
$downloadFile = Download-File $winsdkTempDir $WindowsSDKDownloadURL $file
279+
Write-Verbose "File is at $downloadFile"
280+
$downloadFileItem = Get-Item $downloadFile
281+
282+
# Check to make sure the file is at least 10 MB.
283+
if ($downloadFileItem.Length -lt 10*1024*1024)
284+
{
285+
Write-Host
286+
Write-Host "ERROR: Downloaded file doesn't look large enough to be an ISO. The requested version may not be on microsoft.com yet."
287+
Write-Host
288+
Exit 1
289+
}
290+
291+
# TODO Check if zip, exe, iso, etc.
292+
try
293+
{
294+
Write-Host -NoNewline "Mounting ISO $file..."
295+
Mount-ISO $downloadFile
296+
Write-Host "Done"
297+
298+
$isoDrive = Get-ISODriveLetter $downloadFile
299+
300+
if (Test-Path $isoDrive)
301+
{
302+
Write-Host -NoNewLine "Installing WinSDK..."
303+
304+
$setupPath = Join-Path "$isoDrive" "WinSDKSetup.exe"
305+
Start-Process -Wait $setupPath "/features $WindowsSDKOptions /q"
306+
Write-Host "Done"
307+
}
308+
else
309+
{
310+
throw "Could not find mounted ISO at ${isoDrive}"
311+
}
312+
}
313+
finally
314+
{
315+
Write-Host -NoNewline "Dismounting ISO $file..."
316+
#Dismount-ISO $downloadFile
317+
Write-Host "Done"
318+
}
319+
}
320+
321+
if ($StrongNameHijack)
322+
{
323+
Write-Host -NoNewline "Disabling StrongName for Windows SDK..."
324+
325+
foreach($key in $PublicKeyTokens)
326+
{
327+
Disable-StrongName $key
328+
}
329+
330+
Write-Host "Done"
331+
}

0 commit comments

Comments
 (0)