Skip to content

Commit 24d931c

Browse files
committed
Fix the BOM-migration regex that ate the previous line at 8 sites
The migration in d391aa6 used a value-capture regex that included [\s\S]{0,50}? so the match could cross a newline. At 8 sites the rewriter consumed the assignment line before each ConvertTo-Json pipeline and produced two garbled lines: `Save-TcpkJson -Value $path = Join-Path $Dir 'coverage.json'` followed by `$obj -Path $path -Depth 6`. The brace-balance checker did not catch it because the braces still balanced. The audit died with parse errors on the first affected file loaded, which was _Coverage.ps1 on the reporter's Windows machine. Every corrupted site restored to a proper `Save-TcpkJson -Value $x -Path $p -Depth n` call on its own line: _Coverage.ps1, _Llm.ps1, _Osv.ps1, three sites in Invoke-TcpkAudit.ps1, Save-TcpkFileSnapshot.ps1, Save-TcpkRegistrySnapshot.ps1. Lesson recorded so this class of mistake stays out of future migrations: never use [\s\S] in a codebase-wide rewriter; eyeball the diff before commit; ship one file first if the change is unverified on Windows.
1 parent 72f5f33 commit 24d931c

7 files changed

Lines changed: 27 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ Release history for TCPK. Newest first.
44

55
## Unreleased
66

7+
**Fix the BOM-migration regex that ate the previous line at 8 sites.** The migration in
8+
`d391aa6` used a regex with `[\s\S]{0,50}?` in the value capture. That allowed the match
9+
to cross a newline, so at 8 sites the rewriter consumed the assignment line before each
10+
`ConvertTo-Json` pipeline and produced two garbled lines like `Save-TcpkJson -Value $path
11+
= Join-Path $Dir 'coverage.json'` and `$obj -Path $path -Depth 6`. The audit died with
12+
parse errors on the first affected file loaded (`_Coverage.ps1`, `_Llm.ps1`, `_Osv.ps1`,
13+
`Invoke-TcpkAudit.ps1`, `Save-TcpkFileSnapshot.ps1`, `Save-TcpkRegistrySnapshot.ps1`).
14+
The brace balance checker did not catch it because the braces still balanced.
15+
16+
Every corrupted site restored to a proper `Save-TcpkJson -Value $x -Path $p -Depth n`
17+
call on its own line.
18+
719
**Fix a bad regex in the pre-flight guard that aborted the whole audit on any Windows
820
target.** The guard used `-match '(?i)\Program Files\WindowsApps\'`. .NET regex parses
921
`\P` as an invalid Unicode-property escape and throws on compile, before the check loop

