From b8e43f2aff9974efab1b02b5a58bc4cbccacf927 Mon Sep 17 00:00:00 2001 From: Jacob Weisz Date: Tue, 9 Jul 2024 09:48:35 -0500 Subject: [PATCH] Preliminary system data collection --- XRFAgent.csproj | 1 + modCommand.cs | 3 ++- modSystem.cs | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/XRFAgent.csproj b/XRFAgent.csproj index 1f3bfb4..d32fbf2 100644 --- a/XRFAgent.csproj +++ b/XRFAgent.csproj @@ -54,6 +54,7 @@ + diff --git a/modCommand.cs b/modCommand.cs index 4f533c2..9659eb6 100644 --- a/modCommand.cs +++ b/modCommand.cs @@ -27,7 +27,8 @@ public static void Handle(string inputCommand, string inputSource, string reques switch (inputData[0]) { case "check" when inputData.Length == 3: - if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.GetInstalledSoftware(); } break; + if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.GetInstalledSoftware(); } + else if (inputData[1] == "system" && inputData[2] == "details") { outputResponse = modSystem.GetSystemDetails(); } break; case "hac": case "hacontroller": string inputCommandTrimmed = inputCommand.Remove(0, inputData[0].Length + 1); diff --git a/modSystem.cs b/modSystem.cs index 70a2915..86c3468 100644 --- a/modSystem.cs +++ b/modSystem.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text.Json; +using Microsoft.VisualBasic.Devices; using Microsoft.Win32; namespace XRFAgent @@ -83,6 +84,44 @@ public static string ResetInstalledSoftware() return GetInstalledSoftware(); } + /// + /// Collects some general system information + /// + /// (string) Result + public static string GetSystemDetails() + { + try + { + RegistryKey systemHardware = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\BIOS"); + string moboManufacturer = systemHardware.GetValue("BaseBoardManufacturer").ToString(); + modLogging.LogEvent("Mobo Manufacturer: " + moboManufacturer, EventLogEntryType.Information, 9999); + string moboProduct = systemHardware.GetValue("BaseBoardProduct").ToString(); + modLogging.LogEvent("Mobo Product: " + moboProduct, EventLogEntryType.Information, 9999); + string compManufacturer = systemHardware.GetValue("SystemManufacturer").ToString(); + modLogging.LogEvent("CSys Manufacturer: " + compManufacturer, EventLogEntryType.Information, 9999); + string compModel = systemHardware.GetValue("SystemProductName").ToString(); + modLogging.LogEvent("CSys Model: " + compModel, EventLogEntryType.Information, 9999); + + RegistryKey systemCPU = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0"); + string processorName = systemCPU.GetValue("ProcessorNameString").ToString(); + modLogging.LogEvent("Proc Name: " + processorName, EventLogEntryType.Information, 9999); + ComputerInfo VBCI = new ComputerInfo(); + string physicalMemory = VBCI.TotalPhysicalMemory.ToString(); + modLogging.LogEvent("Phys Memory: " + physicalMemory, EventLogEntryType.Information, 9999); + + string machineName = Environment.MachineName.ToString(); + int uptimeMilliseconds = Environment.TickCount; + string logicalDrives = String.Join(", ", Environment.GetLogicalDrives()).TrimEnd(',', ' '); + + return "System details in event log"; + } + catch (Exception err) + { + modLogging.LogEvent("Unable to get registry information: " + err.Message + "\n\n" + err.StackTrace, EventLogEntryType.Error, 6032); + return "Registry error"; + } + } + /// /// Gets a full Windows build number from the registry ///