fe2a6db786
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>
138 lines
3.4 KiB
C#
138 lines
3.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using System.Xml;
|
|
|
|
namespace ArchestrAServices.Contract;
|
|
|
|
public class ASBCustomSerializer : XmlObjectSerializer
|
|
{
|
|
protected string m_ASBPrefix = "ASB";
|
|
|
|
protected Type m_Type;
|
|
|
|
protected bool m_IsArray;
|
|
|
|
protected bool m_IsCustomSerialization;
|
|
|
|
protected XmlObjectSerializer m_FallbackSerializer;
|
|
|
|
public ASBCustomSerializer(Type type, XmlObjectSerializer fallbackSerializer)
|
|
{
|
|
Type c = type;
|
|
m_IsArray = false;
|
|
if (null != type && type.IsArray)
|
|
{
|
|
m_IsArray = true;
|
|
c = type.GetElementType();
|
|
}
|
|
m_Type = type;
|
|
m_IsCustomSerialization = typeof(IASBCustomSerializableType).IsAssignableFrom(c);
|
|
m_FallbackSerializer = fallbackSerializer;
|
|
}
|
|
|
|
public override bool IsStartObject(XmlDictionaryReader reader)
|
|
{
|
|
bool flag = false;
|
|
if (m_IsCustomSerialization && reader != null)
|
|
{
|
|
return string.Compare(reader.LocalName, m_ASBPrefix, StringComparison.CurrentCultureIgnoreCase) == 0;
|
|
}
|
|
return m_FallbackSerializer.IsStartObject(reader);
|
|
}
|
|
|
|
public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
|
|
{
|
|
object obj = null;
|
|
if (m_IsCustomSerialization && reader != null)
|
|
{
|
|
using MemoryStream memoryStream = new MemoryStream(reader.ReadElementContentAsBase64());
|
|
if (memoryStream != null && memoryStream.Length > 0)
|
|
{
|
|
BinaryReader binaryReader = new BinaryReader(memoryStream);
|
|
if (m_IsArray)
|
|
{
|
|
int num = binaryReader.ReadInt32();
|
|
if (num > 0)
|
|
{
|
|
Type elementType = m_Type.GetElementType();
|
|
if (null != elementType && Activator.CreateInstance(elementType) is IASBCustomSerializableType iASBCustomSerializableType)
|
|
{
|
|
obj = iASBCustomSerializableType.InitializeArrayFromStream(binaryReader, num);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
obj = Activator.CreateInstance(m_Type);
|
|
((IASBCustomSerializableType)obj).InitializeFromStream(binaryReader);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
obj = m_FallbackSerializer.ReadObject(reader, verifyObjectName);
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
public override void WriteEndObject(XmlDictionaryWriter writer)
|
|
{
|
|
if (m_IsCustomSerialization && writer != null)
|
|
{
|
|
writer.WriteEndElement();
|
|
}
|
|
else
|
|
{
|
|
m_FallbackSerializer.WriteEndObject(writer);
|
|
}
|
|
}
|
|
|
|
public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
|
|
{
|
|
if (m_IsCustomSerialization && writer != null)
|
|
{
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
try
|
|
{
|
|
BinaryWriter bw = new BinaryWriter(memoryStream);
|
|
if (m_IsArray)
|
|
{
|
|
if (graph != null)
|
|
{
|
|
Type elementType = m_Type.GetElementType();
|
|
if (null != elementType && Activator.CreateInstance(elementType) is IASBCustomSerializableType iASBCustomSerializableType)
|
|
{
|
|
iASBCustomSerializableType.WriteArrayToStream(graph, ref bw);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
((IASBCustomSerializableType)graph).WriteToStream(bw);
|
|
}
|
|
byte[] array = memoryStream.ToArray();
|
|
writer.WriteBase64(array, 0, array.Length);
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
memoryStream.Dispose();
|
|
}
|
|
}
|
|
m_FallbackSerializer.WriteObjectContent(writer, graph);
|
|
}
|
|
|
|
public override void WriteStartObject(XmlDictionaryWriter writer, object graph)
|
|
{
|
|
if (m_IsCustomSerialization && writer != null)
|
|
{
|
|
writer.WriteStartElement(m_ASBPrefix);
|
|
}
|
|
else
|
|
{
|
|
m_FallbackSerializer.WriteStartObject(writer, graph);
|
|
}
|
|
}
|
|
}
|