24 lines
1.0 KiB
PowerShell
24 lines
1.0 KiB
PowerShell
|
|
# Byte-safe device screenshot helper.
|
||
|
|
# ASCII-only. PS 5.1 `>` redirection writes UTF-16, which corrupts PNG bytes
|
||
|
|
# (measured 2026-10-30: `adb exec-out screencap -p > x.png` produced a file
|
||
|
|
# starting with FF FE). Capture on-device and pull instead.
|
||
|
|
param(
|
||
|
|
[Parameter(Mandatory = $true)][string]$Out,
|
||
|
|
[string]$Device = "/sdcard/shot.png"
|
||
|
|
)
|
||
|
|
$ErrorActionPreference = "Stop"
|
||
|
|
$adb = "D:\working\android\sdk\platform-tools\adb.exe"
|
||
|
|
$old = $ErrorActionPreference
|
||
|
|
$ErrorActionPreference = "Continue"
|
||
|
|
try {
|
||
|
|
& $adb shell screencap -p $Device | Out-Null
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "screencap failed ($LASTEXITCODE)" }
|
||
|
|
& $adb pull $Device $Out | Out-Null
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "pull failed ($LASTEXITCODE)" }
|
||
|
|
}
|
||
|
|
finally { $ErrorActionPreference = $old }
|
||
|
|
$b = [System.IO.File]::ReadAllBytes($Out)
|
||
|
|
$sig = ($b[0..3] | ForEach-Object { $_.ToString("X2") }) -join " "
|
||
|
|
if ($sig -ne "89 50 4E 47") { throw "not a PNG (sig=$sig): $Out" }
|
||
|
|
Write-Host ("OK {0} ({1:N0} bytes)" -f (Split-Path $Out -Leaf), $b.Length)
|