diff --git a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs index 6ee34b08..e83e32e1 100644 --- a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs +++ b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs @@ -44,13 +44,13 @@ namespace SafeExamBrowser.SystemComponents.Contracts string OperatingSystemInfo { get; } /// - /// The MAC Addres of the network addapter + /// The MAC address of the network adapter /// string MacAddress { get; } /// /// Provides the DeviceID information of the user's Plug and Play devices /// - string[] DeviceId { get; } + string[] PlugAndPlayDeviceIds { get; } } } diff --git a/SafeExamBrowser.SystemComponents/SystemInfo.cs b/SafeExamBrowser.SystemComponents/SystemInfo.cs index 102d66bf..3eb62c72 100644 --- a/SafeExamBrowser.SystemComponents/SystemInfo.cs +++ b/SafeExamBrowser.SystemComponents/SystemInfo.cs @@ -25,7 +25,7 @@ namespace SafeExamBrowser.SystemComponents public string Name { get; private set; } public OperatingSystem OperatingSystem { get; private set; } public string MacAddress { get; private set; } - public string[] DeviceId { get; private set; } + public string[] PlugAndPlayDeviceIds { get; private set; } public string OperatingSystemInfo { @@ -133,16 +133,18 @@ namespace SafeExamBrowser.SystemComponents { return Environment.Is64BitOperatingSystem ? "x64" : "x86"; } + private void InitializeMacAddress() { using (var searcher = new ManagementObjectSearcher("Select MACAddress from Win32_NetworkAdapterConfiguration WHERE DNSDomain IS NOT NULL")) using (var results = searcher.Get()) { - if (results.Count > 0) + + if (results != null && results.Count > 0) { - using (var system = results.Cast().First()) + using (var networkAdapter = results.Cast().First()) { - foreach (var property in system.Properties) + foreach (var property in networkAdapter.Properties) { if (property.Name.Equals("MACAddress")) @@ -158,25 +160,27 @@ namespace SafeExamBrowser.SystemComponents } } } + private void InitializePnPDevices() { - List deviceList = new List(); + var deviceList = new List(); using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT DeviceID FROM Win32_PnPEntity")) using (var results = searcher.Get()) { foreach (ManagementObject queryObj in results) { - using (queryObj) + using (queryObj) + { foreach (var property in queryObj.Properties) { if (property.Name.Equals("DeviceID")) { - Console.WriteLine(Convert.ToString(property.Value)); deviceList.Add(Convert.ToString(property.Value).ToLower()); } } + } } - DeviceId = deviceList.ToArray(); + PlugAndPlayDeviceIds = deviceList.ToArray(); } } diff --git a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs index 78201332..35c1319a 100644 --- a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs +++ b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs @@ -32,21 +32,25 @@ namespace SafeExamBrowser.SystemComponents var manufacturer = systemInfo.Manufacturer.ToLower(); var model = systemInfo.Model.ToLower(); var macAddress = systemInfo.MacAddress; - var deviceId = systemInfo.DeviceId; - + var plugAndPlayDeviceIds = systemInfo.PlugAndPlayDeviceIds; + isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface"); isVirtualMachine |= manufacturer.Contains("vmware"); isVirtualMachine |= manufacturer.Contains("parallels software"); isVirtualMachine |= model.Contains("virtualbox"); isVirtualMachine |= manufacturer.Contains("qemu"); - - isVirtualMachine |= ((byte.Parse(macAddress[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddress.StartsWith("080027")); - - foreach (var device in deviceId) + + if (macAddress != null && macAddress.Count() > 2) + { + isVirtualMachine |= ((byte.Parse(macAddress[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddress.StartsWith("080027")); + } + + foreach (var device in plugAndPlayDeviceIds) { isVirtualMachine |= PCI_VENDOR_BLACKLIST.Any(device.ToLower().Contains); } + logger.Debug($"Computer '{systemInfo.Name}' appears to {(isVirtualMachine ? "" : "not ")}be a virtual machine."); return isVirtualMachine;