Exploit database

GH-0fc65d94ad3dc861b46398e006825611

liyuxuan504-byte/cve-2026-14266

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-14266

2 sources

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

Repository files3
liyuxuan504-byte/cve-2026-14266Revision c7e7b5e4f55e

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

tools/05-mini-debugger.ps1

PowerShell · 25,320 bytes
# CVE-2026-14266 Mini-Debugger (v2)
# Captures crash context for heap layout analysis.
# Usage: .\05-mini-debugger.ps1 [path-to-xz-file]
#
# v2 fixes: DEBUG_EVENT is read as a fixed-size byte blob to bypass CLR's
# LayoutKind.Explicit object-field alignment check (which rejected the
# DEBUG_EVENT_U union in v1). Fields are carved out of the blob by offset.

param(
    [string]$XzFile = "C:\Users\10293\Desktop\简历\cve2026-14266-analysis\rce-crash.xz",
    [string]$SevenZip = "C:\Program Files\7-Zip\7z.exe",
    [int]$DumpAfter   = 0x10000,  # bytes past outBuf+cap to dump
    [switch]$CatchAll,           # break on ANY exception (not just AV/heap)
    [int]$MaxCrashes = 3         # stop after N captured crashes
)

# UAC self-elevation: we need SeDebugPrivilege is NOT required (we CREATE the
# process), but Win32 debug API needs a process with at least standard perms.
Add-Type -TypeDefinition @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

