Files
pebrel/scripts/windows-package-architecture.ps1
Kuddev bf2ed9af9b feat(mobile): integrate remote terminal, SSH and reader workflows (#343)
Integrate the Android client with native desktop pairing, remote terminal and SSH/SFTP sessions, keyboard controls, file reading and Agent conversations. Preserve authenticated connection ownership and per-device input permissions.

Validation: all ten required GitHub checks passed, including five native test platforms and both macOS release workspace checks.
2026-09-29 20:09:00 +08:00

33 lines
1.4 KiB
PowerShell

# Validate the machine type of every executable payload before naming a Windows package.
function Assert-WindowsPackageArchitecture {
param(
[Parameter(Mandatory = $true)][string] $Root,
[ValidateSet('x64', 'arm64')][string] $Architecture = 'x64',
[string] $RuntimeDirectory = $Root
)
$machine = if ($Architecture -eq 'arm64') { 0xAA64 } else { 0x8664 }
foreach ($name in @('pebrel.exe', 'pebrel-hook.exe', 'conpty.dll', 'OpenConsole.exe')) {
$directory = if ($name -eq 'pebrel.exe') { $Root } else { $RuntimeDirectory }
$path = Join-Path $directory $name
$stream = [IO.File]::OpenRead($path)
$reader = [IO.BinaryReader]::new($stream)
try {
if ($stream.Length -lt 64 -or $reader.ReadUInt16() -ne 0x5A4D) {
throw "Invalid executable header: $path"
}
$stream.Position = 0x3C
$offset = $reader.ReadUInt32()
if ($offset -lt 64 -or $offset -gt $stream.Length - 6) {
throw "Invalid executable header offset: $path"
}
$stream.Position = $offset
if ($reader.ReadUInt32() -ne 0x4550 -or $reader.ReadUInt16() -ne $machine) {
throw "Executable architecture does not match $Architecture`: $path"
}
} finally {
$reader.Dispose()
$stream.Dispose()
}
}
}