Files
mxaccess/analysis/decompiled/aaServicesCommonDataContracts/ASBClientAccessLayer/ClientAccessUtilities.cs
T
Joseph Doherty fe2a6db786
rust / build / test / clippy / fmt (push) Has been cancelled
Initial project state: .NET reference, design, Rust port (M0+M1), evidence
Layout:
- src/                    .NET 10 x64 reference: MxNativeCodec, MxNativeClient,
                          MxAsbClient, probes, tests, harnesses. Executable spec.
- design/                 Architectural plan for the Rust port (M0–M6), error
                          model, protocol invariants, risks (R1–R16), adversarial
                          review log (review.md).
- rust/                   Rust workspace. M0 skeleton + M1 codec parity.
                          mxaccess-codec: 215 unit tests + 2 cross-implementation
                          parity tests (byte-identical against .NET reference).
                          Other crates are M0 stubs awaiting M2+.
- captures/               Frida + netsh + pcap evidence per CLAUDE.md
                          ("captures are evidence, not throwaway logs").
- analysis/               Decompiled C# (frida/proxy/decompiled-*),
                          Ghidra exports for native DLLs (`exports/` only —
                          working state at `projects/` and AVEVA's input
                          binaries at `input/` are gitignored).
- docs/                   Reverse-engineering reference docs.
- tools/                  Setup-LiveProbeEnv.ps1 (Infisical credential fetcher),
                          Compute-Crc.ps1 (.NET parity helper).
- .github/workflows/      Rust CI: fmt + build + test + clippy on Windows.
- LICENSE                 MIT (Joseph Doherty, 2026).

Verified:
- cargo test --workspace → 217 passed (215 unit + 2 .NET parity), 0 failed
- cargo clippy --workspace -- -D warnings → clean
- cargo fmt --all -- --check → clean
- cargo publish --dry-run -p mxaccess-codec → packages cleanly

Excluded from history (see .gitignore):
- **/bin, **/obj, **/target — build artifacts
- analysis/ghidra/projects/ — Ghidra working state (regenerable)
- analysis/ghidra/input/ — AVEVA proprietary DLLs (vendor IP)

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

105 lines
4.3 KiB
C#

#define TRACE
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Discovery;
using System.Xml;
using ArchestrAServices.Common;
namespace ASBClientAccessLayer;
public class ClientAccessUtilities
{
private Random random = new Random();
public ClientAccessUtilities()
{
random = new Random(Environment.TickCount);
}
public EndpointDiscoveryMetadata FindServiceEndpoint(Type ContractType, Uri[] Scopes, out ASBDiscoveryResult1 Result)
{
Collection<Uri> scopes = new Collection<Uri>(Scopes.ToList());
return FindServiceEndpoint(ContractType.Name, scopes, out Result);
}
public EndpointDiscoveryMetadata FindServiceEndpoint(string ContractTypeName, Collection<Uri> Scopes, out ASBDiscoveryResult1 Result)
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint -- Enter");
Result = ASBDiscoveryResult1.Unknown;
string text = SvcUtilities.GetDiscoveryEndpoint();
if (!string.IsNullOrEmpty(text))
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint -- DiscoveryEndPoint {text} method");
if (!text.ToLower().EndsWith("/probe"))
{
text += "/Probe";
}
Uri probeEndpointAddress = new Uri(text);
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint -- calling InternalFindServiceEndpoint() method");
return InternalFindServiceEndpoint(ContractTypeName, Scopes, probeEndpointAddress, out Result);
}
Result = ASBDiscoveryResult1.DiscoveryNotAvailable;
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint -- Exit");
return null;
}
private EndpointDiscoveryMetadata InternalFindServiceEndpoint(string ContractName, Collection<Uri> Scopes, Uri probeEndpointAddress, out ASBDiscoveryResult1 Result)
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, $"InternalFindServiceEndpoint() Enter");
if (string.IsNullOrEmpty(ContractName))
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, $"InternalFindServiceEndpoint() Empty contact name");
Result = ASBDiscoveryResult1.DiscoveryBadParameters;
return null;
}
if (probeEndpointAddress == null)
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, $"InternalFindServiceEndpoint() probeEndpointAddress is null");
Result = ASBDiscoveryResult1.DiscoveryBadParameters;
return null;
}
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"InternalFindServiceEndpoint() initializing...");
EndpointAddress endpointAddress = new EndpointAddress(probeEndpointAddress);
using (DiscoveryClient discoveryClient = new DiscoveryClient(new DiscoveryEndpoint(SvcUtilities.GetBinding(probeEndpointAddress.ToString()), endpointAddress)))
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"InternalFindServiceEndpoint() Creating FindCriteria instance ...");
FindCriteria findCriteria = new FindCriteria();
Result = ASBDiscoveryResult1.Unknown;
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint finding services with interface {ContractName} and {findCriteria.Scopes.Count()} scopes");
try
{
XmlQualifiedName item = new XmlQualifiedName(ContractName, "http://ArchestrAServices.Contract");
findCriteria.ContractTypeNames.Add(item);
foreach (Uri Scope in Scopes)
{
findCriteria.Scopes.Add(Scope);
}
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"FindServiceEndpoint finding services with interface {ContractName} and {findCriteria.Scopes.Count()} scopes");
foreach (Uri scope in findCriteria.Scopes)
{
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $" {scope.AbsoluteUri.ToString()}");
}
FindResponse findResponse = discoveryClient.Find(findCriteria);
if (findResponse != null && findResponse.Endpoints.Count > 0)
{
Result = ASBDiscoveryResult1.Success;
return findResponse.Endpoints[random.Next(findResponse.Endpoints.Count())];
}
Result = ASBDiscoveryResult1.DiscoveryReturnedNoEndpoints;
}
catch (TargetInvocationException)
{
}
catch (UriFormatException)
{
}
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"InternalFindServiceEndpoint() Enter");
}
return null;
}
}