Files
mxaccess/analysis/decompiled/aaMxDataConsumer/CIDataVersionAdapterV1.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

389 lines
16 KiB
C#

using System.Runtime.InteropServices;
using ArchestrAServices.ASBContract;
using ArchestrAServices.ASBIDataContract;
using ArchestrAServices.ASBIDataContract.V2;
using ArchestrAServices.ASBIDataV2Adapter;
using ArchestrAServices.ASBIDataV2Contract;
using ArchestrAServices.Proxy;
public class CIDataVersionAdapterV1(ASBDataProxy ASBProxy) : CIDataVersionAdapter
{
private ASBDataProxy m_ASBProxy = ASBProxy;
private TimePassed m_timePassed = new TimePassed(300);
private ConnectionId m_blankConnectionId;
[return: MarshalAs(UnmanagedType.U1)]
public override bool Connect(ref string errorMessage)
{
bool result = false;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
result = aSBProxy.Connect(out errorMessage);
}
return result;
}
public override void Abort()
{
m_ASBProxy?.Abort();
}
public override void Disconnect()
{
m_ASBProxy?.Disconnect();
}
[return: MarshalAs(UnmanagedType.U1)]
public override bool SupportsArrayElementWrites()
{
return false;
}
public override ArchestrAResult KeepAlive()
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
archestrAResult = aSBProxy.KeepAlive(m_blankConnectionId);
}
return archestrAResult;
}
public override ArchestrAResult Read(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ref ArchestrAServices.ASBIDataV2Contract.RuntimeValue[] ItemValues, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAServices.ASBContract.RuntimeValue[] array2 = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
array2 = null;
archestrAResult = m_ASBProxy.Read(out array, out array2, m_blankConnectionId, Items.ToV1ItemIdentityArray());
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
if (array2 != null)
{
ItemValues = array2.ToV2RuntimeValueArray();
}
}
return archestrAResult;
}
public override ArchestrAResult Write(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items, ArchestrAServices.ASBIDataV2Contract.WriteValue[] Values, uint WriteHandle)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
archestrAResult = m_ASBProxy.Write(out array, Items.ToV1ItemIdentityArray(), Values.ToV1WriteValueArray(), WriteHandle);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
public override ArchestrAResult WriteUser(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items, ArchestrAServices.ASBIDataV2Contract.WriteValue[] Values, ArchestrAServices.ASBIDataV2Contract.UserToken User, uint WriteHandle)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
ArchestrAServices.ASBContract.UserToken user = User.ToV1UserToken();
archestrAResult = m_ASBProxy.WriteUser(out array, Items.ToV1ItemIdentityArray(), Values.ToV1WriteValueArray(), user, WriteHandle);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
public override ArchestrAResult WriteVerified(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items, ArchestrAServices.ASBIDataV2Contract.WriteValue[] Values, ArchestrAServices.ASBIDataV2Contract.UserToken User, ArchestrAServices.ASBIDataV2Contract.UserToken Supervisor, uint WriteHandle)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
ArchestrAServices.ASBContract.UserToken supervisor = Supervisor.ToV1UserToken();
ArchestrAServices.ASBContract.UserToken user = User.ToV1UserToken();
archestrAResult = m_ASBProxy.WriteVerified(out array, Items.ToV1ItemIdentityArray(), Values.ToV1WriteValueArray(), user, supervisor, WriteHandle);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
public override ArchestrAResult WriteSecured(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items, ArchestrAServices.ASBIDataV2Contract.WriteValue[] Values, ArchestrAServices.ASBIDataV2Contract.UserToken User, uint WriteHandle)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
ArchestrAServices.ASBContract.UserToken user = User.ToV1UserToken();
archestrAResult = m_ASBProxy.WriteSecured(out array, Items.ToV1ItemIdentityArray(), Values.ToV1WriteValueArray(), user, WriteHandle);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
public override ArchestrAResult WriteConfirmed(ref ArchestrAServices.ASBIDataV2Contract.WriteValue ValueReceived, ref long WriteToken, ArchestrAServices.ASBIDataV2Contract.ItemIdentity Item, ArchestrAServices.ASBIDataV2Contract.WriteValue Value, ArchestrAServices.ASBIDataV2Contract.UserToken User, ArchestrAServices.ASBIDataV2Contract.UserToken Supervisor)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
ArchestrAServices.ASBContract.WriteValue ValueReceived2 = default(ArchestrAServices.ASBContract.WriteValue);
ArchestrAServices.ASBContract.UserToken supervisor = Supervisor.ToV1UserToken();
ArchestrAServices.ASBContract.UserToken user = User.ToV1UserToken();
ArchestrAServices.ASBContract.WriteValue value = Value.ToV1WriteValue();
ArchestrAServices.ASBContract.ItemIdentity item = Item.ToV1ItemIdentity();
archestrAResult = m_ASBProxy.WriteConfirmed(out ValueReceived2, out WriteToken, item, value, user, supervisor);
ArchestrAServices.ASBIDataV2Contract.WriteValue writeValue = ValueReceived2.ToV2WriteValue();
ValueReceived = writeValue;
}
return archestrAResult;
}
public override ArchestrAResult ConfirmWrite(ArchestrAServices.ASBIDataV2Contract.ItemIdentity Item, long WriteToken, ArchestrAServices.ASBIDataV2Contract.WriteValue Value, ArchestrAServices.ASBIDataV2Contract.UserToken User, ArchestrAServices.ASBIDataV2Contract.UserToken Supervisor, uint WriteHandle)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
ArchestrAServices.ASBContract.UserToken supervisor = Supervisor.ToV1UserToken();
ArchestrAServices.ASBContract.UserToken user = User.ToV1UserToken();
ArchestrAServices.ASBContract.WriteValue value = Value.ToV1WriteValue();
ArchestrAServices.ASBContract.ItemIdentity item = Item.ToV1ItemIdentity();
archestrAResult = m_ASBProxy.ConfirmWrite(item, WriteToken, value, user, supervisor, WriteHandle);
}
return archestrAResult;
}
public override ArchestrAResult PublishWriteComplete(ref ArchestrAServices.ASBIDataV2Contract.ItemWriteComplete[] CompleteWrites)
{
ArchestrAServices.ASBContract.ItemWriteComplete[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
array = null;
archestrAResult = aSBProxy.PublishWriteComplete(out array);
if (array != null)
{
CompleteWrites = array.ToV2ItemWriteCompleteArray();
}
}
return archestrAResult;
}
public override ArchestrAResult CreateSubscription(ref long SubscriptionId, long MaxQueueSize, ulong SampleInterval)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
archestrAResult = aSBProxy.CreateSubscription(out SubscriptionId, MaxQueueSize, SampleInterval);
}
return archestrAResult;
}
public override ArchestrAResult SetSubscriptionState(long SubscriptionId, ArchestrAServices.ASBIDataContract.V2.Variant NewState, ushort StateToChange)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
ArchestrAServices.ASBIDataContract.Variant newState = NewState.ToV1Variant();
archestrAResult = m_ASBProxy.SetSubscriptionState(SubscriptionId, newState, StateToChange);
}
return archestrAResult;
}
public override ArchestrAResult GetSubscriptionState(ref ArchestrAServices.ASBIDataContract.V2.Variant State, long SubscriptionId, ushort StateToGet)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
ArchestrAServices.ASBIDataContract.Variant State2 = default(ArchestrAServices.ASBIDataContract.Variant);
archestrAResult = aSBProxy.GetSubscriptionState(out State2, SubscriptionId, StateToGet);
ArchestrAServices.ASBIDataContract.V2.Variant variant = State2.ToV2Variant();
State = variant;
}
return archestrAResult;
}
public override ArchestrAResult DeleteSubscription(long SubscriptionId)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
archestrAResult = aSBProxy.DeleteSubscription(SubscriptionId);
}
return archestrAResult;
}
public override ArchestrAResult AddMonitoredItems(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ref ArchestrAServices.ASBIDataV2Contract.ItemRegistration[] ItemCapabilities, long SubscriptionId, ArchestrAServices.ASBIDataV2Contract.MonitoredItem[] Items, byte RequireId)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAServices.ASBContract.ItemRegistration[] array2 = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
array2 = null;
archestrAResult = m_ASBProxy.AddMonitoredItems(out array, out array2, SubscriptionId, Items.ToV1MonitoredItemArray(), RequireId);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
if (array2 != null)
{
ItemCapabilities = array2.ToV2ItemRegistrationArray();
}
}
return archestrAResult;
}
public override ArchestrAResult DeleteMonitoredItems(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, long SubscriptionId, ArchestrAServices.ASBIDataV2Contract.MonitoredItem[] Items)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
archestrAResult = m_ASBProxy.DeleteMonitoredItems(out array, SubscriptionId, Items.ToV1MonitoredItemArray());
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
public override ArchestrAResult GetMonitoredItems(ref ArchestrAServices.ASBIDataV2Contract.MonitoredItem[] Items, long SubscriptionId)
{
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
ArchestrAServices.ASBContract.MonitoredItem[] Items2 = Items.ToV1MonitoredItemArray();
archestrAResult = m_ASBProxy.GetMonitoredItems(out Items2, SubscriptionId);
}
return archestrAResult;
}
public override ArchestrAResult Publish(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ref ArchestrAServices.ASBIDataV2Contract.MonitoredItemValue[] Values, long SubscriptionId)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAServices.ASBContract.MonitoredItemValue[] array2 = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
ASBDataProxy aSBProxy = m_ASBProxy;
if (aSBProxy != null)
{
array = null;
array2 = null;
archestrAResult = aSBProxy.Publish(out array, out array2, SubscriptionId);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
if (array2 != null)
{
Values = array2.ToV2MonitoredItemValueArray();
}
}
return archestrAResult;
}
public override ArchestrAResult RegisterItems(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ref ArchestrAServices.ASBIDataV2Contract.ItemRegistration[] ItemCapabilities, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items, byte RequireId, byte RegisterOnly)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAServices.ASBContract.ItemRegistration[] array2 = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
array2 = null;
archestrAResult = m_ASBProxy.RegisterItems(out array, out array2, Items.ToV1ItemIdentityArray(), RequireId, RegisterOnly);
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
if (array2 != null)
{
ItemCapabilities = array2.ToV2ItemRegistrationArray();
}
}
return archestrAResult;
}
public override ArchestrAResult UnregisterItems(ref ArchestrAServices.ASBIDataV2Contract.ItemStatus[] Status, ArchestrAServices.ASBIDataV2Contract.ItemIdentity[] Items)
{
ArchestrAServices.ASBContract.ItemStatus[] array = null;
ArchestrAResult archestrAResult = default(ArchestrAResult);
archestrAResult = ResultFactory.MakeResult(ArchestrAError.SpecificError, 32);
archestrAResult.SpecificErrorCode = 2147614720u;
if (m_ASBProxy != null)
{
array = null;
archestrAResult = m_ASBProxy.UnregisterItems(out array, Items.ToV1ItemIdentityArray());
if (array != null)
{
Status = array.ToV2ItemStatusArray();
}
}
return archestrAResult;
}
}