Files
histsdk/scripts/Capture-AahClientAccessPointValClContext.ps1
T
dohertj2 c95824a65d Initial commit: managed .NET 10 AVEVA Historian SDK + reverse-engineering toolkit
Full read-only SDK (src/AVEVA.Historian.Client) implementing the CLAUDE.md required
surface against AVEVA Historian's binary WCF protocol — no native AVEVA runtime
dependency. All operations live-verified against a local Historian:

- ProbeAsync, ReadRawAsync, ReadAggregateAsync, ReadAtTimeAsync, ReadEventsAsync
- BrowseTagNamesAsync, GetTagMetadataAsync (17 native data-type codes mapped)
- GetConnectionStatusAsync, GetStoreForwardStatusAsync, GetSystemParameterAsync
- 108/108 unit + integration tests pass

Includes the reverse-engineering toolkit (tools/AVEVA.Historian.ReverseEngineering)
used to decode the protocol: WCF probes, IL inspection via dnlib, and IL-rewrite
instrumentation (instrument-wcf-{write,read}message etc.) plus the .NET Framework
trace harness (tools/AVEVA.Historian.NativeTraceHarness) for parity testing.

Sanitized handoff evidence under docs/reverse-engineering/. Native AVEVA binaries
(current/, aveva-install-x64/, aveva-install-x86/) are gitignored — fetch separately
from the AVEVA installer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 06:31:48 -04:00

92 lines
3.4 KiB
PowerShell

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"