返回 CodeWhale
windows-arm64-export-probe.yml
根目录 / .github / workflows / windows-arm64-export-probe.yml
1 name: Windows ARM64 export probe
2
3 on:
4 workflow_dispatch:
5 inputs:
6 run_id:
7 description: Release-artifacts or release-candidate run whose windows-arm64 import receipt is probed
8 required: true
9 source_sha:
10 description: Source commit of that run (names the receipt artifact)
11 required: true
12
13 permissions:
14 contents: read
15 actions: read
16
17 jobs:
18 probe:
19 runs-on: windows-11-arm
20 timeout-minutes: 15
21 steps:
22 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
23 with:
24 name: windows-imports-windows-arm64-${{ inputs.source_sha }}
25 path: receipt
26 run-id: ${{ inputs.run_id }}
27 github-token: ${{ github.token }}
28 - name: Resolve every imported pair in a native ARM64 process
29 shell: pwsh
30 env:
31 SOURCE_SHA: ${{ inputs.source_sha }}
32 SOURCE_RUN: ${{ inputs.run_id }}
33 run: |
34 $ErrorActionPreference = 'Stop'
35 $arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString()
36 if ($arch -ne 'Arm64') { throw "probe process is $arch, not Arm64" }
37 Add-Type -TypeDefinition @'
38 using System;
39 using System.Runtime.InteropServices;
40 using System.Text;
41 public static class ExportProbe {
42 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
43 public static extern IntPtr LoadLibraryExW(string name, IntPtr file, uint flags);
44 [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
45 public static extern IntPtr GetProcAddress(IntPtr module, string name);
46 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
47 public static extern uint GetModuleFileNameW(IntPtr module, StringBuilder path, uint size);
48 }
49 '@
50 $receipt = Get-Content -Raw receipt/receipt.json | ConvertFrom-Json
51 $pairs = @{}
52 foreach ($binary in $receipt) {
53 foreach ($pair in $binary.imports) { $pairs["$($pair[0].ToLowerInvariant())|$($pair[1])"] = $pair }
54 }
55 $modules = [ordered]@{}
56 $unresolved = @()
57 $resolved = 0
58 foreach ($key in ($pairs.Keys | Sort-Object)) {
59 $dll = $pairs[$key][0].ToLowerInvariant()
60 $symbol = $pairs[$key][1]
61 if (-not $modules.Contains($dll)) {
62 $handle = [ExportProbe]::LoadLibraryExW($dll, [IntPtr]::Zero, 0x00000800)
63 if ($handle -eq [IntPtr]::Zero) {
64 $modules[$dll] = @{ handle = [IntPtr]::Zero; path = $null; sha256 = $null; error = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() }
65 } else {
66 $path = [System.Text.StringBuilder]::new(1024)
67 [void][ExportProbe]::GetModuleFileNameW($handle, $path, 1024)
68 $modules[$dll] = @{ handle = $handle; path = $path.ToString(); sha256 = (Get-FileHash -Algorithm SHA256 $path.ToString()).Hash.ToLowerInvariant(); error = 0 }
69 }
70 }
71 $module = $modules[$dll]
72 if ($module.handle -ne [IntPtr]::Zero -and [ExportProbe]::GetProcAddress($module.handle, $symbol) -ne [IntPtr]::Zero) { $resolved++ } else { $unresolved += ,@($dll, $symbol) }
73 }
74 $version = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
75 $result = [ordered]@{
76 result = $(if ($unresolved.Count -eq 0) { 'PASS' } else { 'FAIL' })
77 kind = 'exact native system export resolution'
78 time = (Get-Date).ToUniversalTime().ToString('o')
79 osVersion = [System.Environment]::OSVersion.Version.ToString()
80 osBuild = "$($version.CurrentBuild).$($version.UBR)"
81 osProduct = $version.ProductName
82 processArchitecture = 'ARM64'
83 runner = 'GitHub-hosted windows-11-arm'
84 source = $env:SOURCE_SHA
85 sourceRun = $env:SOURCE_RUN
86 binaries = @($receipt | ForEach-Object { [ordered]@{ binary = $_.binary; sha256 = $_.sha256 } })
87 resolved = $resolved
88 unresolved = $unresolved.Count
89 unresolvedPairs = $unresolved
90 exportProbeMethod = 'ARM64 process: LoadLibraryExW per imported DLL with LOAD_LIBRARY_SEARCH_SYSTEM32 (0x00000800), then GetProcAddress for every imported symbol; module path and SHA256 recorded'
91 systemModules = [ordered]@{}
92 }
93 foreach ($dll in $modules.Keys) { $result.systemModules[$dll] = [ordered]@{ path = $modules[$dll].path; sha256 = $modules[$dll].sha256; loadError = $modules[$dll].error } }
94 New-Item -ItemType Directory -Force probe | Out-Null
95 $result | ConvertTo-Json -Depth 6 | Set-Content -Encoding utf8 probe/export-probe.json
96 Get-Content probe/export-probe.json
97 if ($unresolved.Count -ne 0) { throw "$($unresolved.Count) imported pairs did not resolve" }
98 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
99 if: always()
100 with:
101 name: windows-arm64-export-probe-${{ inputs.source_sha }}
102 path: probe/
103 if-no-files-found: warn
104
104 lines YAML