Merge pull request #634 from Notselwyn/ProxmoxVMDetection

Extended ISystemInfo with CPU and removed unnecessary (debug) …
This commit is contained in:
Damian Büchel 2023-07-28 16:26:26 +02:00 committed by GitHub
commit fcebf4b436
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 8 deletions

View file

@ -13,11 +13,17 @@ namespace SafeExamBrowser.SystemComponents.Contracts
/// </summary> /// </summary>
public interface ISystemInfo public interface ISystemInfo
{ {
/// <summary> /// <summary>
/// The manufacturer and name of the BIOS. /// The manufacturer and name of the BIOS.
/// </summary> /// </summary>
string BiosInfo { get; } string BiosInfo { get; }
/// <summary>
/// The name of the CPU.
/// </summary>
string Cpu { get; }
/// <summary> /// <summary>
/// Reveals whether the computer system contains a battery. /// Reveals whether the computer system contains a battery.
/// </summary> /// </summary>

View file

@ -229,7 +229,6 @@ namespace SafeExamBrowser.SystemComponents.Registry
try try
{ {
logger.Info($"default(RegistryKey) == null: {key == null}");
if (TryGetBaseKeyFromKeyName(keyName, out var baseKey, out var subKey)) if (TryGetBaseKeyFromKeyName(keyName, out var baseKey, out var subKey))
{ {
key = baseKey.OpenSubKey(subKey); key = baseKey.OpenSubKey(subKey);

View file

@ -20,6 +20,7 @@ namespace SafeExamBrowser.SystemComponents
public class SystemInfo : ISystemInfo public class SystemInfo : ISystemInfo
{ {
public string BiosInfo { get; private set; } public string BiosInfo { get; private set; }
public string Cpu { get; private set; }
public bool HasBattery { get; private set; } public bool HasBattery { get; private set; }
public string MacAddress { get; private set; } public string MacAddress { get; private set; }
public string Manufacturer { get; private set; } public string Manufacturer { get; private set; }
@ -33,6 +34,7 @@ namespace SafeExamBrowser.SystemComponents
{ {
InitializeBattery(); InitializeBattery();
InitializeBiosInfo(); InitializeBiosInfo();
InitializeCpu();
InitializeMacAddress(); InitializeMacAddress();
InitializeMachineInfo(); InitializeMachineInfo();
InitializeOperatingSystem(); InitializeOperatingSystem();
@ -79,6 +81,22 @@ namespace SafeExamBrowser.SystemComponents
} }
} }
private void InitializeCpu()
{
try
{
var cpuObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
foreach (var cpuObj in cpuObjSearcher.Get())
{
Cpu = ((string) cpuObj["Name"]);
}
}
catch (Exception)
{
Cpu = "";
}
}
private void InitializeMachineInfo() private void InitializeMachineInfo()
{ {
var model = default(string); var model = default(string);

View file

@ -66,7 +66,7 @@ namespace SafeExamBrowser.SystemComponents
// redundancy: registry check does this aswell (systemInfo may be using different methods) // redundancy: registry check does this aswell (systemInfo may be using different methods)
isVirtualMachine |= IsVirtualSystemInfo(biosInfo, manufacturer, model); isVirtualMachine |= IsVirtualSystemInfo(biosInfo, manufacturer, model);
isVirtualMachine |= IsVirtualWmi(); isVirtualMachine |= IsVirtualCpu();
isVirtualMachine |= IsVirtualRegistry(); isVirtualMachine |= IsVirtualRegistry();
if (macAddress != null && macAddress.Count() > 2) if (macAddress != null && macAddress.Count() > 2)
@ -222,15 +222,11 @@ namespace SafeExamBrowser.SystemComponents
return isVirtualMachine; return isVirtualMachine;
} }
private bool IsVirtualWmi() private bool IsVirtualCpu()
{ {
var isVirtualMachine = false; var isVirtualMachine = false;
var cpuObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
foreach (var cpuObj in cpuObjSearcher.Get()) isVirtualMachine |= systemInfo.Cpu.ToLower().Contains(" kvm "); // qemu (KVM specifically)
{
isVirtualMachine |= ((string) cpuObj["Name"]).ToLower().Contains(" kvm "); // qemu (KVM specifically)
}
return isVirtualMachine; return isVirtualMachine;
} }