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:
@@ -0,0 +1,156 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class IPAddressWatcher : IDisposable
|
||||
{
|
||||
private readonly ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim();
|
||||
|
||||
private List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public event IPAddressChangeEventHandler AddressChangedEvent;
|
||||
|
||||
public IPAddressWatcher()
|
||||
{
|
||||
ipAddresses = GetAllIpAddresses();
|
||||
}
|
||||
|
||||
~IPAddressWatcher()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Start watching for IP address changes");
|
||||
NetworkChange.NetworkAddressChanged += IpChangedEventHandler;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Stop watching for IP address changes");
|
||||
NetworkChange.NetworkAddressChanged -= IpChangedEventHandler;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private static List<IPAddress> GetAllIpAddresses()
|
||||
{
|
||||
List<IPAddress> list = new List<IPAddress>();
|
||||
NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||
for (int i = 0; i < allNetworkInterfaces.Length; i++)
|
||||
{
|
||||
foreach (UnicastIPAddressInformation unicastAddress in allNetworkInterfaces[i].GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (unicastAddress.IsDnsEligible && unicastAddress.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, " Found IPV4 address = {0}", unicastAddress.Address);
|
||||
list.Add(unicastAddress.Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Found a total of {0} IPV4 addresses", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private bool HaveIpAddressesChanged()
|
||||
{
|
||||
bool flag = false;
|
||||
List<IPAddress> allIpAddresses = GetAllIpAddresses();
|
||||
if (allIpAddresses.Count != ipAddresses.Count)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address count has changed: current count = {0}, previous count = {1}", allIpAddresses.Count, ipAddresses.Count);
|
||||
flag = true;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
foreach (IPAddress item in allIpAddresses)
|
||||
{
|
||||
if (!ipAddresses.Contains(item))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address has changed: new address = {0} did not previously exist", item);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
foreach (IPAddress ipAddress in ipAddresses)
|
||||
{
|
||||
if (!allIpAddresses.Contains(ipAddress))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address has changed: old address = {0} no longer exists", ipAddress);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Addresses Previous: {0} and current {1}", string.Join(",", ipAddresses.Select((IPAddress a) => a.ToString())), string.Join(",", allIpAddresses.Select((IPAddress a) => a.ToString())));
|
||||
ipAddresses = allIpAddresses;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void IpChangedEventHandler(object sender, EventArgs e)
|
||||
{
|
||||
cacheLock.EnterWriteLock();
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
flag = HaveIpAddressesChanged();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cacheLock.ExitWriteLock();
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
TriggerNetworkAddressChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private Task TriggerNetworkAddressChanged()
|
||||
{
|
||||
IPAddressChangeEventHandler handler = this.AddressChangedEvent;
|
||||
if (handler != null)
|
||||
{
|
||||
return Task.Factory.StartNew(delegate
|
||||
{
|
||||
handler();
|
||||
});
|
||||
}
|
||||
return Task.Factory.StartNew(delegate
|
||||
{
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (disposing && cacheLock != null)
|
||||
{
|
||||
cacheLock.Dispose();
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user