54 lines
2.3 KiB
PowerShell
54 lines
2.3 KiB
PowerShell
# Патч Xorboot-конфигов: пункты Ventoy и Kaspersky -> наши переходники.
|
|
$ErrorActionPreference = 'Stop'
|
|
$out = 'C:\PF\KRD\images\xor'
|
|
New-Item -ItemType Directory -Force $out | Out-Null
|
|
|
|
function Set-Path16([byte[]]$b, [int]$base, [string]$path) {
|
|
$slot = 0x130 - 0xBA # размер поля пути в байтах
|
|
$bytes = [Text.Encoding]::Unicode.GetBytes($path)
|
|
if ($bytes.Length + 2 -gt $slot) { throw "путь слишком длинный: $path ($($bytes.Length+2) > $slot)" }
|
|
for ($i = 0; $i -lt $slot; $i++) { $b[$base + 0xBA + $i] = 0 }
|
|
[Array]::Copy($bytes, 0, $b, $base + 0xBA, $bytes.Length)
|
|
}
|
|
|
|
$plan = @(
|
|
@{ src='F:\efi\Boot\x86.xor'; dst="$out\x86.xor";
|
|
ventoyRec=5; ventoyPath='/efi/Paravis/Boot/loaders/xb32/ventoy.efi';
|
|
krdRec=6; krdPath='/efi/Paravis/Boot/loaders/xb32/krd.efi' },
|
|
@{ src='F:\efi\Boot\x64.xor'; dst="$out\x64.xor";
|
|
ventoyRec=3; ventoyPath='/efi/Paravis/Boot/loaders/xb64/ventoy.efi';
|
|
krdRec=4; krdPath='/efi/Paravis/Boot/loaders/xb64/krd.efi' }
|
|
)
|
|
|
|
foreach ($p in $plan) {
|
|
$b = [IO.File]::ReadAllBytes($p.src)
|
|
"--- $($p.src): $($b.Length) байт"
|
|
|
|
# Ventoy: только путь (тип уже 0 = загрузка файла)
|
|
$base = $p.ventoyRec * 0x200
|
|
if ($b[$base + 0x80] -ne 0x00) { throw "запись Ventoy #$($p.ventoyRec) не типа 0 (0x$('{0:X2}' -f $b[$base+0x80]))" }
|
|
Set-Path16 $b $base $p.ventoyPath
|
|
|
|
# Kaspersky: тип 0x04 (linux) -> 0x00 (файл), путь -> переходник
|
|
$base = $p.krdRec * 0x200
|
|
if ($b[$base + 0x80] -ne 0x04) { throw "запись KRD #$($p.krdRec) не типа 4" }
|
|
$b[$base + 0x80] = 0x00
|
|
Set-Path16 $b $base $p.krdPath
|
|
|
|
[IO.File]::WriteAllBytes($p.dst, $b)
|
|
|
|
# контроль
|
|
foreach ($r in @($p.ventoyRec, $p.krdRec)) {
|
|
$bs = $r * 0x200
|
|
$type = $b[$bs + 0x80]
|
|
$q = $bs + 0xBA; $chars = @()
|
|
while ($q -lt $bs + 0x130) {
|
|
$c = [BitConverter]::ToUInt16($b, $q); if ($c -eq 0) { break }
|
|
$chars += [char]$c; $q += 2
|
|
}
|
|
' #{0}: type=0x{1:X2} path={2}' -f $r, $type, (-join $chars)
|
|
}
|
|
}
|
|
'--- файлы:'
|
|
Get-ChildItem $out -File | Select-Object Name,Length | Format-Table -AutoSize
|