public static class MiniDb {
    // ---- Win32 debug API ----
    [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    public static extern bool CreateProcessW(
        string lpAppName, string lpCmdLine, IntPtr lpProcessAttr, IntPtr lpThreadAttr,
        bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment,
        string lpCurrentDirectory, ref STARTUPINFOW lpStartupInfo, out PROCESS_INFORMATION lpProcessInfo);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool WaitForDebugEventEx(IntPtr lpDebugEvent, uint dwMilliseconds);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool ContinueDebugEvent(
        uint dwProcessId, uint dwThreadId, uint dwContinueStatus);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool GetThreadContext(IntPtr hThread, IntPtr lpContext);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool SetThreadContext(IntPtr hThread, IntPtr lpContext);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern uint SuspendThread(IntPtr hThread);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern uint ResumeThread(IntPtr hThread);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, int dwLength);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool ReadProcessMemory(
        IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesRead);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool WriteProcessMemory(
        IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool VirtualProtectEx(
        IntPtr hProcess, IntPtr lpAddress, int dwSize, uint flNewProtect, out uint lpflOldProtect);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern bool CloseHandle(IntPtr hObject);

    [DllImport("kernel32.dll", SetLastError=true)]
    public static extern uint GetLastError();

    // ---- Structs that CLR can verify (no explicit-union object-field alignment issue) ----
    [StructLayout(LayoutKind.Sequential)]
    public struct PROCESS_INFORMATION {
        public IntPtr hProcess;
        public IntPtr hThread;
        public uint dwProcessId;
        public uint dwThreadId;
    }

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    public struct STARTUPINFOW {
        public int cb;
        public IntPtr lpReserved;
        public IntPtr lpDesktop;
        public IntPtr lpTitle;
        public int dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute;
        public uint dwFlags;
        public ushort wShowWindow;
        public ushort cbReserved2;
        public IntPtr lpReserved2;
        public IntPtr hStdInput, hStdOutput, hStdError;
        public static STARTUPINFOW Create() {
            var s = new STARTUPINFOW();
            s.cb = Marshal.SizeOf(typeof(STARTUPINFOW));
            return s;
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MEMORY_BASIC_INFORMATION {
        public IntPtr BaseAddress;
        public IntPtr AllocationBase;
        public uint   AllocationProtect;
        public IntPtr RegionSize;       // SIZE_T (8 on x64)
        public uint   State;
        public uint   Protect;
        public uint   Type;
    }

    // DEBUG_EVENT is read as a raw byte blob (1024 bytes is generous; real size
    // is 168 bytes on x64 but we over-allocate to be safe across patch levels).
    // We carve fields out by offset using BitConverter below.
    public const int DEBUG_EVENT_BLOB = 1024;

    // Constants
    public const uint DEBUG_PROCESS = 0x00000001;
    public const uint CREATE_SUSPENDED = 0x00000004;
    public const uint CREATE_NEW_CONSOLE = 0x00000010;
    public const uint DBG_CONTINUE = 0x00010002;
    public const uint DBG_EXCEPTION_NOT_HANDLED = 0x80010001;
    public const uint EXCEPTION_ACCESS_VIOLATION = 0xC0000005;
    public const uint EXCEPTION_HEAP_CORRUPTION = 0xC0000374;
    public const uint EXCEPTION_SINGLE_STEP = 0x80000004;  // hardware BP / trap flag
    public const uint THREAD_ALL_ACCESS = 0x001F03FF;
    public const uint PROCESS_ALL_ACCESS = 0x001F0FFF;
    public const uint PAGE_GUARD = 0x100;
    public const uint PAGE_NOACCESS = 0x01;
    public const uint PAGE_READONLY = 0x02;
    public const uint PAGE_READWRITE = 0x04;

    // debug event codes
    public const int UNKNOWN = 0;
    public const int EXCEPTION_DEBUG_EVENT = 1;
    public const int CREATE_THREAD_DEBUG_EVENT = 2;
    public const int CREATE_PROCESS_DEBUG_EVENT = 3;
    public const int EXIT_THREAD_DEBUG_EVENT = 4;
    public const int EXIT_PROCESS_DEBUG_EVENT = 5;
    public const int LOAD_DLL_DEBUG_EVENT = 6;
    public const int UNLOAD_DLL_DEBUG_EVENT = 7;
    public const int OUTPUT_DEBUG_STRING_EVENT = 8;
    public const int RIP_EVENT = 9;

    // CONTEXT64 (AMD64). GetThreadContext requires the buffer be 16-byte
    // aligned AND ContextFlags must include CONTEXT_AMD64 (0x00100000).
    // CONTEXT_AMD64 | CONTEXT_FULL(0x1000B) = 0x0010000B
    public const uint CONTEXT64_AMD64 = 0x0010000B;  // CONTEXT_AMD64 | CONTEXT_FULL
}
"@

# ============================================================================
#  Helpers to carve DEBUG_EVENT out of the byte blob.
#  Layout of DEBUG_EVENT on x64:
#    +0x00 uint  dwDebugEventCode
#    +0x04 uint  dwProcessId
#    +0x08 uint  dwThreadId
#    +0x10      union (DEBUG_EVENT_U) -- note: 8-byte aligned (4 bytes pad after dwThreadId)
#  EXCEPTION_DEBUG_INFO:
#    +0x00 EXCEPTION_RECORD ExceptionRecord
#      +0x00 uint   ExceptionCode
#      +0x04 uint   ExceptionFlags
#      +0x08 IntPtr ExceptionRecord  (PVOID, 8 bytes)
#      +0x10 IntPtr ExceptionAddress (8 bytes)
#      +0x18 uint   NumberParameters
#      +0x1C pad(4)              <-- EXCEPTION_INFORMATION follows, ULONG_PTR-aligned
#      +0x20 ULONG_PTR ExceptionInformation[15]  (120 bytes)
#      => EXCEPTION_RECORD size = 0x98 = 152 bytes
#    +0x98 (after 152 bytes) uint dwFirstChance
#  So within the union at offset +0x10 of DEBUG_EVENT:
#    ExceptionCode     @ +0x10
#    ExceptionFlags    @ +0x14
#    ExceptionRecord   @ +0x18
#    ExceptionAddress  @ +0x20
#    NumberParameters  @ +0x28
#    ExceptionInformation[0] (AV kind)   @ +0x30
#    ExceptionInformation[1] (AV fault VA) @ +0x38
#    dwFirstChance    @ +0x10 + 0x98 = +0xA8
# ============================================================================
function Get-DbgEvent {
    param([byte[]]$b)
    $code = [BitConverter]::ToUInt32($b, 0)
    $pidv = [BitConverter]::ToUInt32($b, 4)
    $tid  = [BitConverter]::ToUInt32($b, 8)
    return @{ Code=$code; Pid=$pidv; Tid=$tid }
}
function Get-ExceptionInfo {
    param([byte[]]$b)
    # DEBUG_EVENT header: code@0, pid@4, tid@8. Union @ +0x10.
    # EXCEPTION_DEBUG_INFO = { EXCEPTION_RECORD ExceptionRecord; DWORD dwFirstChance; }
    # EXCEPTION_RECORD (x64):
    #   +0x00 DWORD ExceptionCode
    #   +0x04 DWORD ExceptionFlags
    #   +0x08 PVOID ExceptionRecord   (8)
    #   +0x10 PVOID ExceptionAddress  (8)
    #   +0x18 DWORD NumberParameters
    #   +0x1C (4 pad)
    #   +0x20 ULONG_PTR ExceptionInformation[15]  (120 bytes)
    #   total EXCEPTION_RECORD = 0x20 + 120 = 0x98 = 152 bytes
    # dwFirstChance = union_base + 0x98 = DEBUG_EVENT+0x10+0x98 = +0xA8
    # For ACCESS_VIOLATION, ExceptionInformation[0] = read(0)/write(1)/exec(8) @ union+0x20 = +0x30
    # ExceptionInformation[1] = fault VA @ union+0x28 = +0x38
    $excCode     = [BitConverter]::ToUInt32($b, 0x10)
    $excFlags    = [BitConverter]::ToUInt32($b, 0x14)
    $excAddr     = [BitConverter]::ToUInt64($b, 0x20)
    $numParams   = [BitConverter]::ToUInt32($b, 0x28)
    $avKind      = [BitConverter]::ToUInt64($b, 0x30)   # [0]
    $avFaultVA   = [BitConverter]::ToUInt64($b, 0x38)   # [1]
    $firstChance = [BitConverter]::ToUInt32($b, 0xA8)
    return @{ Code=$excCode; Flags=$excFlags; Address=$excAddr;
              NumParams=$numParams; AVKind=$avKind; AVFaultVA=$avFaultVA;
              FirstChance=$firstChance }
}

# ---- read CONTEXT64 fields out of its native buffer ----
# CONTEXT64 layout (AMD64), the fields we care about and their offsets:
$CONTEXT_OFFSETS = @{
    Rax=0x78; Rcx=0x80; Rdx=0x88; Rbx=0x90; Rsp=0x98; Rbp=0xA0; Rsi=0xA8; Rdi=0xB0
    R8=0xB8; R9=0xC0; R10=0xC8; R11=0xD0; R12=0xD8; R13=0xE0; R14=0xE8; R15=0xF0
    Rip=0xF8
}
function Get-Reg {
    param([byte[]]$b,[string]$r)
    [BitConverter]::ToUInt64($b, $CONTEXT_OFFSETS[$r])
}
function ToIP {
    param([uint64]$v)
    return [IntPtr]::new([Int64]$v)
}

# ====== Main ======
Write-Host "=== CVE-2026-14266 Mini-Debugger v2 ===" -ForegroundColor Cyan
Write-Host "Target: $SevenZip"
Write-Host "PoC:    $XzFile"
if (-not (Test-Path $XzFile))  { Write-Host "PoC not found: $XzFile" -ForegroundColor Red; exit 1 }
if (-not (Test-Path $SevenZip)){ Write-Host "7z.exe not found: $SevenZip" -ForegroundColor Red; exit 1 }
Write-Host ""

$cmdLine = "`"$SevenZip`" x `"$XzFile`" -so -mmt=2"
Write-Host "Command: $cmdLine`n"

$si = [MiniDb+STARTUPINFOW]::Create()
$pi = New-Object MiniDb+PROCESS_INFORMATION

$workDir = "C:\temp\cve2026"
$result = [MiniDb]::CreateProcessW(
    $SevenZip, $cmdLine,
    [IntPtr]::Zero, [IntPtr]::Zero,
    $false,
    [MiniDb]::DEBUG_PROCESS,
    [IntPtr]::Zero,
    $workDir,
    [ref]$si,
    [ref]$pi
)
if (-not $result) {
    $err = [MiniDb]::GetLastError()
    Write-Host "CreateProcess FAILED: GLE=$err" -ForegroundColor Red
    exit 1
}

Write-Host "Process created: PID=$($pi.dwProcessId) TID=$($pi.dwThreadId)" -ForegroundColor Green
Write-Host "Debugging... (waiting for crash)`n" -ForegroundColor DarkGray

$hProcess = $pi.hProcess
$crashCount = 0
$done = $false

# Allocate CONTEXT64 buffer (must be 16-byte aligned). AllocHGlobal gives
# pointer-aligned; pad up to 1232 bytes (CONTEXT64 real size ~1232).
$ctxSize = 1232
$ctxPtr  = [Runtime.InteropServices.Marshal]::AllocHGlobal($ctxSize + 16)
# align to 16
$aligned = [IntPtr]::Add($ctxPtr, (16 - ([int64]$ctxPtr.ToInt64() % 16)) % 16)

try {
    while (-not $done) {
        $blob = New-Object byte[] ([MiniDb]::DEBUG_EVENT_BLOB)
        $pBlob = [Runtime.InteropServices.Marshal]::AllocHGlobal([MiniDb]::DEBUG_EVENT_BLOB)
        try {
            [Runtime.InteropServices.Marshal]::Copy($blob, 0, $pBlob, $blob.Length)
            $ok = [MiniDb]::WaitForDebugEventEx($pBlob, [UInt32]::MaxValue)
            if (-not $ok) {
                Write-Host "WaitForDebugEventEx FAILED: GLE=$([MiniDb]::GetLastError())"
                break
            }
            [Runtime.InteropServices.Marshal]::Copy($pBlob, $blob, 0, $blob.Length)
        } finally {
            [Runtime.InteropServices.Marshal]::FreeHGlobal($pBlob)
        }

        $ev = Get-DbgEvent $blob
        $pid2 = $ev.Pid; $tid2 = $ev.Tid; $code = $ev.Code

        switch ($code) {
            ([MiniDb]::EXCEPTION_DEBUG_EVENT) {
                $exi = Get-ExceptionInfo $blob
                $ec = $exi.Code; $ea = $exi.Address; $fc = $exi.FirstChance

                # Only break on AV or Heap Corruption (or anything if -CatchAll).
                # Always skip the initial debugger breakpoint (0x80000003 @ ntdll LdrpDoDebuggerBreak)
                # and C++ exceptions which fire constantly during normal 7z teardown.
                $isInitialBp = ($ec -eq 0x80000003)
                $isInteresting = (-not $isInitialBp) -and (
                    $CatchAll -or
                    $ec -eq [MiniDb]::EXCEPTION_ACCESS_VIOLATION -or
                    $ec -eq [MiniDb]::EXCEPTION_HEAP_CORRUPTION -or
                    $ec -eq 0xC0000409   # STACK_BUFFER_OVERRUN
                )
                if ($isInitialBp) {
                    [MiniDb]::ContinueDebugEvent($pid2, $tid2, [MiniDb]::DBG_CONTINUE) | Out-Null
                    continue
                }
                if ($isInteresting) {

                    $crashCount++
                    Write-Host "`n=== CRASH #$crashCount ===" -ForegroundColor Red
                    $ecName = switch ($ec) {
                        0xC0000005  { "ACCESS_VIOLATION" }
                        0xC0000374  { "HEAP_CORRUPTION" }
                        0x80000003  { "BREAKPOINT" }
                        0xC0000409  { "STACK_BUFFER_OVERRUN" }
                        0xE06D7363  { "CPP_EXCEPTION" }
                        0xC00000FD  { "STACK_OVERFLOW" }
                        default     { "0x$($ec.ToString('X8'))" }
                    }
                    Write-Host ("Exception:    0x{0:X8} ({1})" -f $ec, $ecName)
                    Write-Host ("Address(IP):  0x{0:X16}" -f $ea)
                    Write-Host ("Thread:       {0}" -f $tid2)
                    Write-Host ("FirstChance:  {0}" -f $fc)
                    if ($ec -eq 0xC0000005) {
                        $kind = switch ($exi.AVKind) { 0 {"READ"}; 1 {"WRITE"}; 8 {"EXEC"}; default {"$($exi.AVKind)"} }
                        Write-Host ("AV kind:      {0}" -f $kind)
                        Write-Host ("AV fault VA:  0x{0:X16}" -f $exi.AVFaultVA)
                    }

                    # The faulting thread is TID from the event header. Open it.
                    $hThread = [MiniDb]::OpenThread([MiniDb]::THREAD_ALL_ACCESS, $false, $tid2)
                    if ($hThread -eq [IntPtr]::Zero) {
                        Write-Host "OpenThread(TID=$tid2) FAILED: GLE=$([MiniDb]::GetLastError())" -ForegroundColor Yellow
                    } else {
                        # SuspendThread first so context is stable & we can query it.
                        # Then zero ctxBuf, set ContextFlags, copy in, call GetThreadContext.
                        $ctxBytes = New-Object byte[] $ctxSize
                        $flags = [MiniDb]::CONTEXT64_AMD64
                        [BitConverter]::GetBytes([UInt32]$flags).CopyTo($ctxBytes, 0x30)  # ContextFlags @ +0x30
                        [Runtime.InteropServices.Marshal]::Copy($ctxBytes, 0, $aligned, $ctxSize)

                        if ([MiniDb]::GetThreadContext($hThread, $aligned)) {
                            [Runtime.InteropServices.Marshal]::Copy($aligned, $ctxBytes, 0, $ctxSize)
                            Write-Host "`n=== Register Context ===" -ForegroundColor Yellow
                            $regs = @('Rax','Rbx','Rcx','Rdx','Rsi','Rdi','Rbp','Rsp','Rip',
                                      'R8','R9','R10','R11','R12','R13','R14','R15')
                            foreach ($r in ($regs | Sort-Object)) {
                                "  {0,-4} = 0x{1:X16}" -f $r, (Get-Reg $ctxBytes $r)
                            }

                            $rbx = Get-Reg $ctxBytes 'Rbx'
                            $rcx = Get-Reg $ctxBytes 'Rcx'
                            if ($rbx -ne 0) {
                                Write-Host "`n=== Decoder Struct @ RBX (0x$($rbx.ToString('X16'))) ===" -ForegroundColor Yellow
                                Write-Host "  Offset | Value"
                                Write-Host "  -------|------"
                                $structBuf = New-Object byte[] 0x60
                                $rd = 0
                                if ([MiniDb]::ReadProcessMemory($hProcess, (ToIP $rbx), $structBuf, 0x60, [ref]$rd) -and $rd -ge 0x60) {
                                    for ($off = 0; $off -lt 0x60; $off += 8) {
                                        $v = [BitConverter]::ToUInt64($structBuf, $off)
                                        "  +0x{0:X2}  = 0x{1:X16}" -f $off, $v
                                    }
                                } else {
                                    Write-Host "  (read failed GLE=$([MiniDb]::GetLastError()))" -ForegroundColor Yellow
                                }

                                # outBuf base @ RBX+0x28, capacity @ RBX+0x30, cursor @ RBX+0x38
                                $outBuf = [BitConverter]::ToUInt64($structBuf, 0x28)
                                $cap    = [BitConverter]::ToUInt64($structBuf, 0x30)
                                $cursor = [BitConverter]::ToUInt64($structBuf, 0x38)

                                # The crash VA is the FIRST byte the decoder tried to write past
                                # the buffer. For an AV that's AVFaultVA; for heap corruption
                                # it's typically in rcx (memcpy dest).
                                $crashVA = if ($ec -eq 0xC0000005 -and $exi.AVFaultVA -ne 0) { $exi.AVFaultVA } else { $rcx }

                                # Sanity: outBuf must look like a user-mode heap VA (high bits 0x000001.. / 0x000002..),
                                # and cap must be a sane small-ish number. Otherwise RBX does NOT point at the
                                # decoder struct (e.g. we caught an unrelated exception) — skip the dump.
                                $outBufValid = (($outBuf -ge 0x10000) -and ($outBuf -lt 0x7FF000000000))
                                $capValid    = (($cap -ge 1) -and ($cap -le 0x10000000))
                                if ($outBufValid -and $capValid) {
                                    Write-Host "`n=== outBuf = 0x$($outBuf.ToString('X16'))  cap=0x$($cap.ToString('X'))  cursor=0x$($cursor.ToString('X')) ===" -ForegroundColor Yellow
                                    $cOff = if ($outBuf -le $crashVA) { ($crashVA - $outBuf) } else { 0 }
                                    Write-Host ("Crash write VA = 0x{0:X16}  =>  outBuf + 0x{1:X}" -f $crashVA, $cOff)
                                    $past = [int64]($cOff - $cap)
                                    if ($past -ge 0) {
                                        Write-Host ("Overflow past capacity: +0x{0:X} bytes" -f $past) -ForegroundColor Magenta
                                    } else {
                                        Write-Host ("(crash VA within buffer, not an overflow: offset 0x{0:X})" -f $cOff) -ForegroundColor DarkYellow
                                    }

                                    Write-Host "`nHeap memory PAST outBuf (what overflow corrupts):" -ForegroundColor Yellow
                                    Write-Host "  relOutBuf | Hex dump"
                                    Write-Host "  ---------|--------"
                                    # start dumping a little before outBuf+cap so we see the legit tail + overflow zone
                                    $dumpBase = $outBuf + $cap - 0x40
                                    for ($off = 0; $off -lt $DumpAfter; $off += 16) {
                                        $addr = ToIP ($dumpBase + [uint64]$off)
                                        $b = New-Object byte[] 16
                                        $r2 = 0
                                        if ([MiniDb]::ReadProcessMemory($hProcess, $addr, $b, 16, [ref]$r2) -and $r2 -gt 0) {
                                            $n = [Math]::Min([int]$r2, 16)
                                            $hex = (($b[0..($n-1)]) | ForEach-Object { "{0:X2}" -f $_ }) -join ' '
                                            $relToOutBuf = [int64](($dumpBase + $off) - $outBuf)
                                            $tag = if ($relToOutBuf -lt 0) { "<pre-buf>   " }
                                                   elseif ($relToOutBuf -lt [int64]$cap) { "<buf-tail>  " }
                                                   else { "<OVERFLOW>  " }
                                            $relHex = "{0:+0;-0}" -f $relToOutBuf
                                            "  {0,10} {1} {2}" -f $relHex, $tag, $hex
                                        } else {
                                            # page boundary: jump to next 0x1000 to find next mapped region
                                            $pageEnd = ($dumpBase + $off + 0x1000) -band (-bnot 0xFFF)
                                            $nextOff = $pageEnd - $dumpBase
                                            if ($nextOff -le $off) { $nextOff = $off + 0x10 }
                                            "  outBuf+{0,6:X}  <unmapped>  (skip to {1:X})" -f $off, ($nextOff)
                                            $off = [int]($nextOff - 0x10)   # loop will +=0x10
                                        }
                                    }
                                } else {
                                    Write-Host "  (RBX not pointing at decoder struct — outBuf/cap look bogus; skipping dump)" -ForegroundColor DarkYellow
                                }
                            }
                        } else {
                            Write-Host "GetThreadContext FAILED: GLE=$([MiniDb]::GetLastError())" -ForegroundColor Yellow
                        }
                        [MiniDb]::CloseHandle($hThread) | Out-Null
                    }

                    if ($fc -eq 1 -and $crashCount -lt $MaxCrashes) {
                        [MiniDb]::ContinueDebugEvent($pid2, $tid2, [MiniDb]::DBG_EXCEPTION_NOT_HANDLED) | Out-Null
                    } else {
                        [MiniDb]::ContinueDebugEvent($pid2, $tid2, [MiniDb]::DBG_CONTINUE) | Out-Null
                        $done = $true
                    }
                    continue
                }
                [MiniDb]::ContinueDebugEvent($pid2, $tid2, [MiniDb]::DBG_EXCEPTION_NOT_HANDLED) | Out-Null
                continue
            }

            ([MiniDb]::CREATE_PROCESS_DEBUG_EVENT) {
                # union @ +0x10. CREATE_PROCESS_DEBUG_INFO x64 layout:
                #   +0x00 HANDLE hFile
                #   +0x08 HANDLE hProcess
                #   +0x10 HANDLE hThread
                #   +0x18 LPVOID lpBaseOfImage
                #   +0x20 DWORD  dwDebugInfoFileOffset
                #   +0x24 DWORD  nDebugInfoSize
                #   +0x28 LPVOID lpThreadLocalBase
                #   +0x30 LPVOID lpStartAddress
                #   +0x38 LPVOID lpImageName
                #   +0x40 WORD   fUnicode
                $hFile     = [BitConverter]::ToUInt64($blob, 0x10)
                $imageBase = [BitConverter]::ToUInt64($blob, 0x28)
                Write-Host "[+] process started, image base: 0x$($imageBase.ToString('X16'))"
                if ($hFile -ne 0) { [MiniDb]::CloseHandle([IntPtr]::new([Int64]$hFile)) | Out-Null }
            }

            ([MiniDb]::LOAD_DLL_DEBUG_EVENT) {
                # LOAD_DLL_DEBUG_INFO x64:
                #   +0x00 HANDLE hFile
                #   +0x08 LPVOID lpBaseOfDll
                $hFile   = [BitConverter]::ToUInt64($blob, 0x10)
                $dllBase = [BitConverter]::ToUInt64($blob, 0x18)
                Write-Host "[.] DLL loaded @ 0x$($dllBase.ToString('X16'))"
                if ($hFile -ne 0) { [MiniDb]::CloseHandle([IntPtr]::new([Int64]$hFile)) | Out-Null }
            }

            ([MiniDb]::EXIT_PROCESS_DEBUG_EVENT) {
                # EXIT_PROCESS_DEBUG_INFO: DWORD dwExitCode @ union+0x00
                $exitCode = [BitConverter]::ToUInt32($blob, 0x10)
                Write-Host "`n[*] Process exited: 0x$($exitCode.ToString('X8'))"
                $done = $true
            }
        }

        [MiniDb]::ContinueDebugEvent($pid2, $tid2, [MiniDb]::DBG_CONTINUE) | Out-Null
    }
} finally {
    [Runtime.InteropServices.Marshal]::FreeHGlobal($ctxPtr)
    [MiniDb]::CloseHandle($pi.hProcess) | Out-Null
    [MiniDb]::CloseHandle($pi.hThread)  | Out-Null
}

Write-Host "`n=== Done ===" -ForegroundColor Green
Write-Host "Captured $crashCount crash(es). Use the <OVERFLOW> dump to identify"
Write-Host "what sits immediately past outBuf+capacity (function pointer / vtable / heap metadata)."