Exploit database

GH-945bd5267b0d1b94c3f74faf5cda7e5a

blkph0x/cve-2026-83844_poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-83844

5 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files14
blkph0x/cve-2026-83844_pocRevision 193ed44859da

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

lab/corpus/followup/guest_fill_action.ps1

PowerShell · 51,986 bytes
# Dot-source from guest_action.ps1 only for a dedicated, bounded C12 action.
# The caller checks the signed package, exact Paint PID, input hash and CDB
# profile before invoking this function. This helper independently verifies
# UI tolerance, canvas geometry and the visible pinned raster before clicking.

function Invoke-PaintFillAction {
    param(
        [Parameter(Mandatory = $true)][int]$PaintPid,
        [Parameter(Mandatory = $true)][string]$FixturePath,
        [Parameter(Mandatory = $true)][ValidateSet(0,1)][int]$Tolerance,
        [ValidateSet(100,300,800)][int]$ZoomPercent = 800,
        [ValidateSet(16,257)][int]$ExpectedWidth = 16,
        [ValidateSet(16,129)][int]$ExpectedHeight = 16,
        [ValidateRange(0,256)][int]$ClickImageX = 3,
        [ValidateRange(-1,128)][int]$ClickImageY = -1,
        [Parameter(Mandatory = $true)][string]$OutDir,
        [Parameter(Mandatory = $true)][string]$CdbLogPath,
        [ValidateSet('SendInput', 'mouse_event', 'touch')][string]$CanvasInputMethod = 'SendInput',
        [switch]$HeapLookup,
        [switch]$AttemptDeselect,
        [switch]$HoverDrain
    )

    $marker = 'C:\PaintLab\guest.marker'
    if ($env:USERNAME -ne 'WDAGUtilityAccount' -or
        -not (Test-Path -LiteralPath $marker -PathType Leaf) -or
        (Get-Content -LiteralPath $marker -Raw).Trim() -ne 'PaintABLab-Sandbox-v1') {
        throw 'Fill action is restricted to the disposable Paint guest.'
    }
    if (($ExpectedWidth -eq 16 -and ($ExpectedHeight -ne 16 -or $ZoomPercent -ne 800)) -or
        ($ExpectedWidth -eq 257 -and $ExpectedHeight -ne 129) -or
        ($ExpectedWidth -eq 257 -and $ZoomPercent -ne 300)) {
        throw 'Fill geometry/zoom differs from the two pinned lab profiles.'
    }
    $seedY = if ($ClickImageY -ge 0) { $ClickImageY } else {
        [int][Math]::Floor($ExpectedHeight/2)
    }
    if ($ClickImageX -ge $ExpectedWidth -or $seedY -ge $ExpectedHeight) {
        throw 'Fill seed lies outside the pinned image.'
    }
    Add-Type -AssemblyName UIAutomationClient
    Add-Type -AssemblyName UIAutomationTypes
    Add-Type -AssemblyName System.Drawing
    Add-Type -AssemblyName System.Windows.Forms
    if (-not ('PaintFillMouse' -as [type])) {
        Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class PaintFillMouse {
    [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
    [DllImport("user32.dll")] public static extern bool GetCursorPos(out Point point);
    [DllImport("user32.dll")] public static extern void mouse_event(uint flags, uint dx, uint dy, uint data, UIntPtr extraInfo);
    [StructLayout(LayoutKind.Sequential)] public struct MouseInput {
        public int dx; public int dy; public uint mouseData; public uint dwFlags;
        public uint time; public UIntPtr dwExtraInfo;
    }
    [StructLayout(LayoutKind.Explicit)] public struct Input {
        [FieldOffset(0)] public uint type;
        [FieldOffset(8)] public MouseInput mi;
    }
    [DllImport("user32.dll", SetLastError=true)]
    private static extern uint SendInput(uint count, [In] Input[] entries, int size);
    public static uint SendMouseEvent(uint flags, out int win32Error) {
        var entry = new Input { type = 0, mi = new MouseInput { dwFlags = flags } };
        uint sent = SendInput(1, new Input[] { entry }, Marshal.SizeOf(typeof(Input)));
        win32Error = sent == 1 ? 0 : Marshal.GetLastWin32Error();
        return sent;
    }
    public static uint SendMouseMove(int dx, int dy, out int win32Error) {
        var entry = new Input { type = 0, mi = new MouseInput { dx = dx, dy = dy, dwFlags = 1 } };
        uint sent = SendInput(1, new Input[] { entry }, Marshal.SizeOf(typeof(Input)));
        win32Error = sent == 1 ? 0 : Marshal.GetLastWin32Error();
        return sent;
    }
    [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
    [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr window, out uint processId);
    [StructLayout(LayoutKind.Sequential)] public struct Point { public int X; public int Y; }
    [DllImport("user32.dll")] public static extern IntPtr WindowFromPoint(Point point);
}
'@
    }
    if ($CanvasInputMethod -eq 'touch' -and -not ('PaintFillTouch' -as [type])) {
        Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class PaintFillTouch {
    public const uint DownFlags = 0x00010006;   // INRANGE | INCONTACT | DOWN
    public const uint UpdateFlags = 0x00020006; // INRANGE | INCONTACT | UPDATE
    public const uint UpFlags = 0x00040002;     // INRANGE | UP
    [StructLayout(LayoutKind.Sequential, Pack=8)] public struct Point {
        public int X, Y;
    }
    [StructLayout(LayoutKind.Sequential, Pack=8)] public struct Rect {
        public int Left, Top, Right, Bottom;
    }
    [StructLayout(LayoutKind.Sequential, Pack=8)] public struct PointerInfo {
        public uint pointerType, pointerId, frameId, pointerFlags;
        public IntPtr sourceDevice, hwndTarget;
        public Point ptPixelLocation, ptHimetricLocation;
        public Point ptPixelLocationRaw, ptHimetricLocationRaw;
        public uint dwTime, historyCount;
        public int InputData;
        public uint dwKeyStates;
        public ulong PerformanceCount;
        public uint ButtonChangeType;
    }
    [StructLayout(LayoutKind.Sequential, Pack=8)] public struct TouchInfo {
        public PointerInfo pointerInfo;
        public uint touchFlags, touchMask;
        public Rect rcContact, rcContactRaw;
        public uint orientation, pressure;
    }
    [DllImport("user32.dll", SetLastError=true)]
    private static extern bool InitializeTouchInjection(uint maxCount, uint mode);
    [DllImport("user32.dll", SetLastError=true)]
    private static extern bool InjectTouchInput(uint count, [In] ref TouchInfo contact);
    public static int PointerInfoSize() { return Marshal.SizeOf(typeof(PointerInfo)); }
    public static int TouchInfoSize() { return Marshal.SizeOf(typeof(TouchInfo)); }
    public static bool LayoutValid() {
        return IntPtr.Size == 8 &&
            PointerInfoSize() == 96 &&
            TouchInfoSize() == 144 &&
            Marshal.OffsetOf(typeof(PointerInfo), "ptPixelLocation").ToInt32() == 32 &&
            Marshal.OffsetOf(typeof(PointerInfo), "PerformanceCount").ToInt32() == 80 &&
            Marshal.OffsetOf(typeof(TouchInfo), "touchFlags").ToInt32() == 96 &&
            Marshal.OffsetOf(typeof(TouchInfo), "rcContact").ToInt32() == 104;
    }
    public static TouchInfo Frame(int x, int y, uint flags, int radius) {
        var point = new Point { X = x, Y = y };
        var area = new Rect { Left = x-radius, Top = y-radius,
                              Right = x+radius, Bottom = y+radius };
        return new TouchInfo {
            pointerInfo = new PointerInfo {
                pointerType = 2, pointerId = 0, pointerFlags = flags,
                ptPixelLocation = point
            },
            touchFlags = 0, touchMask = 0x5, // CONTACTAREA | PRESSURE
            rcContact = area, pressure = 512
        };
    }
    public static bool Initialize(out int error) {
        bool ok = InitializeTouchInjection(1, 3); // one contact, no feedback
        error = ok ? 0 : Marshal.GetLastWin32Error();
        return ok;
    }
    public static bool Send(ref TouchInfo info, out int error) {
        bool ok = InjectTouchInput(1, ref info);
        error = ok ? 0 : Marshal.GetLastWin32Error();
        return ok;
    }
}
'@
    }

    function Get-Elements([System.Windows.Automation.AutomationElement]$Window) {
        $all = $Window.FindAll([System.Windows.Automation.TreeScope]::Descendants,
                               [System.Windows.Automation.Condition]::TrueCondition)
        @(
            for ($i = 0; $i -lt [Math]::Min($all.Count,1000); $i++) {
                $element = $all.Item($i)
                try {
                    $current = $element.Current
                    [pscustomobject]@{
                        element = $element
                        name = [string]$current.Name
                        id = [string]$current.AutomationId
                        type = [string]$current.ControlType.ProgrammaticName
                        rect = $current.BoundingRectangle
                    }
                } catch { }
            }
        )
    }

    function Get-ReadyElements([System.Windows.Automation.AutomationElement]$Window,
                               [ValidateSet('tolerance','color-zoom','canvas')][string]$Phase) {
        # A debugger-attached UIA FindAll can transiently throw after a tool
        # click. Retry the same named-control gate; never substitute pixels or
        # a title for semantic UI readback.
        $started = Get-Date
        $deadline = $started.AddSeconds(8)
        $attempts = @()
        $rows = @()
        $ready = $false
        do {
            $errorType = $null
            $errorMessage = $null
            try { $rows = @(Get-Elements $Window) }
            catch {
                $rows = @()
                $errorType = $_.Exception.GetType().FullName
                $errorMessage = $_.Exception.Message
            }
            $tolerance = @($rows | Where-Object {
                $_.type -eq 'ControlType.Slider' -and $_.name -eq 'Tolerance'
            })
            $color = @($rows | Where-Object {
                $_.type -eq 'ControlType.RadioButton' -and $_.name -eq 'Color 1: Black'
            })
            $zoom = @($rows | Where-Object {
                $_.type -eq 'ControlType.Slider' -and $_.name -eq 'Zoom'
            })
            $canvas = @($rows | Where-Object {
                $_.type -eq 'ControlType.Group' -and $_.id -eq 'image' -and
                $_.name -match '^Using Fill with color tool on Canvas' -and
                [double]$_.rect.Width -eq $ExpectedWidth*($ZoomPercent/100) -and
                [double]$_.rect.Height -eq $ExpectedHeight*($ZoomPercent/100)
            })
            $observedImageGroups = @($rows | Where-Object {
                $_.type -eq 'ControlType.Group' -and $_.id -eq 'image'
            } | Select-Object -First 4 | ForEach-Object {
                [ordered]@{
                    name = $_.name
                    rect = @([double]$_.rect.Left,[double]$_.rect.Top,
                             [double]$_.rect.Width,[double]$_.rect.Height)
                }
            })
            $ready = switch ($Phase) {
                'tolerance' { $tolerance.Count -eq 1 }
                'color-zoom' { $color.Count -eq 1 -and $zoom.Count -eq 1 }
                'canvas' { $canvas.Count -eq 1 }
            }
            $attempts += [ordered]@{
                elapsed_ms = [int]((Get-Date) - $started).TotalMilliseconds
                control_count = $rows.Count
                tolerance_count = $tolerance.Count
                color1_black_count = $color.Count
                zoom_count = $zoom.Count
                named_scaled_fill_canvas_count = $canvas.Count
                observed_image_groups = $observedImageGroups
                uia_error_type = $errorType
                uia_error_message = $errorMessage
                sampled_names = @($rows | Select-Object -First 12 | ForEach-Object { $_.name })
            }
            if ($ready) { break }
            Start-Sleep -Milliseconds 250
        } while ((Get-Date) -lt $deadline)
        $record = [ordered]@{
            schema = 'paint-fill-uia-readiness-v1'
            phase = $Phase
            ready = $ready
            deadline_ms = 8000
            wait_ms = [int]((Get-Date) - $started).TotalMilliseconds
            attempts = $attempts
            failure_screenshot = $null
        }
        if (-not $ready) {
            try {
                $failureShot = Join-Path $OutDir "fill-uia-$Phase-failure.png"
                Save-FillScreenshot $failureShot
                $record.failure_screenshot = "fill-uia-$Phase-failure.png"
            } catch {
                $record.screenshot_error_type = $_.Exception.GetType().FullName
            }
        }
        $record | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath `
            (Join-Path $OutDir "fill-uia-$Phase-readiness.json") -Encoding UTF8
        if (-not $ready) { throw "Fill UIA $Phase did not meet the exact control gate within 8 seconds." }
        $rows
    }

    function Click-Control([System.Windows.Rect]$Rect) {
        $x = [int][Math]::Floor(($Rect.Left + $Rect.Right) / 2)
        $y = [int][Math]::Floor(($Rect.Top + $Rect.Bottom) / 2)
        if (-not [PaintFillMouse]::SetCursorPos($x,$y)) { throw 'Could not point at UI control.' }
        [PaintFillMouse]::mouse_event(2,0,0,0,[UIntPtr]::Zero)
        [PaintFillMouse]::mouse_event(4,0,0,0,[UIntPtr]::Zero)
    }

    function Get-PointCanvasHit([int]$X,[int]$Y,[int]$ExpectedPid) {
        $node = [System.Windows.Automation.AutomationElement]::FromPoint(
            [System.Windows.Point]::new([double]$X,[double]$Y))
        $walker = [System.Windows.Automation.TreeWalker]::RawViewWalker
        $chain = @()
        $found = $false
        for ($depth = 0; $depth -lt 8 -and $null -ne $node; $depth++) {
            try {
                $current = $node.Current
                $rect = $current.BoundingRectangle
                $row = [ordered]@{
                    name = [string]$current.Name
                    automation_id = [string]$current.AutomationId
                    control_type = [string]$current.ControlType.ProgrammaticName
                    process_id = [int]$current.ProcessId
                    rect = @([int]$rect.Left,[int]$rect.Top,[int]$rect.Right,[int]$rect.Bottom)
                }
                $chain += $row
                if ($row.automation_id -eq 'image' -and
                    $row.name -match '^Using Fill with color tool on Canvas' -and
                    $row.process_id -eq $ExpectedPid -and
                    $X -ge $rect.Left -and $X -lt $rect.Right -and
                    $Y -ge $rect.Top -and $Y -lt $rect.Bottom) {
                    $found = $true
                }
                $node = $walker.GetParent($node)
            } catch { break }
        }
        $paintPaneWindowChain = (
            $chain.Count -ge 2 -and
            $chain[0].control_type -eq 'ControlType.Pane' -and
            $chain[0].process_id -eq $ExpectedPid -and
            $chain[1].control_type -eq 'ControlType.Window' -and
            $chain[1].process_id -eq $ExpectedPid -and
            $chain[1].name -match ' - Paint$'
        )
        return [ordered]@{
            canvas_ancestor_found = $found
            paint_pane_window_chain_found = $paintPaneWindowChain
            chain = $chain
        }
    }

    function Save-FillScreenshot([string]$Path) {
        $bounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
        $bitmap = [System.Drawing.Bitmap]::new($bounds.Width,$bounds.Height)
        $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
        try {
            $graphics.CopyFromScreen($bounds.Location,[System.Drawing.Point]::Empty,$bounds.Size)
            $bitmap.Save($Path,[System.Drawing.Imaging.ImageFormat]::Png)
        } finally {
            $graphics.Dispose()
            $bitmap.Dispose()
        }
    }

    function Get-RgbBytes([string]$Path,[int]$Left,[int]$Top,[int]$Scale) {
        $bitmap = [System.Drawing.Bitmap]::FromFile($Path)
        try {
            if ($Left -lt 0 -or $Top -lt 0 -or $Left + $ExpectedWidth*$Scale -gt $bitmap.Width -or
                $Top + $ExpectedHeight*$Scale -gt $bitmap.Height) {
                throw 'Scaled pinned raster lies outside the image.'
            }
            $bytes = New-Object byte[] ($ExpectedWidth*$ExpectedHeight*3)
            $offset = 0
            for ($y = 0; $y -lt $ExpectedHeight; $y++) {
                for ($x = 0; $x -lt $ExpectedWidth; $x++) {
                    $color = $bitmap.GetPixel($Left + $x*$Scale + [int][Math]::Floor($Scale/2),
                                              $Top + $y*$Scale + [int][Math]::Floor($Scale/2))
                    $bytes[$offset++] = $color.R
                    $bytes[$offset++] = $color.G
                    $bytes[$offset++] = $color.B
                }
            }
            return ,$bytes
        } finally { $bitmap.Dispose() }
    }

    function Hash-Rgb([byte[]]$Bytes) {
        $hash = [System.Security.Cryptography.SHA256]::Create()
        try { [BitConverter]::ToString($hash.ComputeHash($Bytes)).Replace('-','').ToLowerInvariant() }
        finally { $hash.Dispose() }
    }

    function Get-WhiteHandleSentinels([string]$Path,[int]$Left,[int]$Top,[int]$Scale = 1) {
        $bitmap = [System.Drawing.Bitmap]::FromFile($Path)
        try {
            $count = 0
            $middleX = [int][Math]::Floor($ExpectedWidth*$Scale/2)
            $middleY = [int][Math]::Floor($ExpectedHeight*$Scale/2)
            $outsideX = $ExpectedWidth*$Scale+4
            $outsideY = $ExpectedHeight*$Scale+4
            foreach ($dy in @(-4,$middleY,$outsideY)) {
                foreach ($dx in @(-4,$middleX,$outsideX)) {
                    if ($dx -eq $middleX -and $dy -eq $middleY) { continue }
                    $x = $Left + $dx
                    $y = $Top + $dy
                    if ($x -lt 0 -or $y -lt 0 -or $x -ge $bitmap.Width -or $y -ge $bitmap.Height) {
                        throw 'Handle sentinel lies outside screenshot.'
                    }
                    $color = $bitmap.GetPixel($x,$y)
                    if ($color.R -eq 255 -and $color.G -eq 255 -and $color.B -eq 255) { $count++ }
                }
            }
            return $count
        } finally { $bitmap.Dispose() }
    }

    function Cdb-Markers([string]$Path) {
        if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { return @() }
        @(
            foreach ($line in (Get-Content -LiteralPath $Path -ErrorAction SilentlyContinue)) {
                if ($line -match '^PAINT_TRACE_HIT=([a-z0-9_]+)\s*$') { $Matches[1] }
            }
        )
    }

    $paint = Get-Process -Id $PaintPid -ErrorAction Stop
    if ($paint.ProcessName -ne 'mspaint' -or $paint.MainWindowHandle -eq [IntPtr]::Zero) {
        throw 'Expected exact visible Paint PID for fill action.'
    }
    $window = [System.Windows.Automation.AutomationElement]::FromHandle($paint.MainWindowHandle)
    $windowRect = $window.Current.BoundingRectangle
    $shell = New-Object -ComObject WScript.Shell
    if (-not $shell.AppActivate($PaintPid)) { throw 'Could not foreground Paint for fill action.' }

    # The file-dialog title can update before the canvas's UIA geometry does,
    # particularly while the debugger filters frequent window messages.
    # Wait for the same exact gate, then record observed controls on failure.
    $canvasReadyStart = Get-Date
    $canvasReadyDeadline = $canvasReadyStart.AddSeconds(8)
    $canvasReadyAttempts = @()
    $initialCanvas = @()
    $before = @()
    do {
        $uiaErrorType = $null
        try {
            $before = @(Get-Elements $window)
        } catch {
            $before = @()
            $uiaErrorType = $_.Exception.GetType().FullName
        }
        $initialCanvas = @($before | Where-Object {
            $_.type -eq 'ControlType.Group' -and $_.id -eq 'image'
        })
        $observed = @($initialCanvas | Select-Object -First 8 | ForEach-Object {
            [ordered]@{
                name = $_.name
                rect = @([double]$_.rect.Left,[double]$_.rect.Top,
                         [double]$_.rect.Width,[double]$_.rect.Height)
            }
        })
        $canvasReadyAttempts += [ordered]@{
            elapsed_ms = [int]((Get-Date) - $canvasReadyStart).TotalMilliseconds
            image_group_count = $initialCanvas.Count
            image_groups = $observed
            uia_error_type = $uiaErrorType
        }
        if ($initialCanvas.Count -eq 1 -and
            [double]$initialCanvas[0].rect.Width -eq $ExpectedWidth -and
            [double]$initialCanvas[0].rect.Height -eq $ExpectedHeight) { break }
        Start-Sleep -Milliseconds 250
    } while ((Get-Date) -lt $canvasReadyDeadline)
    $canvasReady = ($initialCanvas.Count -eq 1 -and
        [double]$initialCanvas[0].rect.Width -eq $ExpectedWidth -and
        [double]$initialCanvas[0].rect.Height -eq $ExpectedHeight)
    $canvasReadyRecord = [ordered]@{
        schema = 'paint-fill-canvas-readiness-v1'
        expected_image_groups = 1
        expected_rect_size = @($ExpectedWidth,$ExpectedHeight)
        ready = $canvasReady
        wait_ms = [int]((Get-Date) - $canvasReadyStart).TotalMilliseconds
        attempts = $canvasReadyAttempts
        failure_screenshot = $null
    }
    if (-not $canvasReady) {
        try {
            $failureShot = Join-Path $OutDir 'fill-canvas-readiness-failure.png'
            Save-FillScreenshot $failureShot
            $canvasReadyRecord.failure_screenshot = 'fill-canvas-readiness-failure.png'
        } catch {
            $canvasReadyRecord.screenshot_error_type = $_.Exception.GetType().FullName
        }
    }
    $canvasReadyRecord | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath `
        (Join-Path $OutDir 'fill-canvas-readiness.json') -Encoding UTF8
    if (-not $canvasReady) {
        throw 'Pre-Esc canvas did not become the unique pinned screen rectangle within 8 seconds; see fill-canvas-readiness.json.'
    }
    $initialLeft = [int]$initialCanvas[0].rect.Left
    $initialTop = [int]$initialCanvas[0].rect.Top
    $beforeEscFile = Join-Path $OutDir 'fill-before-esc.png'
    Save-FillScreenshot $beforeEscFile
    [System.Windows.Forms.SendKeys]::SendWait('{ESC}')
    Start-Sleep -Milliseconds 500
    $afterEscFile = Join-Path $OutDir 'fill-after-esc.png'
    Save-FillScreenshot $afterEscFile
    $escProbe = [ordered]@{
        screenshot_before = 'fill-before-esc.png'
        screenshot_after = 'fill-after-esc.png'
        white_handle_sentinels_before = Get-WhiteHandleSentinels $beforeEscFile $initialLeft $initialTop
        white_handle_sentinels_after = Get-WhiteHandleSentinels $afterEscFile $initialLeft $initialTop
    }
    $deselectProbe = $null
    if ($AttemptDeselect) {
        # This shortcut is an experimental UI action, not an assumed Paint
        # contract. The trial stops unless the handles vanish and all 256
        # source pixels remain identical in the same 16x16 rectangle.
        if (-not $shell.AppActivate($PaintPid)) { throw 'Paint lost foreground before deselect attempt.' }
        [System.Windows.Forms.SendKeys]::SendWait('^d')
        Start-Sleep -Milliseconds 500
        $deselectFile = Join-Path $OutDir 'fill-after-deselect.png'
        Save-FillScreenshot $deselectFile
        $deselectExpected = Get-RgbBytes $FixturePath 0 0 1
        $deselectVisible = Get-RgbBytes $deselectFile $initialLeft $initialTop 1
        $samePixels = $deselectExpected.Length -eq $deselectVisible.Length
        if ($samePixels) {
            for ($i = 0; $i -lt $deselectExpected.Length; $i++) {
                if ($deselectExpected[$i] -ne $deselectVisible[$i]) {
                    $samePixels = $false
                    break
                }
            }
        }
        $remainingHandles = Get-WhiteHandleSentinels $deselectFile $initialLeft $initialTop
        $deselectProbe = [ordered]@{
            action = 'Ctrl+D experimental deselect'
            screenshot = 'fill-after-deselect.png'
            white_handle_sentinels_before = [int]$escProbe.white_handle_sentinels_after
            white_handle_sentinels_after = $remainingHandles
            expected_rgb_sha256 = Hash-Rgb $deselectExpected
            visible_rgb_sha256 = Hash-Rgb $deselectVisible
            exact_visible_fixture = $samePixels
            passed = ([int]$escProbe.white_handle_sentinels_after -eq 8 -and
                      $remainingHandles -eq 0 -and $samePixels)
        }
        $deselectProbe | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath `
            (Join-Path $OutDir 'fill-deselect-preflight.json') -Encoding UTF8
        if (-not $deselectProbe.passed) {
            throw 'Deselect attempt did not produce an 8-to-0 handle transition while preserving the exact 16x16 raster.'
        }
    }
    $fillReadyStart = Get-Date
    $fillReadyDeadline = $fillReadyStart.AddSeconds(8)
    $fillReadyAttempts = @()
    $buttons = @()
    do {
        $uiaErrorType = $null
        try {
            $before = @(Get-Elements $window)
        } catch {
            $before = @()
            $uiaErrorType = $_.Exception.GetType().FullName
        }
        $allButtons = @($before | Where-Object { $_.type -eq 'ControlType.Button' })
        $buttons = @($allButtons | Where-Object { $_.name -eq 'Fill' })
        $fillNamed = @($allButtons | Where-Object { $_.name -match 'Fill' } |
            Select-Object -First 8 | ForEach-Object {
                [ordered]@{
                    name = $_.name
                    rect = @([double]$_.rect.Left,[double]$_.rect.Top,
                             [double]$_.rect.Width,[double]$_.rect.Height)
                }
            })
        $fillReadyAttempts += [ordered]@{
            elapsed_ms = [int]((Get-Date) - $fillReadyStart).TotalMilliseconds
            button_count = $allButtons.Count
            exact_fill_count = $buttons.Count
            fill_named_buttons = $fillNamed
            sampled_button_names = @($allButtons | Select-Object -First 16 |
                ForEach-Object { $_.name })
            uia_error_type = $uiaErrorType
        }
        if ($buttons.Count -eq 1) { break }
        Start-Sleep -Milliseconds 250
    } while ((Get-Date) -lt $fillReadyDeadline)
    $fillReady = $buttons.Count -eq 1
    $fillReadyRecord = [ordered]@{
        schema = 'paint-fill-button-readiness-v1'
        expected_button_name = 'Fill'
        expected_count = 1
        ready = $fillReady
        wait_ms = [int]((Get-Date) - $fillReadyStart).TotalMilliseconds
        attempts = $fillReadyAttempts
        failure_screenshot = $null
    }
    if (-not $fillReady) {
        try {
            $failureShot = Join-Path $OutDir 'fill-button-readiness-failure.png'
            Save-FillScreenshot $failureShot
            $fillReadyRecord.failure_screenshot = 'fill-button-readiness-failure.png'
        } catch {
            $fillReadyRecord.screenshot_error_type = $_.Exception.GetType().FullName
        }
    }
    $fillReadyRecord | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath `
        (Join-Path $OutDir 'fill-button-readiness.json') -Encoding UTF8
    if (-not $fillReady) {
        throw 'Fill button did not become unique within 8 seconds; see fill-button-readiness.json.'
    }
    $button = $buttons[0]
    if ($button.rect.Left -le $windowRect.Left -or $button.rect.Right -ge $windowRect.Right -or
        $button.rect.Top -le $windowRect.Top -or $button.rect.Bottom -ge $windowRect.Bottom) {
        throw 'Fill button rectangle lies outside the Paint window.'
    }
    Click-Control $button.rect
    Start-Sleep -Milliseconds 700
    $after = @(Get-ReadyElements $window 'tolerance')
    $sliders = @($after | Where-Object { $_.type -eq 'ControlType.Slider' -and $_.name -eq 'Tolerance' })
    if ($sliders.Count -ne 1) { throw "Expected one tolerance slider; found $($sliders.Count)." }
    $range = $null
    if (-not $sliders[0].element.TryGetCurrentPattern(
        [System.Windows.Automation.RangeValuePattern]::Pattern,[ref]$range)) {
        throw 'Tolerance slider has no RangeValuePattern.'
    }
    if ($range.Current.IsReadOnly -or $range.Current.Minimum -ne 0 -or
        $range.Current.Maximum -ne 100 -or $range.Current.SmallChange -ne 1) {
        throw 'Tolerance slider range differs from the paired UI-control observation.'
    }
    $range.SetValue([double]$Tolerance)
    Start-Sleep -Milliseconds 300
    $actualTolerance = [double]$range.Current.Value
    if ($actualTolerance -ne [double]$Tolerance) {
        throw "Tolerance readback $actualTolerance differs from requested $Tolerance."
    }
    $after = @(Get-ReadyElements $window 'color-zoom')
    $color1 = @($after | Where-Object { $_.type -eq 'ControlType.RadioButton' -and $_.name -eq 'Color 1: Black' })
    if ($color1.Count -ne 1) { throw 'Color 1 is not uniquely verified as Black.' }
    $zoom = @($after | Where-Object { $_.type -eq 'ControlType.Slider' -and $_.name -eq 'Zoom' })
    if ($zoom.Count -ne 1) { throw 'Zoom slider is not unique.' }
    $zoomPattern = $null
    if (-not $zoom[0].element.TryGetCurrentPattern(
        [System.Windows.Automation.RangeValuePattern]::Pattern,[ref]$zoomPattern)) {
        throw 'Zoom slider has no RangeValuePattern.'
    }
    $zoomPattern.SetValue([double]$ZoomPercent)
    Start-Sleep -Milliseconds 600
    if ([double]$zoomPattern.Current.Value -ne [double]$ZoomPercent) {
        throw "Zoom readback differs from requested $ZoomPercent%."
    }
    $after = @(Get-ReadyElements $window 'canvas')
    $canvas = @($after | Where-Object { $_.type -eq 'ControlType.Group' -and $_.id -eq 'image' })
    if ($canvas.Count -ne 1 -or $canvas[0].name -notmatch '^Using Fill with color tool on Canvas') {
        throw 'Fill canvas UI control is not uniquely identified.'
    }
    $rect = $canvas[0].rect
    $scale = [int]($ZoomPercent / 100)
    if ([double]$rect.Width -ne $ExpectedWidth*$scale -or [double]$rect.Height -ne $ExpectedHeight*$scale -or
        [double]$rect.Left -ne [Math]::Floor($rect.Left) -or
        [double]$rect.Top -ne [Math]::Floor($rect.Top)) {
        throw 'Paint canvas does not match the pinned zoom rectangle.'
    }
    $left = [int]$rect.Left
    $top = [int]$rect.Top
    $preFile = Join-Path $OutDir 'fill-before-click.png'
    Save-FillScreenshot $preFile
    $handlesBeforeClick = if ($AttemptDeselect) {
        Get-WhiteHandleSentinels $preFile $left $top $scale
    } else { $null }
    $fixtureBytes = Get-RgbBytes $FixturePath 0 0 1
    $preBytes = Get-RgbBytes $preFile $left $top $scale
    for ($i = 0; $i -lt $fixtureBytes.Length; $i++) {
        if ($preBytes[$i] -ne $fixtureBytes[$i]) {
            throw 'Visible Paint canvas does not exactly match the pinned fixture.'
        }
    }
    $clickX = $left + $ClickImageX*$scale + [int][Math]::Floor($scale/2)
    $clickY = $top + $seedY*$scale + [int][Math]::Floor($scale/2)
    $touchContactRadius = if ($ExpectedWidth -eq 257 -and $ExpectedHeight -eq 129 -and
                              $ClickImageX -eq 256 -and $seedY -eq 128) { 1 } else { 2 }
    $preflight = [ordered]@{
        schema = 'paint-fill-click-preflight-v1'
        target_tolerance = $Tolerance
        tolerance_readback = $actualTolerance
        tolerance_range = [ordered]@{ min=0; max=100; small_change=1; read_only=$false }
        color1 = 'Black'
        zoom_percent = $ZoomPercent
        image_size = @($ExpectedWidth,$ExpectedHeight)
        canvas_rect = @($left,$top,($left+$ExpectedWidth*$scale),($top+$ExpectedHeight*$scale))
        fixture_rgb_sha256 = Hash-Rgb $fixtureBytes
        screen_rgb_sha256 = Hash-Rgb $preBytes
        exact_visible_fixture = $true
        white_handle_sentinels_before_click = $handlesBeforeClick
        deselect_attempted = [bool]$AttemptDeselect
        hover_drain_attempted = [bool]$HoverDrain
        canvas_input_method = $CanvasInputMethod
        hover_handler_new_hit_before_click = $false
        hover_handler_wait_ms = $null
        hover_settle_ms = $null
        move_preflight_sent = $false
        move_preflight_accepted = $false
        click_image_pixel = @($ClickImageX,$seedY)
        click_screen_point = @($clickX,$clickY)
        markers_before_click = @(Cdb-Markers $CdbLogPath)
    }
    $preflightPath = Join-Path $OutDir 'fill-click-preflight.json'
    if ($AttemptDeselect -and $handlesBeforeClick -ne 0) {
        $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
        throw 'Image handles reappeared before the verified Fill click.'
    }
    if (-not $shell.AppActivate($PaintPid)) { throw 'Paint could not be foregrounded before bucket click.' }
    Start-Sleep -Milliseconds 150
    [uint32]$foregroundPid = 0
    $null = [PaintFillMouse]::GetWindowThreadProcessId(
        [PaintFillMouse]::GetForegroundWindow(),[ref]$foregroundPid)
    if ($foregroundPid -ne [uint32]$PaintPid) {
        throw 'Foreground process does not match the signed Paint PID before click.'
    }
    $markersBeforeMove = @(Cdb-Markers $CdbLogPath)
    $inRangeBeforeMove = @($markersBeforeMove | Where-Object {
        $_ -eq 'fill_deep_ui_in_range_handler'
    }).Count
    if (-not [PaintFillMouse]::SetCursorPos($clickX,$clickY)) {
        throw 'Could not point at the verified canvas pixel.'
    }
    Start-Sleep -Milliseconds 120
    $actualPointer = [PaintFillMouse+Point]::new()
    if (-not [PaintFillMouse]::GetCursorPos([ref]$actualPointer) -or
        $actualPointer.X -ne $clickX -or $actualPointer.Y -ne $clickY) {
        throw 'Mouse pointer did not remain at the verified canvas pixel.'
    }
    [uint32]$foregroundAfterMove = 0
    $null = [PaintFillMouse]::GetWindowThreadProcessId(
        [PaintFillMouse]::GetForegroundWindow(),[ref]$foregroundAfterMove)
    if ($foregroundAfterMove -ne [uint32]$PaintPid) {
        throw 'Paint lost foreground ownership after pointing at the canvas.'
    }
    $point = [PaintFillMouse+Point]::new()
    $point.X = $clickX
    $point.Y = $clickY
    [uint32]$targetPid = 0
    $null = [PaintFillMouse]::GetWindowThreadProcessId(
        [PaintFillMouse]::WindowFromPoint($point),[ref]$targetPid)
    if ($targetPid -ne [uint32]$PaintPid) {
        throw 'Window at the verified canvas pixel does not belong to Paint.'
    }
    $preflight.foreground_matches_paint = $true
    $preflight.point_window_matches_paint = $true
    $pointHit = Get-PointCanvasHit $clickX $clickY $PaintPid
    $preflight.point_automation_chain = @($pointHit.chain)
    $preflight.point_canvas_ancestor_found = [bool]$pointHit.canvas_ancestor_found
    $preflight.point_paint_pane_window_chain_found = [bool]$pointHit.paint_pane_window_chain_found
    $preflight.point_canvas_bounds_contains_point = (
        $clickX -ge $rect.Left -and $clickX -lt $rect.Right -and
        $clickY -ge $rect.Top -and $clickY -lt $rect.Bottom
    )
    $preflight.point_automation_resolution = $(if ($pointHit.canvas_ancestor_found) {
        'canvas_ancestor'
    } elseif ($pointHit.paint_pane_window_chain_found) {
        'paint_pane_window_only'
    } else {
        'unresolved'
    })
    if (-not $preflight.point_canvas_bounds_contains_point -or
        -not ($pointHit.canvas_ancestor_found -or $pointHit.paint_pane_window_chain_found)) {
        $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
        throw 'UI Automation at the click point did not resolve to the named Paint canvas bounds and Paint Pane/Window chain.'
    }
    if ($HoverDrain) {
        if ($clickX + 1 -ge [int]$rect.Right) {
            throw 'The bounded one-pixel move would leave the verified canvas.'
        }
        $preflight.move_preflight_sent = $true
        [int]$moveOutError = 0
        [int]$moveBackError = 0
        $moveOut = [PaintFillMouse]::SendMouseMove(1,0,[ref]$moveOutError)
        $moveBack = [PaintFillMouse]::SendMouseMove(-1,0,[ref]$moveBackError)
        $preflight.move_preflight_accepted = ($moveOut -eq 1 -and $moveBack -eq 1)
        if (-not $preflight.move_preflight_accepted) {
            [void][PaintFillMouse]::SetCursorPos($clickX,$clickY)
            $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
            throw "Bounded mouse-move preflight was not accepted: out=$moveOut/$moveOutError back=$moveBack/$moveBackError."
        }
        $hoverStart = Get-Date
        $hoverDeadline = $hoverStart.AddSeconds(8)
        $hoverSeen = $false
        do {
            $hoverNow = @(Cdb-Markers $CdbLogPath)
            $hoverSeen = @($hoverNow | Where-Object {
                $_ -eq 'fill_deep_ui_in_range_handler'
            }).Count -gt $inRangeBeforeMove
            if ($hoverSeen) { break }
            Start-Sleep -Milliseconds 150
        } while ((Get-Date) -lt $hoverDeadline)
        $preflight.hover_handler_wait_ms = [int]((Get-Date) - $hoverStart).TotalMilliseconds
        $preflight.hover_handler_new_hit_before_click = $hoverSeen
        if (-not $hoverSeen) {
            $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
            throw 'No new in-range handler hit before the bounded hover-drain click.'
        }
        Start-Sleep -Milliseconds 700
        $preflight.hover_settle_ms = 700
        [uint32]$foregroundAfterHover = 0
        $null = [PaintFillMouse]::GetWindowThreadProcessId(
            [PaintFillMouse]::GetForegroundWindow(),[ref]$foregroundAfterHover)
        $pointerAfterHover = [PaintFillMouse+Point]::new()
        [uint32]$targetAfterHover = 0
        $null = [PaintFillMouse]::GetWindowThreadProcessId(
            [PaintFillMouse]::WindowFromPoint($point),[ref]$targetAfterHover)
        $preflight.hover_foreground_matches_paint = $foregroundAfterHover -eq [uint32]$PaintPid
        $preflight.hover_point_window_matches_paint = $targetAfterHover -eq [uint32]$PaintPid
        $preflight.hover_pointer_matches_click = (
            [PaintFillMouse]::GetCursorPos([ref]$pointerAfterHover) -and
            $pointerAfterHover.X -eq $clickX -and $pointerAfterHover.Y -eq $clickY
        )
        if (-not $preflight.hover_foreground_matches_paint -or
            -not $preflight.hover_point_window_matches_paint -or
            -not $preflight.hover_pointer_matches_click) {
            $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
            throw 'Paint foreground or verified canvas point changed after hover drain.'
        }
    }
    # Snapshot after pointer positioning: hover must not count as a click hit.
    $preflight.markers_before_click = @(Cdb-Markers $CdbLogPath)
    $preflight | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $preflightPath -Encoding UTF8
    $clickUtc = (Get-Date).ToUniversalTime().ToString('o')
    $downSent = $false
    $upSent = $false
    $osAccepted = $null
    $touchReport = $null
    if ($CanvasInputMethod -eq 'SendInput') {
        [int]$downError = 0
        $downCount = [PaintFillMouse]::SendMouseEvent(2,[ref]$downError)
        if ($downCount -ne 1) {
            throw "SendInput mouse-down was not accepted: count=$downCount error=$downError"
        }
        $downSent = $true
        Start-Sleep -Milliseconds 150
        [int]$upError = 0
        $upCount = [PaintFillMouse]::SendMouseEvent(4,[ref]$upError)
        if ($upCount -ne 1) {
            [PaintFillMouse]::mouse_event(4,0,0,0,[UIntPtr]::Zero)
            throw "SendInput mouse-up was not accepted: count=$upCount error=$upError"
        }
        $upSent = $true
        $osAccepted = $true
    } elseif ($CanvasInputMethod -eq 'mouse_event') {
        # mouse_event returns void. Only a Paint callback or pixel change can
        # establish application delivery; record the calls, not acceptance.
        [PaintFillMouse]::mouse_event(2,0,0,0,[UIntPtr]::Zero)
        $downSent = $true
        Start-Sleep -Milliseconds 150
        [PaintFillMouse]::mouse_event(4,0,0,0,[UIntPtr]::Zero)
        $upSent = $true
    } else {
        # One documented touch contact at the same verified interior point.
        # Record each native return/error even if a later frame fails.
        $touchReport = [ordered]@{
            schema = 'paint-fill-touch-input-v1'
            api = 'InitializeTouchInjection + InjectTouchInput'
            pointer_info_size = [PaintFillTouch]::PointerInfoSize()
            touch_info_size = [PaintFillTouch]::TouchInfoSize()
            layout_valid = [PaintFillTouch]::LayoutValid()
            pointer_type = 'PT_TOUCH'
            pointer_id = 0
            feedback_mode = 'TOUCH_FEEDBACK_NONE'
            contact_radius = $touchContactRadius
            contact_area_within_canvas = ($clickX-$touchContactRadius -ge $rect.Left -and
                $clickY-$touchContactRadius -ge $rect.Top -and
                $clickX+$touchContactRadius -lt $rect.Right -and
                $clickY+$touchContactRadius -lt $rect.Bottom)
            screen_point = @($clickX,$clickY)
            initialize_attempted = $false
            initialize_accepted = $false
            initialize_error = $null
            down_attempted = $false
            down_accepted = $false
            down_error = $null
            update_attempted = $false
            update_accepted = $false
            update_error = $null
            up_attempted = $false
            up_accepted = $false
            up_error = $null
            status = 'preflight'
            failure_type = $null
        }
        try {
            if (-not $touchReport.layout_valid -or -not $touchReport.contact_area_within_canvas) {
                throw 'Touch ABI layout or contact-area boundary differs from the pinned x64 control.'
            }
            if (@($preflight.markers_before_click | Where-Object {
                    $_ -in @('fill_pixel_scan','fill_deep_execute_scan_result',
                             'fill_deep_execute_draw_complete','fill_deep_execute_exit')
                }).Count -gt 0) {
                throw 'A one-shot scan or Execute exit checkpoint was consumed before touch injection.'
            }
            [int]$nativeError = 0
            $touchReport.initialize_attempted = $true
            $touchReport.initialize_accepted = [PaintFillTouch]::Initialize([ref]$nativeError)
            $touchReport.initialize_error = $nativeError
            if (-not $touchReport.initialize_accepted) {
                throw "InitializeTouchInjection failed with Win32 error $nativeError."
            }
            $contact = [PaintFillTouch]::Frame($clickX,$clickY,[PaintFillTouch]::DownFlags,
                                              $touchContactRadius)
            $touchReport.down_attempted = $true
            $touchReport.down_accepted = [PaintFillTouch]::Send([ref]$contact,[ref]$nativeError)
            $touchReport.down_error = $nativeError
            if (-not $touchReport.down_accepted) {
                throw "InjectTouchInput DOWN failed with Win32 error $nativeError."
            }
            Start-Sleep -Milliseconds 75
            $contact = [PaintFillTouch]::Frame($clickX,$clickY,[PaintFillTouch]::UpdateFlags,
                                              $touchContactRadius)
            $touchReport.update_attempted = $true
            $touchReport.update_accepted = [PaintFillTouch]::Send([ref]$contact,[ref]$nativeError)
            $touchReport.update_error = $nativeError
            Start-Sleep -Milliseconds 75
            $contact = [PaintFillTouch]::Frame($clickX,$clickY,[PaintFillTouch]::UpFlags,
                                              $touchContactRadius)
            $touchReport.up_attempted = $true
            $touchReport.up_accepted = [PaintFillTouch]::Send([ref]$contact,[ref]$nativeError)
            $touchReport.up_error = $nativeError
            if (-not $touchReport.update_accepted -or -not $touchReport.up_accepted) {
                throw 'One or more touch UPDATE/UP frames failed; see fill-touch-input.json.'
            }
            $touchReport.status = 'accepted_by_api'
        } catch {
            $touchReport.status = 'failed'
            $touchReport.failure_type = $_.Exception.GetType().FullName
            throw
        } finally {
            $touchReport | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath `
                (Join-Path $OutDir 'fill-touch-input.json') -Encoding UTF8
        }
    }
    $touchOperationWait = $null
    $touchRender = $null
    if ($CanvasInputMethod -eq 'touch') {
        # Wait for the common Execute exit after scan and optional GDI+ draw.
        # The old fixed screenshot delay preceded even the seed read.
        $operationTimeoutMs = if ($ExpectedWidth -eq 257) { 60000 }
                              elseif ($HeapLookup) { 40000 } else { 20000 }
        $operationWaitStart = Get-Date
        $operationDeadline = $operationWaitStart.AddMilliseconds($operationTimeoutMs)
        $exitObserved = $false
        $operationPolls = 0
        $operationMarkers = @()
        do {
            $operationPolls++
            $operationMarkers = @(Cdb-Markers $CdbLogPath)
            $exitObserved = $operationMarkers -contains 'fill_deep_execute_exit'
            if ($exitObserved) { break }
            Start-Sleep -Milliseconds 200
        } while ((Get-Date) -lt $operationDeadline)
        $touchOperationWait = [ordered]@{
            schema = 'paint-fill-touch-operation-wait-v1'
            marker = 'fill_deep_execute_exit'
            marker_means = 'common_Execute_exit_after_scan_and_optional_draw'
            heap_lookup = [bool]$HeapLookup
            timeout_ms = $operationTimeoutMs
            wait_ms = [int]((Get-Date) - $operationWaitStart).TotalMilliseconds
            polls = $operationPolls
            scan_entry_seen = $operationMarkers -contains 'fill_pixel_scan'
            scan_result_seen = $operationMarkers -contains 'fill_deep_execute_scan_result'
            draw_complete_seen = $operationMarkers -contains 'fill_deep_execute_draw_complete'
            exit_seen = $exitObserved
            status = $(if ($exitObserved) { 'exit_seen' } else { 'deadline_expired' })
        }
        $touchOperationWait | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath `
            (Join-Path $OutDir 'fill-touch-operation-wait.json') -Encoding UTF8
    } else {
        Start-Sleep -Seconds 2
    }
    if (-not [PaintFillMouse]::SetCursorPos([int]($button.rect.Left+2),[int]($button.rect.Top+2))) {
        throw 'Could not clear cursor from canvas before screenshot.'
    }
    Start-Sleep -Milliseconds 400
    if ($CanvasInputMethod -eq 'touch' -and $touchOperationWait.exit_seen) {
        # Two identical changed samples are useful render evidence. Identical
        # source pixels are still inconclusive even after the Execute exit.
        $renderStart = Get-Date
        $renderTimeoutMs = if ($ExpectedWidth -eq 257) { 15000 } else { 8000 }
        $renderDeadline = $renderStart.AddMilliseconds($renderTimeoutMs)
        $renderProbes = @()
        $lastHash = $null
        $stableChanged = $false
        do {
            $probePath = Join-Path $OutDir 'fill-render-probe.png'
            Save-FillScreenshot $probePath
            $probeHash = Hash-Rgb (Get-RgbBytes $probePath $left $top $scale)
            $renderProbes += [ordered]@{
                elapsed_ms = [int]((Get-Date) - $renderStart).TotalMilliseconds
                rgb_sha256 = $probeHash
                changed_from_source = $probeHash -ne (Hash-Rgb $fixtureBytes)
            }
            if ($probeHash -eq $lastHash -and $probeHash -ne (Hash-Rgb $fixtureBytes)) {
                $stableChanged = $true
                break
            }
            $lastHash = $probeHash
            Start-Sleep -Milliseconds 500
        } while ((Get-Date) -lt $renderDeadline)
        $touchRender = [ordered]@{
            schema = 'paint-fill-touch-render-observation-v1'
            max_wait_ms = $renderTimeoutMs
            wait_ms = [int]((Get-Date) - $renderStart).TotalMilliseconds
            probes = $renderProbes
            stable_changed_raster = $stableChanged
            draw_complete_seen = [bool]$touchOperationWait.draw_complete_seen
            output_evidence = ($stableChanged -and $touchOperationWait.draw_complete_seen)
            status = $(if ($stableChanged -and $touchOperationWait.draw_complete_seen) {
                'changed_raster_stable_after_draw_checkpoint'
            } else { 'output_unresolved' })
        }
        $touchRender | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath `
            (Join-Path $OutDir 'fill-touch-render-observation.json') -Encoding UTF8
    }
    $postFile = Join-Path $OutDir 'fill-after-click.png'
    Save-FillScreenshot $postFile
    $postBytes = Get-RgbBytes $postFile $left $top $scale
    $black = 0
    for ($i = 0; $i -lt $postBytes.Length; $i += 3) {
        if ($postBytes[$i] -eq 0 -and $postBytes[$i+1] -eq 0 -and $postBytes[$i+2] -eq 0) { $black++ }
    }
    [ordered]@{
        schema = 'paint-fill-action-v1'
        preflight = 'fill-click-preflight.json'
        screenshot_before = 'fill-before-click.png'
        screenshot_after = 'fill-after-click.png'
        esc_probe = $escProbe
        deselect_probe = $deselectProbe
        white_handle_sentinels_before_click = $handlesBeforeClick
        target_tolerance = $Tolerance
        tolerance_readback = $actualTolerance
        color1 = 'Black'
        zoom_percent = $ZoomPercent
        image_size = @($ExpectedWidth,$ExpectedHeight)
        canvas_rect = @($left,$top,($left+$ExpectedWidth*$scale),($top+$ExpectedHeight*$scale))
        click_image_pixel = @($ClickImageX,$seedY)
        click_screen_point = @($clickX,$clickY)
        click_started_utc = $clickUtc
        hover_drain_attempted = [bool]$HoverDrain
        hover_handler_new_hit_before_click = [bool]$preflight.hover_handler_new_hit_before_click
        hover_handler_wait_ms = $preflight.hover_handler_wait_ms
        hover_settle_ms = $preflight.hover_settle_ms
        move_preflight_sent = [bool]$preflight.move_preflight_sent
        move_preflight_accepted = [bool]$preflight.move_preflight_accepted
        input_delivery = [ordered]@{
            api = $CanvasInputMethod
            mouse_down_sent = $downSent
            mouse_up_sent = $upSent
            mouse_down_accepted = $osAccepted
            mouse_up_accepted = $osAccepted
            touch_report = $(if ($touchReport) { 'fill-touch-input.json' } else { $null })
            touch_initialize_accepted = $(if ($touchReport) { $touchReport.initialize_accepted } else { $null })
            touch_down_sent = $(if ($touchReport) { $touchReport.down_attempted } else { $null })
            touch_down_accepted = $(if ($touchReport) { $touchReport.down_accepted } else { $null })
            touch_down_error = $(if ($touchReport) { $touchReport.down_error } else { $null })
            touch_update_sent = $(if ($touchReport) { $touchReport.update_attempted } else { $null })
            touch_update_accepted = $(if ($touchReport) { $touchReport.update_accepted } else { $null })
            touch_update_error = $(if ($touchReport) { $touchReport.update_error } else { $null })
            touch_up_sent = $(if ($touchReport) { $touchReport.up_attempted } else { $null })
            touch_up_accepted = $(if ($touchReport) { $touchReport.up_accepted } else { $null })
            touch_up_error = $(if ($touchReport) { $touchReport.up_error } else { $null })
            winui_handler_measured = $false
        }
        touch_operation_wait = $(if ($touchOperationWait) { $touchOperationWait } else { $null })
        touch_render_observation = $(if ($touchRender) { $touchRender } else { $null })
        foreground_matches_paint = $true
        point_window_matches_paint = $true
        point_canvas_ancestor_found = [bool]$pointHit.canvas_ancestor_found
        point_paint_pane_window_chain_found = [bool]$pointHit.paint_pane_window_chain_found
        point_canvas_bounds_contains_point = [bool]$preflight.point_canvas_bounds_contains_point
        point_automation_resolution = [string]$preflight.point_automation_resolution
        fixture_rgb_sha256 = Hash-Rgb $fixtureBytes
        pre_rgb_sha256 = Hash-Rgb $preBytes
        post_rgb_sha256 = Hash-Rgb $postBytes
        post_black_pixels = $black
        markers_before_click = @($preflight.markers_before_click)
    }
}