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,134 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ServiceModel;
|
||||
|
||||
namespace Asb.Base.V2;
|
||||
|
||||
public sealed class ConnectContext<T> : IDisposable where T : class, IAuthenticateAsb
|
||||
{
|
||||
private bool disposed;
|
||||
|
||||
public bool Success { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public ChannelFactory<T> ServiceChannelFactory { get; set; }
|
||||
|
||||
public T ServiceClient { get; set; }
|
||||
|
||||
public IClientChannel ServiceChannel { get; set; }
|
||||
|
||||
public Guid ConnectionId { get; set; }
|
||||
|
||||
public string ConnectionUser { get; set; }
|
||||
|
||||
public string ConnectionApplication { get; set; }
|
||||
|
||||
~ConnectContext()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public bool EstablishSecureSession(string solutionName, ClientAccess access)
|
||||
{
|
||||
string errorMessage = string.Empty;
|
||||
Guid connectId = Guid.Empty;
|
||||
Success = SystemAuthenticationClientAuthentication.EstablishSecureSession(solutionName, GenerateClientMetadata(access), (ConnectRequest request) => ServiceClient.Connect(request), (AuthenticateMeRequest request) => ServiceClient.AuthenticateMe(request), delegate(Guid id)
|
||||
{
|
||||
connectId = id;
|
||||
}, delegate(string msg)
|
||||
{
|
||||
errorMessage = msg;
|
||||
});
|
||||
if (Success)
|
||||
{
|
||||
ConnectionId = connectId;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = errorMessage;
|
||||
}
|
||||
return Success;
|
||||
}
|
||||
|
||||
public void DisconnectSecureSession()
|
||||
{
|
||||
SystemAuthenticationClientAuthentication.DisconnectSecureSession(ConnectionId, delegate(DisconnectRequest request)
|
||||
{
|
||||
ServiceClient.Disconnect(request);
|
||||
});
|
||||
}
|
||||
|
||||
public void CastClientToChannel()
|
||||
{
|
||||
ServiceChannel = ServiceClient as IClientChannel;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private ClientMetadata GenerateClientMetadata(ClientAccess access)
|
||||
{
|
||||
ClientMetadata clientMetadata = new ClientMetadata
|
||||
{
|
||||
UserName = (string.IsNullOrEmpty(ConnectionUser) ? Environment.UserName : ConnectionUser),
|
||||
HostName = Environment.MachineName,
|
||||
ApplicationName = (string.IsNullOrEmpty(ConnectionApplication) ? Process.GetCurrentProcess().ProcessName : ConnectionApplication),
|
||||
Access = access
|
||||
};
|
||||
string terminalServicesClientName = GetTerminalServicesClientName();
|
||||
if (terminalServicesClientName == "\0")
|
||||
{
|
||||
clientMetadata.SessionHostName = string.Empty;
|
||||
clientMetadata.SessionId = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
clientMetadata.SessionHostName = terminalServicesClientName;
|
||||
clientMetadata.SessionId = Process.GetCurrentProcess().SessionId.ToString();
|
||||
}
|
||||
return clientMetadata;
|
||||
}
|
||||
|
||||
private static string GetTerminalServicesClientName()
|
||||
{
|
||||
IntPtr ppBuffer;
|
||||
int pBytesReturned;
|
||||
bool num = NativeMethods.WTSQuerySessionInformation(NativeMethods.WTS_CURRENT_SERVER_HANDLE, -1, NativeMethods.WTS_INFO_CLASS.WTSClientName, out ppBuffer, out pBytesReturned);
|
||||
string result = null;
|
||||
if (num)
|
||||
{
|
||||
result = Marshal.PtrToStringAuto(ppBuffer);
|
||||
NativeMethods.WTSFreeMemory(ppBuffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
disposed = true;
|
||||
if (disposing)
|
||||
{
|
||||
if (ServiceChannel != null)
|
||||
{
|
||||
ServiceChannel.Close();
|
||||
ServiceChannel.Dispose();
|
||||
}
|
||||
ServiceChannel = null;
|
||||
if (ServiceChannelFactory != null)
|
||||
{
|
||||
ServiceChannelFactory.Close();
|
||||
((IDisposable)ServiceChannelFactory).Dispose();
|
||||
}
|
||||
ServiceChannelFactory = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user