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>
323 lines
7.4 KiB
C#
323 lines
7.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using ArchestrA.Diagnostics;
|
|
|
|
namespace ArchestrAServices.Common;
|
|
|
|
public class aaLoggerListner : TraceListener
|
|
{
|
|
private enum aaLogType
|
|
{
|
|
LogErrorType,
|
|
LogWarningType,
|
|
LogInfoType,
|
|
LogTraceType,
|
|
LogStartStopType,
|
|
LogThreadStartStopType,
|
|
LogConnectionType,
|
|
LogRefCountType,
|
|
LogCtorDtorType,
|
|
LogSQLType,
|
|
LogEntryExitType
|
|
}
|
|
|
|
private static object LogLockObject = new object();
|
|
|
|
private string CSVLOGFLAG = "ASBAdvancedLog";
|
|
|
|
private string LoggingIdentity = string.Empty;
|
|
|
|
private bool IsCustomLogType;
|
|
|
|
private bool IsCsvLogType;
|
|
|
|
private aaLogType LoggerType;
|
|
|
|
private int CustomLogTypeCookie;
|
|
|
|
private SourceLevels sourceLevel = SourceLevels.All;
|
|
|
|
private string asbLogFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ArchestrA\\LogFiles\\ASBLogging\\";
|
|
|
|
private string asbLogFile;
|
|
|
|
private static object LogFileLockObject = new object();
|
|
|
|
public SourceLevels SourceLevel
|
|
{
|
|
get
|
|
{
|
|
return sourceLevel;
|
|
}
|
|
set
|
|
{
|
|
sourceLevel = value;
|
|
}
|
|
}
|
|
|
|
public aaLoggerListner()
|
|
{
|
|
Logger.LogSetIdentityName(Process.GetCurrentProcess().ProcessName);
|
|
LoggerType = aaLogType.LogTraceType;
|
|
IsCustomLogType = false;
|
|
IsCsvLogType = false;
|
|
CustomLogTypeCookie = 0;
|
|
InitializeAdvanceLog();
|
|
}
|
|
|
|
public aaLoggerListner(string initializeData)
|
|
{
|
|
string[] array = new string[0];
|
|
if (!string.IsNullOrEmpty(initializeData))
|
|
{
|
|
array = initializeData.Split(',');
|
|
}
|
|
string logCategory = "LogTraceType";
|
|
if (array.Length != 0)
|
|
{
|
|
logCategory = array[0].Trim();
|
|
}
|
|
string text = "All";
|
|
if (array.Length > 1)
|
|
{
|
|
text = array[1].Trim();
|
|
}
|
|
SetSourceLevel(text);
|
|
LoggingIdentity = Process.GetCurrentProcess().ProcessName;
|
|
string[] commandLineArgs = Environment.GetCommandLineArgs();
|
|
foreach (string text2 in commandLineArgs)
|
|
{
|
|
if (!text2.ToLower().StartsWith("/n"))
|
|
{
|
|
continue;
|
|
}
|
|
string text3 = text2.Substring(2).ToLower();
|
|
if (!text3.Contains("discovery"))
|
|
{
|
|
break;
|
|
}
|
|
if (text3.Contains("local"))
|
|
{
|
|
LoggingIdentity = "aaDiscoveryLocal";
|
|
}
|
|
else if (text3.Contains("global"))
|
|
{
|
|
if (text3.Contains("primary"))
|
|
{
|
|
LoggingIdentity = "aaDiscoveryPrimaryGlobal";
|
|
}
|
|
else if (text3.Contains("secondary"))
|
|
{
|
|
LoggingIdentity = "aaDiscoverySecondaryGlobal";
|
|
}
|
|
}
|
|
else if (text3.Contains("universal"))
|
|
{
|
|
if (text3.Contains("primary"))
|
|
{
|
|
LoggingIdentity = "aaDiscoveryPrimaryUniversal";
|
|
}
|
|
else if (text3.Contains("secondary"))
|
|
{
|
|
LoggingIdentity = "aaDiscoverySecondaryUniversal";
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
Logger.LogSetIdentityName(LoggingIdentity);
|
|
InitializeAdvanceLog();
|
|
IsCsvLogType = false;
|
|
SetLogCategory(logCategory);
|
|
}
|
|
|
|
public aaLoggerListner(string LogCategory, string LogIdentityName)
|
|
{
|
|
LoggingIdentity = LogIdentityName;
|
|
Logger.LogSetIdentityName(LoggingIdentity);
|
|
InitializeAdvanceLog();
|
|
IsCsvLogType = false;
|
|
SetLogCategory(LogCategory);
|
|
}
|
|
|
|
private void InitializeAdvanceLog()
|
|
{
|
|
if (!Directory.Exists(asbLogFolder))
|
|
{
|
|
Directory.CreateDirectory(asbLogFolder);
|
|
}
|
|
asbLogFile = asbLogFolder + Environment.MachineName + "_" + LoggingIdentity + ".log";
|
|
}
|
|
|
|
private void SetLogCategory(string LogCategory)
|
|
{
|
|
aaLogType loggerType = aaLogType.LogTraceType;
|
|
try
|
|
{
|
|
loggerType = (aaLogType)Enum.Parse(typeof(aaLogType), LogCategory);
|
|
IsCustomLogType = false;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
if (string.Compare(LogCategory, CSVLOGFLAG, ignoreCase: true) == 0)
|
|
{
|
|
IsCsvLogType = true;
|
|
}
|
|
else
|
|
{
|
|
CustomLogTypeCookie = Logger.LogRegisterCustomFlag(LogCategory);
|
|
}
|
|
IsCustomLogType = true;
|
|
}
|
|
LoggerType = loggerType;
|
|
}
|
|
|
|
private void SetSourceLevel(string level)
|
|
{
|
|
SourceLevels sourceLevels = SourceLevels.All;
|
|
try
|
|
{
|
|
sourceLevels = (SourceLevels)Enum.Parse(typeof(SourceLevels), level);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
sourceLevels = SourceLevels.All;
|
|
}
|
|
sourceLevel = sourceLevels;
|
|
}
|
|
|
|
public override void Write(string message)
|
|
{
|
|
LogIt(message, TraceEventType.Verbose);
|
|
}
|
|
|
|
public override void WriteLine(string message)
|
|
{
|
|
LogIt(message, TraceEventType.Verbose);
|
|
}
|
|
|
|
public override void WriteLine(string message, string category)
|
|
{
|
|
LogIt(message, TraceEventType.Verbose);
|
|
}
|
|
|
|
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
|
|
{
|
|
LogAdvancedFile(eventCache, source, eventType, message);
|
|
LogIt(message, eventType);
|
|
}
|
|
|
|
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
|
|
{
|
|
if (IsCsvLogType)
|
|
{
|
|
LogCsvFile(eventCache, source, eventType, id, format, args);
|
|
return;
|
|
}
|
|
string message = string.Format(CultureInfo.CurrentCulture, format, args);
|
|
LogAdvancedFile(eventCache, source, eventType, message);
|
|
LogIt(message, eventType);
|
|
}
|
|
|
|
private void LogIt(string message, TraceEventType eventType)
|
|
{
|
|
aaLogType aaLogType2 = LoggerType;
|
|
switch (eventType)
|
|
{
|
|
case TraceEventType.Warning:
|
|
aaLogType2 = aaLogType.LogWarningType;
|
|
break;
|
|
case TraceEventType.Error:
|
|
aaLogType2 = aaLogType.LogErrorType;
|
|
break;
|
|
case TraceEventType.Critical:
|
|
aaLogType2 = aaLogType.LogErrorType;
|
|
break;
|
|
}
|
|
if (!IsCustomLogType)
|
|
{
|
|
switch (aaLogType2)
|
|
{
|
|
case aaLogType.LogErrorType:
|
|
Logger.LogError(message);
|
|
break;
|
|
case aaLogType.LogWarningType:
|
|
Logger.LogWarning(message);
|
|
break;
|
|
case aaLogType.LogInfoType:
|
|
Logger.LogInfo(message);
|
|
break;
|
|
case aaLogType.LogTraceType:
|
|
Logger.LogTrace(message);
|
|
break;
|
|
case aaLogType.LogStartStopType:
|
|
Logger.LogStartStop(message);
|
|
break;
|
|
case aaLogType.LogThreadStartStopType:
|
|
Logger.LogThreadStartStop(message);
|
|
break;
|
|
case aaLogType.LogConnectionType:
|
|
Logger.LogConnection(message);
|
|
break;
|
|
case aaLogType.LogRefCountType:
|
|
Logger.LogRefCount(message);
|
|
break;
|
|
case aaLogType.LogCtorDtorType:
|
|
Logger.LogCtorDtor(message);
|
|
break;
|
|
case aaLogType.LogSQLType:
|
|
Logger.LogSQL(message);
|
|
break;
|
|
case aaLogType.LogEntryExitType:
|
|
Logger.LogEntryExit(message);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (aaLogType2)
|
|
{
|
|
case aaLogType.LogErrorType:
|
|
Logger.LogError(message);
|
|
break;
|
|
case aaLogType.LogWarningType:
|
|
Logger.LogWarning(message);
|
|
break;
|
|
default:
|
|
Logger.LogCustom(CustomLogTypeCookie, message);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LogCsvFile(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
|
|
{
|
|
string text = eventCache.DateTime.ToString("M/d/yyyy HH:mm:ss.fff") + "," + Environment.MachineName + "," + LoggingIdentity + "," + eventType.ToString() + "," + id + "," + eventCache.ProcessId + "," + eventCache.ThreadId.ToString() + "," + format;
|
|
foreach (object obj in args)
|
|
{
|
|
text = text + "," + obj.ToString();
|
|
}
|
|
string text2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ArchestrA\\LogFiles\\";
|
|
if (!Directory.Exists(text2))
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
lock (LogLockObject)
|
|
{
|
|
using StreamWriter streamWriter = File.AppendText(text2 + Environment.MachineName + "_" + LoggingIdentity + "_" + eventCache.ProcessId + ".csv");
|
|
streamWriter.WriteLine(text);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
public void LogAdvancedFile(TraceEventCache eventCache, string source, TraceEventType eventType, string message)
|
|
{
|
|
}
|
|
}
|