param( [string]$Bootpack = "\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry\bootpack\bootpack.txt" ) $ErrorActionPreference="Stop" function Get-EntriesCount([string]$jsonText){ $cnt=-1 try { $obj = ($jsonText | ConvertFrom-Json) if($obj -and $obj.entries){ $cnt = $obj.entries.Count } } catch { $cnt = ([regex]::Matches($jsonText,'"id"\s*:')).Count } return $cnt } # Lecture bootpack (UTF-8 sans BOM) et extraction du pointeur $encNoBom = New-Object System.Text.UTF8Encoding($false) if(!(Test-Path -LiteralPath $Bootpack)){ Write-Host "[BLOCK] bootpack.txt missing -> $Bootpack"; exit 2 } $text=[IO.File]::ReadAllText($Bootpack,$encNoBom) $m=[regex]::Match($text,'(?ms)^\[BUG_KB_JSON_POINTER\]\s*(.*?)(?=^\[|\Z)') if(-not $m.Success){ Write-Host "[GATE-BLOCK] kb_pointer_missing"; exit 5 } $ptr=$m.Groups[1].Value $kp=[regex]::$(if(Match($ptr,'(){ mi)^\s*Path\s* } else { \s*(.+?)\s*$').Groups[1].Value.Trim() }) $ks=[regex]::$(if(Match($ptr,'(){ mi)^\s*SHA256\s* } else { \s*([0-9A-Fa-f]+)\s*$').Groups[1].Value.Trim().ToLower() }) $ke=[regex]::$(if(Match($ptr,'(){ mi)^\s*Entries\s* } else { \s*([0-9]+)\s*$').Groups[1].Value.Trim() }) if([string]::IsNullOrWhiteSpace($kp)){ $kp=Join-Path (Split-Path $Bootpack -Parent) "bootpack_paste.txt" } if(!(Test-Path -LiteralPath $kp)){ Write-Host "[GATE-BLOCK] kb_path_missing -> $kp"; exit 5 } $raw=Get-Content -LiteralPath $kp -Raw $i=$raw.LastIndexOf(']}'); if($i -ge 0){ $raw=$raw.Substring(0,$i+2) } $cnt=Get-EntriesCount $raw if($cnt -lt 0){ Write-Host "[GATE-BLOCK] kb_parse_failed -> $kp"; exit 5 } $real=(Get-FileHash -LiteralPath $kp -Algorithm SHA256).Hash.ToLower() $okSha = ($ks -eq $real) $okEnt = ([string]$ke -eq [string]$cnt) Write-Host ("POINTER -> Path="+$kp+" ; SHA="+$(if([string]::IsNullOrEmpty($ks)){""}else{$ks})+" ; Entries="+$(if([string]::IsNullOrEmpty($ke)){""}else{$ke})) Write-Host ("REAL -> SHA="+$real+" ; Entries="+$cnt) if($okSha -and $okEnt){ Write-Host "[OK] bootpack KB pointer matches" exit 0 } else { $reasons=@() if(-not $okSha){ $reasons += "kb_sha_mismatch" } if(-not $okEnt){ $reasons += "kb_entries_mismatch" } Write-Host ("[GATE-BLOCK] "+($reasons -join ",")) exit 5 }