Initial project state: .NET reference, design, Rust port (M0+M1), evidence
rust / build / test / clippy / fmt (push) Has been cancelled
rust / build / test / clippy / fmt (push) Has been cancelled
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>
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Xml;
|
||||
|
||||
namespace Asb.Base.V2.Serialization;
|
||||
|
||||
public sealed class BaseV2Serializer : XmlObjectSerializer
|
||||
{
|
||||
private const string BaseV2Prefix = "ASBBaseV2";
|
||||
|
||||
private readonly Type elementType;
|
||||
|
||||
private readonly bool useCustomSerialization;
|
||||
|
||||
private readonly XmlObjectSerializer fallbackSerializer;
|
||||
|
||||
public BaseV2Serializer(Type type, XmlObjectSerializer fallbackSerializer)
|
||||
{
|
||||
this.fallbackSerializer = fallbackSerializer;
|
||||
elementType = type;
|
||||
if (!(type == null))
|
||||
{
|
||||
Type c = (type.IsArray ? type.GetElementType() : type);
|
||||
useCustomSerialization = typeof(IBaseV2CustomSerializable).IsAssignableFrom(c);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsStartObject(XmlDictionaryReader reader)
|
||||
{
|
||||
if (useCustomSerialization)
|
||||
{
|
||||
return string.Compare(reader.LocalName, "ASBBaseV2", StringComparison.CurrentCultureIgnoreCase) == 0;
|
||||
}
|
||||
return fallbackSerializer.IsStartObject(reader);
|
||||
}
|
||||
|
||||
public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
|
||||
{
|
||||
if (useCustomSerialization)
|
||||
{
|
||||
using MemoryStream input = new MemoryStream(reader.ReadElementContentAsBase64());
|
||||
using BinaryReader binaryReader = new BinaryReader(input);
|
||||
if (binaryReader.ReadBoolean())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (Activator.CreateInstance(elementType.IsArray ? elementType.GetElementType() : elementType) is IBaseV2CustomSerializable baseV2CustomSerializable)
|
||||
{
|
||||
if (elementType.IsArray)
|
||||
{
|
||||
int arrayLength = binaryReader.ReadInt32();
|
||||
return baseV2CustomSerializable.InitializeArrayFromStream(binaryReader, arrayLength);
|
||||
}
|
||||
baseV2CustomSerializable.InitializeFromStream(binaryReader);
|
||||
return baseV2CustomSerializable;
|
||||
}
|
||||
}
|
||||
return fallbackSerializer.ReadObject(reader, verifyObjectName);
|
||||
}
|
||||
|
||||
public override void WriteEndObject(XmlDictionaryWriter writer)
|
||||
{
|
||||
if (useCustomSerialization)
|
||||
{
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
fallbackSerializer.WriteEndObject(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
|
||||
{
|
||||
bool flag = false;
|
||||
if (useCustomSerialization)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
|
||||
binaryWriter.Write(graph == null);
|
||||
if (graph == null)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else if (elementType.IsArray)
|
||||
{
|
||||
if (Activator.CreateInstance(elementType.GetElementType()) is IBaseV2CustomSerializable baseV2CustomSerializable)
|
||||
{
|
||||
baseV2CustomSerializable.WriteArrayToStream(graph, binaryWriter);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
else if (graph is IBaseV2CustomSerializable baseV2CustomSerializable2)
|
||||
{
|
||||
baseV2CustomSerializable2.WriteToStream(binaryWriter);
|
||||
flag = true;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
byte[] array = memoryStream.ToArray();
|
||||
writer.WriteBase64(array, 0, array.Length);
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
fallbackSerializer.WriteObjectContent(writer, graph);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteStartObject(XmlDictionaryWriter writer, object graph)
|
||||
{
|
||||
if (useCustomSerialization)
|
||||
{
|
||||
writer.WriteStartElement("ASBBaseV2");
|
||||
}
|
||||
else
|
||||
{
|
||||
fallbackSerializer.WriteStartObject(writer, graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Description;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
|
||||
namespace Asb.Base.V2.Serialization;
|
||||
|
||||
public sealed class BaseV2SerializerContractBehaviorAttribute : Attribute, IContractBehavior
|
||||
{
|
||||
public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
|
||||
{
|
||||
ReplaceSerializerOperationBehavior(contractDescription);
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
|
||||
{
|
||||
ReplaceSerializerOperationBehavior(contractDescription);
|
||||
}
|
||||
|
||||
public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
|
||||
{
|
||||
foreach (OperationDescription operation in contractDescription.Operations)
|
||||
{
|
||||
foreach (MessageDescription message in operation.Messages)
|
||||
{
|
||||
ValidateMessagePartDescription(message.Body.ReturnValue);
|
||||
foreach (MessagePartDescription part in message.Body.Parts)
|
||||
{
|
||||
ValidateMessagePartDescription(part);
|
||||
}
|
||||
foreach (MessageHeaderDescription header in message.Headers)
|
||||
{
|
||||
ValidateCustomSerializableType(header.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateMessagePartDescription(MessagePartDescription part)
|
||||
{
|
||||
if (part != null)
|
||||
{
|
||||
ValidateCustomSerializableType(part.Type);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateCustomSerializableType(Type type)
|
||||
{
|
||||
if (typeof(IBaseV2CustomSerializable).IsAssignableFrom(type))
|
||||
{
|
||||
if (!type.IsPublic)
|
||||
{
|
||||
throw new InvalidOperationException("Custom serialization is supported in public types only");
|
||||
}
|
||||
if (type.IsClass && type.GetConstructor(new Type[0]) == null)
|
||||
{
|
||||
throw new InvalidOperationException("Custom serializable types must have a public, parameterless constructor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReplaceSerializerOperationBehavior(ContractDescription contract)
|
||||
{
|
||||
foreach (OperationDescription operation in contract.Operations)
|
||||
{
|
||||
for (int i = 0; i < operation.Behaviors.Count; i++)
|
||||
{
|
||||
if (operation.Behaviors[i] is DataContractSerializerOperationBehavior)
|
||||
{
|
||||
operation.Behaviors[i] = new BaseV2SerializerOperationBehavior(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ServiceModel.Description;
|
||||
using System.Xml;
|
||||
using ArchestrAServices.Common;
|
||||
|
||||
namespace Asb.Base.V2.Serialization;
|
||||
|
||||
public class BaseV2SerializerOperationBehavior : DataContractSerializerOperationBehavior
|
||||
{
|
||||
public BaseV2SerializerOperationBehavior(OperationDescription operation)
|
||||
: base(operation)
|
||||
{
|
||||
}
|
||||
|
||||
public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "BaseV2SerializerOperationBehavior:CreateSerializer-creating an instance for BaseV2Serializer class");
|
||||
return new BaseV2Serializer(type, base.CreateSerializer(type, name, ns, knownTypes));
|
||||
}
|
||||
|
||||
public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "BaseV2SerializerOperationBehavior:CreateSerializer-creating an instance for BaseV2Serializer class");
|
||||
return new BaseV2Serializer(type, base.CreateSerializer(type, name, ns, knownTypes));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Asb.Base.V2.Serialization;
|
||||
|
||||
public interface IBaseV2CustomSerializable
|
||||
{
|
||||
void WriteToStream(BinaryWriter writer);
|
||||
|
||||
void InitializeFromStream(BinaryReader reader);
|
||||
|
||||
void WriteArrayToStream(object graph, BinaryWriter writer);
|
||||
|
||||
object InitializeArrayFromStream(BinaryReader reader, int arrayLength);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Asb.Base.V2.Serialization;
|
||||
|
||||
public static class SerializationExtensions
|
||||
{
|
||||
public static void WriteStringSafe(this BinaryWriter writer, string value)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
writer.Write(value == null);
|
||||
if (value != null)
|
||||
{
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadStringSafe(this BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
if (!reader.ReadBoolean())
|
||||
{
|
||||
return reader.ReadString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user