TCPK/Private/_Coverage.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ function Save-TcpkCoverage {
9696
)
9797
$obj = New-TcpkCoverageManifest -Elevated $Elevated -ProcessAttached $ProcessAttached `
9898
-AttachedPid $AttachedPid -OnlineCve $OnlineCve -ScanProfile $ScanProfile -GeneratedAt $GeneratedAt
99-
Save-TcpkJson -Value $path = Join-Path $Dir 'coverage.json'
100-
$obj -Path $path -Depth 6
99+
$path = Join-Path $Dir 'coverage.json'
100+
Save-TcpkJson -Value $obj -Path $path -Depth 6
101101
$path
102102
}
103103

TCPK/Private/_Llm.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function Set-TcpkLlmConfig {
6666
if ($PSBoundParameters.ContainsKey('BaseUrl')) { $cfg | Add-Member baseUrl $BaseUrl -Force }
6767
if ($PSBoundParameters.ContainsKey('ApiKey')) { $cfg | Add-Member apiKey $ApiKey -Force }
6868
if ($PSBoundParameters.ContainsKey('Enabled')) { $cfg | Add-Member enabled $Enabled -Force }
69-
if ($PSBoundParameters.ContainsKey('Temperature')) { $cfg | Add-Member temperature Save-TcpkJson -Value $Temperature -Force }
70-
$cfg -Path (Get-TcpkLlmConfigPath) -Depth 6
69+
if ($PSBoundParameters.ContainsKey('Temperature')) { $cfg | Add-Member temperature $Temperature -Force }
70+
Save-TcpkJson -Value $cfg -Path (Get-TcpkLlmConfigPath) -Depth 6
7171
$script:TcpkLlmConfig = $cfg
7272
return $cfg
7373
}

TCPK/Private/_Osv.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function Get-TcpkOsvCache {
241241
function Save-TcpkOsvCache {
242242
[CmdletBinding()] param([Parameter(Mandatory)]$Cache)
243243
$p = Get-TcpkOsvCachePath
244-
try { ([pscustomobject]Save-TcpkJson -Value $Cache) -Path $p -Depth 8 -ErrorAction Stop } catch { }
244+
try { Save-TcpkJson -Value ([pscustomobject]$Cache) -Path $p -Depth 8 } catch { }
245245
}
246246

247247
function Get-TcpkOsvCacheKey { param([string]$Ecosystem, [string]$Name, [string]$Version)

TCPK/Public/Invoke-TcpkAudit.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,8 @@ function Invoke-TcpkAudit {
975975
Write-Information -MessageData " Extracting interesting strings (recon)..." -InformationAction Continue
976976
$rsSw = [System.Diagnostics.Stopwatch]::StartNew()
977977
try {
978-
$reconStrings = Get-TcpkReconStrings -Path Save-TcpkJson -Value $expanded
979-
$reconStrings -Path (Join-Path $OutDir 'strings.json') -Depth 4
978+
$reconStrings = Get-TcpkReconStrings -Path $expanded
979+
Save-TcpkJson -Value $reconStrings -Path (Join-Path $OutDir 'strings.json') -Depth 4
980980
Write-Information -MessageData (" strings.json: {0} URLs, {1} paths, {2} reg keys, {3} IPs, {4} emails, {5} cmd refs" -f `
981981
@($reconStrings.Urls).Count, @($reconStrings.FilePaths).Count, @($reconStrings.RegistryKeys).Count, `
982982
@($reconStrings.IpAddresses).Count, @($reconStrings.Emails).Count, @($reconStrings.Commands).Count) -InformationAction Continue
@@ -989,8 +989,8 @@ function Invoke-TcpkAudit {
989989

990990
# --- attack-surface map (synthesized entry-point view; Batch C deliverable) ---
991991
try {
992-
$surface = Save-TcpkJson -Value $findingsFull | Get-TcpkAttackSurface
993-
$surface -Path (Join-Path $OutDir 'attack-surface.json') -Depth 6
992+
$surface = $findingsFull | Get-TcpkAttackSurface
993+
Save-TcpkJson -Value $surface -Path (Join-Path $OutDir 'attack-surface.json') -Depth 6
994994
$catSummary = (@($surface.Categories) | ForEach-Object { "$($_.Label)=$($_.Count)" }) -join '; '
995995
$all.Add( (New-TcpkFinding -Module 'recon' -RuleId 'attacksurface.summary' `
996996
-Severity 'INFO' -Confidence 'Confirmed' `
@@ -1023,8 +1023,8 @@ function Invoke-TcpkAudit {
10231023

10241024
# --- exploit plan (CVE matches + exploitable findings -> actionable items) ---
10251025
try {
1026-
$plan = @(Get-TcpkExploitPlan -Findings $findingsFull -CveMatches Save-TcpkJson -Value $cveMatches -Path $expanded)
1027-
$plan -Path (Join-Path $OutDir 'exploits.json') -Depth 5
1026+
$plan = @(Get-TcpkExploitPlan -Findings $findingsFull -CveMatches $cveMatches -Path $expanded)
1027+
Save-TcpkJson -Value $plan -Path (Join-Path $OutDir 'exploits.json') -Depth 5
10281028
$expModules = @($plan | Where-Object { $_.Module }).Count
10291029
Write-Information -MessageData " exploits.json: $(@($plan).Count) actionable items ($expModules with a framework exploit module)" -InformationAction Continue
10301030
Write-TcpkLog -Level SUCCESS -Component 'exploit.plan' -Message "$(@($plan).Count) items, $expModules with a module" | Out-Null

TCPK/Public/OsIntegration/Save-TcpkFileSnapshot.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function Save-TcpkFileSnapshot {
4747
}
4848
}
4949
}
50-
Confirm-TcpkParentDir -FilePath Save-TcpkJson -Value $OutFile
51-
$snap -Path $OutFile -Depth 4
50+
Confirm-TcpkParentDir -FilePath $OutFile
51+
Save-TcpkJson -Value $snap -Path $OutFile -Depth 4
5252

5353
New-TcpkFinding -Module 'os' -RuleId 'fs.snapshot' `
5454
-Severity 'INFO' -Confidence 'Confirmed' `

TCPK/Public/OsIntegration/Save-TcpkRegistrySnapshot.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function Save-TcpkRegistrySnapshot {
4444
$snap[$kp] = $vals
4545
}
4646
}
47-
Confirm-TcpkParentDir -FilePath Save-TcpkJson -Value $OutFile
48-
$snap -Path $OutFile -Depth 6
47+
Confirm-TcpkParentDir -FilePath $OutFile
48+
Save-TcpkJson -Value $snap -Path $OutFile -Depth 6
4949

5050
New-TcpkFinding -Module 'os' -RuleId 'registry.snapshot' `
5151
-Severity 'INFO' -Confidence 'Confirmed' `

0 commit comments

Comments
 (0)