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,275 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ArchestrA.Diagnostics;
|
||||
|
||||
internal static class Logger
|
||||
{
|
||||
public static int ErrorCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int errorCount = 0;
|
||||
int warningCount = 0;
|
||||
long ftLastError = 0L;
|
||||
long ftLastWarning = 0L;
|
||||
if (NativeMethods.GetLoggerStats(string.Empty, ref errorCount, ref ftLastError, ref warningCount, ref ftLastWarning) <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return errorCount;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsLoaded { get; private set; }
|
||||
|
||||
public static int WarningCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int errorCount = 0;
|
||||
int warningCount = 0;
|
||||
long ftLastError = 0L;
|
||||
long ftLastWarning = 0L;
|
||||
if (NativeMethods.GetLoggerStats(string.Empty, ref errorCount, ref ftLastError, ref warningCount, ref ftLastWarning) <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return warningCount;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckRegistry { get; set; }
|
||||
|
||||
private static bool DomainUnloaded { get; set; }
|
||||
|
||||
private static int LoggerClientIdentity { get; set; }
|
||||
|
||||
static Logger()
|
||||
{
|
||||
LoggerClientIdentity = 0;
|
||||
CheckRegistry = true;
|
||||
}
|
||||
|
||||
public static void LogConnection(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogConnection(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogCtorDtor(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogCtorDtor(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogCustom(int cookie, string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogCustom(LoggerClientIdentity, cookie, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogEntryExit(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogEntryExit(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogError(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogError(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogInfo(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogInfo(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogRefCount(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogRefCount(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static int LogRegisterCustomFlag(string flagName)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NativeMethods.RegisterLogFlag(LoggerClientIdentity, 11, flagName);
|
||||
}
|
||||
|
||||
public static int LogRegisterCustomFlagEx(string flagName, int defaultValue)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NativeMethods.RegisterLogFlagEx(LoggerClientIdentity, 11, flagName, defaultValue);
|
||||
}
|
||||
|
||||
public static void LogSQL(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogSQL(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogSetIdentityName(string identityName)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.SetIdentityName(LoggerClientIdentity, identityName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogStartStop(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogStartStop(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogThreadStartStop(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogThreadStartStop(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogTrace(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogTrace(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogWarning(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogWarning(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLoggerCheck()
|
||||
{
|
||||
CheckRegistry = true;
|
||||
}
|
||||
|
||||
private static bool InitLoggerDll()
|
||||
{
|
||||
bool flag = IsLoaded;
|
||||
if (flag)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (CheckRegistry)
|
||||
{
|
||||
IntPtr intPtr = IntPtr.Zero;
|
||||
CheckRegistry = false;
|
||||
new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\Software\\ArchestrA\\Framework\\Logger").Assert();
|
||||
try
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\\ArchestrA\\Framework\\Logger", writable: false);
|
||||
if (registryKey != null)
|
||||
{
|
||||
string text = Convert.ToString(registryKey.GetValue("InstallPath", string.Empty), CultureInfo.InvariantCulture);
|
||||
if (text.Length > 0)
|
||||
{
|
||||
intPtr = NativeMethods.LoadLibraryExW(wParam: new IntPtr(0), lpMdoule: Path.Combine(text, "LoggerDll.dll"), flag: 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
flag = intPtr != IntPtr.Zero;
|
||||
}
|
||||
IsLoaded = flag;
|
||||
return flag;
|
||||
}
|
||||
|
||||
private static bool Initialize()
|
||||
{
|
||||
if (DomainUnloaded)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (LoggerClientIdentity != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int hIdentity = 0;
|
||||
int num = NativeMethods.RegisterLoggerClient(ref hIdentity);
|
||||
LoggerClientIdentity = hIdentity;
|
||||
if (num != 0 && LoggerClientIdentity != 0)
|
||||
{
|
||||
new FileIOPermission(PermissionState.Unrestricted).Assert();
|
||||
try
|
||||
{
|
||||
NativeMethods.SetIdentityName(LoggerClientIdentity, Assembly.GetExecutingAssembly().GetName().Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
AppDomain.CurrentDomain.DomainUnload += OnCurrentDomainUnload;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void OnCurrentDomainUnload(object sender, EventArgs e)
|
||||
{
|
||||
UnInitialize();
|
||||
DomainUnloaded = true;
|
||||
}
|
||||
|
||||
private static void UnInitialize()
|
||||
{
|
||||
if (LoggerClientIdentity != 0)
|
||||
{
|
||||
NativeMethods.UnregisterLoggerClient(LoggerClientIdentity);
|
||||
LoggerClientIdentity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ArchestrA.Diagnostics;
|
||||
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("kernel32")]
|
||||
public static extern IntPtr LoadLibraryExW([MarshalAs(UnmanagedType.LPWStr)] string lpMdoule, IntPtr wParam, int flag);
|
||||
|
||||
[DllImport("kernel32")]
|
||||
internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] string lpMdoule);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGGERCLIENT", ExactSpelling = true)]
|
||||
internal static extern int RegisterLoggerClient(ref int hIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "UNREGISTERLOGGERCLIENT", ExactSpelling = true)]
|
||||
internal static extern int UnregisterLoggerClient(int hIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "SETIDENTITYNAME", ExactSpelling = true)]
|
||||
internal static extern int SetIdentityName(int hIdentity, string strIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGERROR", ExactSpelling = true)]
|
||||
internal static extern void InternalLogError(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGWARNING", ExactSpelling = true)]
|
||||
internal static extern void InternalLogWarning(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGINFO", ExactSpelling = true)]
|
||||
internal static extern void InternalLogInfo(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGTRACE", ExactSpelling = true)]
|
||||
internal static extern void InternalLogTrace(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGSTARTSTOP", ExactSpelling = true)]
|
||||
internal static extern void InternalLogStartStop(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGENTRYEXIT", ExactSpelling = true)]
|
||||
internal static extern void InternalLogEntryExit(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGTHREADSTARTSTOP", ExactSpelling = true)]
|
||||
internal static extern void InternalLogThreadStartStop(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGSQL", ExactSpelling = true)]
|
||||
internal static extern void InternalLogSQL(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCONNECTION", ExactSpelling = true)]
|
||||
internal static extern void InternalLogConnection(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCTORDTOR", ExactSpelling = true)]
|
||||
internal static extern void InternalLogCtorDtor(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGREFCOUNT", ExactSpelling = true)]
|
||||
internal static extern void InternalLogRefCount(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGFLAG", ExactSpelling = true)]
|
||||
internal static extern int RegisterLogFlag(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string strFlag);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGFLAGEX", ExactSpelling = true)]
|
||||
internal static extern int RegisterLogFlagEx(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string strFlag, int nDefaultVal);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCUSTOM2", ExactSpelling = true)]
|
||||
internal static extern void InternalLogCustom(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "GETLOGGERSTATS", ExactSpelling = true)]
|
||||
internal static extern int GetLoggerStats([MarshalAs(UnmanagedType.LPWStr)] string hostName, ref int errorCount, ref long ftLastError, ref int warningCount, ref long ftLastWarning);
|
||||
}
|
||||
Reference in New Issue
Block a user