Merge pull request #634 from Notselwyn/ProxmoxVMDetection
Extended ISystemInfo with CPU and removed unnecessary (debug) …
This commit is contained in:
commit
fcebf4b436
4 changed files with 27 additions and 8 deletions
|
@ -13,11 +13,17 @@ namespace SafeExamBrowser.SystemComponents.Contracts
|
|||
/// </summary>
|
||||
public interface ISystemInfo
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The manufacturer and name of the BIOS.
|
||||
/// </summary>
|
||||
string BiosInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the CPU.
|
||||
/// </summary>
|
||||
string Cpu { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Reveals whether the computer system contains a battery.
|
||||
/// </summary>
|
||||
|
|
|
@ -229,7 +229,6 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
|
||||
try
|
||||
{
|
||||
logger.Info($"default(RegistryKey) == null: {key == null}");
|
||||
if (TryGetBaseKeyFromKeyName(keyName, out var baseKey, out var subKey))
|
||||
{
|
||||
key = baseKey.OpenSubKey(subKey);
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace SafeExamBrowser.SystemComponents
|
|||
public class SystemInfo : ISystemInfo
|
||||
{
|
||||
public string BiosInfo { get; private set; }
|
||||
public string Cpu { get; private set; }
|
||||
public bool HasBattery { get; private set; }
|
||||
public string MacAddress { get; private set; }
|
||||
public string Manufacturer { get; private set; }
|
||||
|
@ -33,6 +34,7 @@ namespace SafeExamBrowser.SystemComponents
|
|||
{
|
||||
InitializeBattery();
|
||||
InitializeBiosInfo();
|
||||
InitializeCpu();
|
||||
InitializeMacAddress();
|
||||
InitializeMachineInfo();
|
||||
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()
|
||||
{
|
||||
var model = default(string);
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace SafeExamBrowser.SystemComponents
|
|||
|
||||
// redundancy: registry check does this aswell (systemInfo may be using different methods)
|
||||
isVirtualMachine |= IsVirtualSystemInfo(biosInfo, manufacturer, model);
|
||||
isVirtualMachine |= IsVirtualWmi();
|
||||
isVirtualMachine |= IsVirtualCpu();
|
||||
isVirtualMachine |= IsVirtualRegistry();
|
||||
|
||||
if (macAddress != null && macAddress.Count() > 2)
|
||||
|
@ -222,15 +222,11 @@ namespace SafeExamBrowser.SystemComponents
|
|||
return isVirtualMachine;
|
||||
}
|
||||
|
||||
private bool IsVirtualWmi()
|
||||
private bool IsVirtualCpu()
|
||||
{
|
||||
var isVirtualMachine = false;
|
||||
var cpuObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
|
||||
|
||||
foreach (var cpuObj in cpuObjSearcher.Get())
|
||||
{
|
||||
isVirtualMachine |= ((string) cpuObj["Name"]).ToLower().Contains(" kvm "); // qemu (KVM specifically)
|
||||
}
|
||||
isVirtualMachine |= systemInfo.Cpu.ToLower().Contains(" kvm "); // qemu (KVM specifically)
|
||||
|
||||
return isVirtualMachine;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue