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>
151 lines
3.3 KiB
C#
151 lines
3.3 KiB
C#
#define TRACE
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.ServiceProcess;
|
|
using System.Timers;
|
|
|
|
namespace ArchestrAServices.Common;
|
|
|
|
public class WindowsServiceWatcher : IDisposable
|
|
{
|
|
private static readonly int TimerInterval = 5000;
|
|
|
|
private static readonly int LogWarningCount = 12;
|
|
|
|
private readonly string serviceName;
|
|
|
|
private bool disposed;
|
|
|
|
private Timer timer;
|
|
|
|
private int isOfflineCounter;
|
|
|
|
private bool lastIsRunningStatus;
|
|
|
|
private ServiceController serviceController;
|
|
|
|
public event EventHandler<WindowsServiceStatusChangedEventArgs> StatusChanged;
|
|
|
|
public WindowsServiceWatcher(string serviceName)
|
|
{
|
|
this.serviceName = serviceName;
|
|
timer = new Timer(TimerInterval);
|
|
timer.Elapsed += MonitorServiceStatus;
|
|
timer.Enabled = false;
|
|
timer.AutoReset = false;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
MonitorServiceStatus(null, null);
|
|
timer.Enabled = true;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
timer.Enabled = false;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (disposed)
|
|
{
|
|
return;
|
|
}
|
|
if (disposing)
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timer.Elapsed -= MonitorServiceStatus;
|
|
timer.Dispose();
|
|
timer = null;
|
|
}
|
|
if (serviceController != null)
|
|
{
|
|
serviceController.Dispose();
|
|
serviceController = null;
|
|
}
|
|
lastIsRunningStatus = false;
|
|
isOfflineCounter = 0;
|
|
}
|
|
disposed = true;
|
|
}
|
|
|
|
private void MonitorServiceStatus(object source, ElapsedEventArgs e)
|
|
{
|
|
bool flag = false;
|
|
bool flag2;
|
|
try
|
|
{
|
|
if (serviceController == null)
|
|
{
|
|
serviceController = new ServiceController(serviceName);
|
|
}
|
|
serviceController.Refresh();
|
|
flag2 = serviceController.Status == ServiceControllerStatus.Running;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
if (serviceController != null)
|
|
{
|
|
serviceController.Dispose();
|
|
serviceController = null;
|
|
}
|
|
flag2 = false;
|
|
flag = true;
|
|
}
|
|
if (flag2)
|
|
{
|
|
if (!lastIsRunningStatus)
|
|
{
|
|
SvcTrace.DiagControl.TraceEvent(TraceEventType.Information, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service is running.", new object[1] { serviceName }));
|
|
OnStatusChanged(new WindowsServiceStatusChangedEventArgs
|
|
{
|
|
IsRunning = true
|
|
});
|
|
lastIsRunningStatus = true;
|
|
isOfflineCounter = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (lastIsRunningStatus)
|
|
{
|
|
OnStatusChanged(new WindowsServiceStatusChangedEventArgs
|
|
{
|
|
IsRunning = false
|
|
});
|
|
lastIsRunningStatus = false;
|
|
}
|
|
isOfflineCounter++;
|
|
if (isOfflineCounter % LogWarningCount == 0)
|
|
{
|
|
if (flag)
|
|
{
|
|
SvcTrace.DiagControl.TraceEvent(TraceEventType.Error, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service does not exist. If this problem persists, please try installing the {0} windows service.", new object[1] { serviceName }));
|
|
}
|
|
else
|
|
{
|
|
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service is not running. If this problem persists, please try restarting the {0} windows service.", new object[1] { serviceName }));
|
|
}
|
|
}
|
|
}
|
|
timer.Enabled = true;
|
|
}
|
|
|
|
private void OnStatusChanged(WindowsServiceStatusChangedEventArgs newStatus)
|
|
{
|
|
if (this.StatusChanged != null)
|
|
{
|
|
this.StatusChanged(this, newStatus);
|
|
}
|
|
}
|
|
}
|