# scan-forensics.ps1 # One-shot evidence capture for the "scanner stops working" fault (WMS X9R tablet). # # Why: on 2026-09-25 the field log proved the break is BELOW the JS layer # (60s heartbeat keys=0 while every JS gate was green). The only thing JS cannot see is # whether the kernel/Activity still gets the key events. This script captures that layer. # # Usage (tablet plugged in, USB debugging on): # powershell -NoProfile -ExecutionPolicy Bypass -File scripts\scan-forensics.ps1 # powershell -NoProfile -ExecutionPolicy Bypass -File scripts\scan-forensics.ps1 -Seconds 30 # # Run it WHILE the fault is present, and scan the gun 3-5 times during the capture window. # Everything is kept (no cleanup) under -OutDir. # # Verdict rules: # kernel key DOWN > 0 but app heartbeat keys=0 -> Android dispatch / WebView / IME layer # kernel key DOWN = 0 -> gun / cable / USB port (hardware) or scan service # # ASCII only on purpose: `powershell -File` reads non-ASCII scripts as ANSI on this machine. param( [int]$Seconds = 20, [string]$OutDir = '' ) $ErrorActionPreference = 'Continue' function Find-Adb { $candidates = @( (Join-Path $env:LOCALAPPDATA 'Android\Sdk\platform-tools\adb.exe'), 'C:\Android\Sdk\platform-tools\adb.exe', 'D:\Android\Sdk\platform-tools\adb.exe' ) foreach ($c in $candidates) { if (Test-Path $c) { return $c } } $cmd = Get-Command adb -ErrorAction SilentlyContinue if ($cmd) { return $cmd.Source } throw 'adb.exe not found. Set PATH or edit Find-Adb in this script.' } if (-not $OutDir) { $OutDir = Join-Path $env:TEMP ('scan-forensics\' + (Get-Date -Format 'yyyyMMdd-HHmmss')) } New-Item -ItemType Directory -Force -Path $OutDir | Out-Null $adb = Find-Adb Write-Host "adb = $adb" Write-Host "out dir = $OutDir" Write-Host '' function Sh($cmd) { & $adb shell $cmd 2>&1 } function Save($name, $lines) { $path = Join-Path $OutDir $name $lines | Out-File -FilePath $path -Encoding utf8 Write-Host (" saved {0}" -f $name) } # 1) device present? $devices = & $adb devices 2>&1 $serial = ($devices | Select-String -Pattern '^\S+\s+device$' | ForEach-Object { $_.Line.Split()[0] }) | Select-Object -First 1 if (-not $serial) { Write-Host '!! no adb device. Check: USB debugging on, try another USB port (this box only works on some ports), replug.' -ForegroundColor Red Write-Host ($devices -join "`n") exit 2 } Write-Host "device = $serial" & $adb root 2>&1 | Out-Null & $adb wait-for-device 2>&1 | Out-Null # 2) static environment Save '00-device.txt' @( "serial = $serial", "captured = $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')", "id = $(Sh 'id')", "model = $(Sh 'getprop ro.product.model')", "android = $(Sh 'getprop ro.build.version.release') build=$(Sh 'getprop ro.build.type') selinux=$(Sh 'getenforce')", "uptime = $(Sh 'cat /proc/uptime') (seconds since boot - tells whether a reboot just happened)", "pkg = $(Sh 'dumpsys window | grep -E ''mCurrentFocus|mFocusedApp''')" ) Save '01-input-devices.txt' (Sh 'cat /proc/bus/input/devices') Save '02-dmesg-usb-input.txt' (Sh "dmesg | grep -iE 'usb|newtologic|hid|input:' | tail -n 120") Save '03-app-logcat.txt' (Sh "logcat -d -s WMSScan:V WMSPage:V UniConsole:V UniViewConsole:V | tail -n 400") Save '04-dumpsys-input.txt' (Sh 'dumpsys input | head -n 250') # 3) kernel key stream (scan now!) $gevPath = Join-Path $OutDir '05-getevent.txt' Write-Host '' Write-Host ("==> SCAN THE GUN 3-5 TIMES NOW (you have {0} seconds) <==" -f $Seconds) -ForegroundColor Yellow & $adb shell "timeout $Seconds getevent -lt" 2>&1 | Out-File -FilePath $gevPath -Encoding utf8 Write-Host (" saved 05-getevent.txt") # 4) verdict $gev = Get-Content $gevPath -ErrorAction SilentlyContinue $keyDown = @($gev | Select-String -Pattern 'EV_KEY\s+(KEY_[0-9A-Z_]+)\s+DOWN' -AllMatches) $enterDown = @($gev | Select-String -Pattern 'EV_KEY\s+KEY_ENTER\s+DOWN') $gunLines = @($gev | Select-String -Pattern 'event\d+.*EV_KEY') $logcat = Get-Content (Join-Path $OutDir '03-app-logcat.txt') -ErrorAction SilentlyContinue $health = @($logcat | Select-String -Pattern 'health.*keys=' | Select-Object -Last 1) Write-Host '' Write-Host '================ VERDICT ================' Write-Host ("kernel : key DOWN events = {0} (ENTER = {1})" -f $keyDown.Count, $enterDown.Count) Write-Host (" gun/kernel EV_KEY lines = {0}" -f $gunLines.Count) if ($health.Count -gt 0) { Write-Host ("app : last heartbeat -> {0}" -f $health[0].Line.Trim()) } else { Write-Host 'app : no WMSScan heartbeat in logcat buffer (buffer may have wrapped)' } Write-Host '' if ($keyDown.Count -ge 3) { Write-Host 'kernel HAS key events -> the break is ABOVE the kernel (Android dispatch / WebView / IME / app).' -ForegroundColor Green Write-Host ' Next: compare with the app heartbeat keys= above. keys=0 here means the app never got them.' } else { Write-Host 'kernel has NO (or almost no) key events -> gun / cable / USB port / scan service (hardware).' -ForegroundColor Red Write-Host ' Next: swap cable+port, watch dmesg in 02-dmesg-usb-input.txt for disconnect/reconnect.' } Write-Host '' Write-Host 'Keep this folder for the vendor/customer report. Nothing was deleted.'