param( [ValidateSet("NativeRead", "ManagedValCl")] [string]$Scenario = "NativeRead", [string]$HostName = "localhost", [UInt16]$Port = 32568, [string]$TagName = $env:HISTORIAN_TEST_TAG, [int]$LookbackMinutes = 1440, [int]$MaxRows = 1, [int]$FridaTimeoutSeconds = 35, [string]$OutputPath ) $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $PSScriptRoot $fridaScript = Join-Path $PSScriptRoot "frida\aahclientaccesspoint-valcl-context.js" if (-not (Test-Path -LiteralPath $fridaScript)) { throw "Missing Frida script at $fridaScript" } if ([string]::IsNullOrWhiteSpace($OutputPath)) { $stamp = Get-Date -Format "yyyyMMdd-HHmmss" $OutputPath = Join-Path $repoRoot "artifacts\reverse-engineering\aahclientaccesspoint-valcl-$($Scenario.ToLowerInvariant())-$stamp.ndjson" } $OutputPath = [IO.Path]::GetFullPath($OutputPath) New-Item -ItemType Directory -Force -Path (Split-Path -Parent $OutputPath) | Out-Null $serverProcess = Get-Process -Name "aahClientAccessPoint" -ErrorAction Stop | Select-Object -First 1 Write-Host "Attaching server ValCl context probe to PID $($serverProcess.Id). Capture: $OutputPath" $fridaArgs = @( "-q", "-t", $FridaTimeoutSeconds.ToString(), "-p", $serverProcess.Id.ToString(), "-l", $fridaScript, "-o", $OutputPath ) $fridaJob = Start-Job -ScriptBlock { param([string[]]$ArgsForFrida) & frida @ArgsForFrida } -ArgumentList (,$fridaArgs) Start-Sleep -Seconds 2 try { if ($Scenario -eq "NativeRead") { if ([string]::IsNullOrWhiteSpace($TagName)) { throw "A tag name is required for NativeRead. Pass -TagName or set HISTORIAN_TEST_TAG." } $harness = Join-Path $repoRoot "tools\AVEVA.Historian.NativeTraceHarness\bin\Debug\net481\AVEVA.Historian.NativeTraceHarness.exe" if (-not (Test-Path -LiteralPath $harness)) { dotnet build .\tools\AVEVA.Historian.NativeTraceHarness\AVEVA.Historian.NativeTraceHarness.csproj --nologo --verbosity:minimal | Out-Host } & $harness ` --scenario history ` --server-name $HostName ` --tcp-port $Port ` --tag $TagName ` --lookback-minutes $LookbackMinutes ` --max-rows $MaxRows ` --connection-wait-seconds 15 | Out-Host } else { $probe = Join-Path $repoRoot "tools\AVEVA.Historian.NetFxWcfProbe\bin\Debug\net481\AVEVA.Historian.NetFxWcfProbe.exe" if (-not (Test-Path -LiteralPath $probe)) { dotnet build .\tools\AVEVA.Historian.NetFxWcfProbe\AVEVA.Historian.NetFxWcfProbe.csproj --nologo --verbosity:minimal | Out-Host } & $probe --endpoint "net.pipe://localhost/Hist" | Out-Host } } finally { Wait-Job $fridaJob -Timeout ([Math]::Max($FridaTimeoutSeconds, 5)) | Out-Null $fridaOutput = Receive-Job $fridaJob -ErrorAction SilentlyContinue if ($fridaOutput) { $fridaOutput | Out-Host $fridaSidecar = $OutputPath + ".frida.log" $fridaOutput | Set-Content -LiteralPath $fridaSidecar -Encoding UTF8 if ($fridaOutput -match "Failed to attach|refused to load frida-agent") { Write-Warning "Frida could not attach to aahClientAccessPoint. Run this script from an elevated PowerShell session to capture server helper calls." } } Remove-Job $fridaJob -Force -ErrorAction SilentlyContinue } Write-Host "Server ValCl context capture written to $OutputPath"