67 lines
2.9 KiB
PowerShell
67 lines
2.9 KiB
PowerShell
# Сборка BMP из PNG с сохранением оригинального заголовка + заливка на флешку.
|
|
$ErrorActionPreference = 'Stop'
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$work = 'C:\PF\KRD\images'
|
|
$bak = 'C:\PF\Ventoy\backup\xor-images'
|
|
New-Item -ItemType Directory -Force $bak | Out-Null
|
|
|
|
$map = @(
|
|
@{ png = 'legacy-1'; src = 'C:\PF\PSD\main\main1.bmp'; dst = 'F:\efi\Paravis\Boot\xor\Main1.bmp' },
|
|
@{ png = 'legacy-2'; src = 'C:\PF\PSD\main\main2.bmp'; dst = 'F:\efi\Paravis\Boot\xor\Main2.bmp' },
|
|
@{ png = 'x64-1'; src = 'C:\PF\PSD\UEFI\x64\main\main1.bmp'; dst = 'F:\efi\Boot\1x64.bmp' },
|
|
@{ png = 'x64-2'; src = 'C:\PF\PSD\UEFI\x64\main\main2.bmp'; dst = 'F:\efi\Boot\2x64.bmp' },
|
|
@{ png = 'x86-1'; src = 'C:\PF\PSD\UEFI\x86\main\main1.bmp'; dst = 'F:\efi\Boot\1x86.bmp' },
|
|
@{ png = 'x86-2'; src = 'C:\PF\PSD\UEFI\x86\main\main2.bmp'; dst = 'F:\efi\Boot\2x86.bmp' }
|
|
)
|
|
|
|
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена — сначала выключите' }
|
|
|
|
foreach ($m in $map) {
|
|
$pngPath = Join-Path $work ($m.png + '.png')
|
|
$srcBytes = [IO.File]::ReadAllBytes($m.src)
|
|
$off = [BitConverter]::ToUInt32($srcBytes, 10)
|
|
$w = [BitConverter]::ToInt32($srcBytes, 18)
|
|
$h = [BitConverter]::ToInt32($srcBytes, 22)
|
|
|
|
$img = [System.Drawing.Image]::FromFile($pngPath)
|
|
if ($img.Width -ne $w -or $img.Height -ne $h) { throw "$($m.png): размер $($img.Width)x$($img.Height) != ${w}x${h}" }
|
|
$bmp = New-Object System.Drawing.Bitmap $img
|
|
$img.Dispose()
|
|
|
|
$rowBytes = $w * 3
|
|
$pix = New-Object byte[] ($rowBytes * $h)
|
|
for ($y = 0; $y -lt $h; $y++) {
|
|
$srcY = $h - 1 - $y # BMP хранится снизу вверх
|
|
for ($x = 0; $x -lt $w; $x++) {
|
|
$c = $bmp.GetPixel($x, $srcY)
|
|
$o = $y * $rowBytes + $x * 3
|
|
$pix[$o] = $c.B
|
|
$pix[$o + 1] = $c.G
|
|
$pix[$o + 2] = $c.R
|
|
}
|
|
}
|
|
$bmp.Dispose()
|
|
|
|
$outBytes = New-Object byte[] $srcBytes.Length
|
|
[Array]::Copy($srcBytes, $outBytes, $srcBytes.Length)
|
|
[Array]::Copy($pix, 0, $outBytes, [int]$off, $pix.Length)
|
|
|
|
$outPath = Join-Path $work ($m.png + '.bmp')
|
|
[IO.File]::WriteAllBytes($outPath, $outBytes)
|
|
"--- {0}: {1:N0} байт (эталон {2:N0})" -f $m.png, $outBytes.Length, $srcBytes.Length
|
|
}
|
|
|
|
'--- заливка на флешку (с бэкапом):'
|
|
foreach ($m in $map) {
|
|
$b = Split-Path $m.dst -Leaf
|
|
if (Test-Path $m.dst) {
|
|
Copy-Item $m.dst (Join-Path $bak $b) -Force
|
|
}
|
|
Copy-Item (Join-Path $work ($m.png + '.bmp')) $m.dst -Force
|
|
$i = Get-Item $m.dst
|
|
" {0,-24} {1:N0} байт sha256={2}" -f $m.dst, $i.Length, (Get-FileHash $m.dst -Algorithm SHA256).Hash.Substring(0,12)
|
|
}
|
|
'--- бэкапы:'
|
|
Get-ChildItem $bak -File | Select-Object Name,Length | Format-Table -AutoSize
|