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>
276 lines
5.7 KiB
C#
276 lines
5.7 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|