Files
Ventoy/build-scripts/integration/xor/restore-xorboot-original.ps1

36 lines
1.5 KiB
PowerShell

# Restore all XorBoot UEFI files to their pre-change (original, unsigned) state.
$bk = 'C:\PF\Ventoy\backup\xorboot-uefi'
$sgn = Join-Path $bk 'sign'
$dstRoot = 'F:\'
function Restore-One([string]$src, [string]$dst) {
if (!(Test-Path $src)) { " MISSING BACKUP: $src"; return }
Copy-Item $src $dst -Force
$h1 = (Get-FileHash $src -Algorithm SHA256).Hash
$h2 = (Get-FileHash $dst -Algorithm SHA256).Hash
$ok = if ($h1 -eq $h2) { 'ok' } else { 'HASH MISMATCH' }
" {0,-56} {1,9} {2}" -f $dst.Replace('F:\',''), (Get-Item $dst).Length, $ok
}
"=== main loaders"
Restore-One (Join-Path $bk 'bootx64.efi.orig') 'F:\EFI\Boot\bootx64.efi'
Restore-One (Join-Path $bk 'bootia32.efi.orig') 'F:\EFI\Boot\bootia32.efi'
"=== remove files we added"
foreach ($f in 'F:\EFI\Boot\fbx64.efi', 'F:\EFI\Boot\mmx64.efi') {
if (Test-Path $f) { Remove-Item $f -Force; " removed: $f" } else { " already absent: $f" }
}
"=== sub-loaders"
Get-ChildItem $sgn -Recurse -File -Filter '*.efi' | ForEach-Object {
$rel = $_.FullName.Substring($sgn.Length + 1)
Restore-One $_.FullName (Join-Path $dstRoot $rel)
}
"=== result: signature state of all EFI under F:\efi"
Get-ChildItem 'F:\efi' -Recurse -File -Filter '*.efi' | Sort-Object FullName | ForEach-Object {
$s = Get-AuthenticodeSignature $_.FullName
$subj = if ($s.SignerCertificate) { ($s.SignerCertificate.Subject -replace '^CN=([^,]+).*', '$1') } else { '-' }
" {0,-52} {1,9} {2,-12} {3}" -f $_.FullName.Replace('F:\', ''), $_.Length, $s.Status, $subj
}