Files
histsdk/scripts/Attach-NativeTraceHarnessAahClientExportCapture.ps1
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

81 lines
3.1 KiB
PowerShell

param(
[ValidateSet("history", "event")]
[string]$Scenario = "history",
[string]$ServerName = "localhost",
[string]$TagName = "OtOpcUaParityTest_001.Counter",
[string]$RetrievalMode = "Full",
[int]$LookbackMinutes = 1440,
[int]$MaxRows = 1,
[UInt64]$ResolutionTicks = 0,
[switch]$DirectConnection,
[int]$PreLoadSleepSeconds = 10,
[int]$ConnectionWaitSeconds = 15,
[string]$OutputPath = $null
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$fridaScript = Join-Path $PSScriptRoot "frida\aahclient-exports.js"
$harness = Join-Path $repoRoot "tools\AVEVA.Historian.NativeTraceHarness\bin\Debug\net481\AVEVA.Historian.NativeTraceHarness.exe"
if (-not (Test-Path -LiteralPath $harness)) {
throw "Missing harness executable. Run dotnet build .\Histsdk.slnx first."
}
if ([string]::IsNullOrWhiteSpace($OutputPath)) {
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
$OutputPath = Join-Path $repoRoot "docs\reverse-engineering\aahclient-export-frida-$Scenario-$stamp.ndjson"
}
$outputDirectory = Split-Path -Parent $OutputPath
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
$childOut = Join-Path $env:TEMP ("histsdk-aahclient-export-{0}.out.log" -f ([Guid]::NewGuid().ToString("N")))
$childErr = Join-Path $env:TEMP ("histsdk-aahclient-export-{0}.err.log" -f ([Guid]::NewGuid().ToString("N")))
$args = @(
"--scenario", $Scenario,
"--server-name", $ServerName,
"--tag", $TagName,
"--retrieval-mode", $RetrievalMode,
"--lookback-minutes", $LookbackMinutes.ToString(),
"--max-rows", $MaxRows.ToString(),
"--connection-wait-seconds", $ConnectionWaitSeconds.ToString(),
"--pre-load-sleep-seconds", $PreLoadSleepSeconds.ToString()
)
if ($ResolutionTicks -gt 0) {
$args += @("--resolution-ticks", $ResolutionTicks.ToString())
}
if ($DirectConnection) {
$args += "--direct-connection"
}
Write-Host "Starting native trace harness with $PreLoadSleepSeconds second pre-load pause."
$process = Start-Process -FilePath $harness -ArgumentList $args -WorkingDirectory $repoRoot -RedirectStandardOutput $childOut -RedirectStandardError $childErr -PassThru -WindowStyle Hidden
try {
Start-Sleep -Seconds 1
Write-Host "Attaching aahClient.dll export Frida capture to PID $($process.Id). Capture: $OutputPath"
& frida -q -p $process.Id -l $fridaScript 2>&1 | Tee-Object -FilePath $OutputPath
if (-not $process.HasExited) {
$process.WaitForExit(30000) | Out-Null
}
}
finally {
if (-not $process.HasExited) {
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
}
"--- native stdout ---" | Tee-Object -FilePath $OutputPath -Append
Get-Content -LiteralPath $childOut -ErrorAction SilentlyContinue | Tee-Object -FilePath $OutputPath -Append
"--- native stderr ---" | Tee-Object -FilePath $OutputPath -Append
Get-Content -LiteralPath $childErr -ErrorAction SilentlyContinue | Tee-Object -FilePath $OutputPath -Append
Remove-Item -LiteralPath $childOut, $childErr -ErrorAction SilentlyContinue
}
Write-Host "Capture complete: $OutputPath"