88
99using System ;
1010using System . Linq ;
11+ using System . Management ;
1112using SafeExamBrowser . Logging . Contracts ;
1213using SafeExamBrowser . Monitoring . Contracts ;
1314using SafeExamBrowser . SystemComponents . Contracts ;
@@ -41,6 +42,19 @@ public class VirtualMachineDetector : IVirtualMachineDetector
4142 "PROD_VIRTUAL_DVD"
4243 } ;
4344
45+ private static readonly string [ ] SystemHardware =
46+ {
47+ "CIM_Memory" ,
48+ "CIM_NumericSensor" ,
49+ "CIM_Sensor" ,
50+ "CIM_TemperatureSensor" ,
51+ "CIM_VoltageSensor" ,
52+ "Win32_CacheMemory" ,
53+ "Win32_Fan" ,
54+ "Win32_PerfFormattedData_Counters_ThermalZoneInformation" ,
55+ "Win32_VoltageProbe"
56+ } ;
57+
4458 private readonly ILogger logger ;
4559 private readonly IRegistry registry ;
4660 private readonly ISystemInfo systemInfo ;
@@ -56,6 +70,7 @@ public bool IsVirtualMachine()
5670 {
5771 var isVirtualMachine = false ;
5872
73+ isVirtualMachine |= HasNoSystemHardware ( ) ;
5974 isVirtualMachine |= HasVirtualDevice ( ) ;
6075 isVirtualMachine |= HasVirtualMacAddress ( ) ;
6176 isVirtualMachine |= IsVirtualCpu ( ) ;
@@ -67,6 +82,30 @@ public bool IsVirtualMachine()
6782 return isVirtualMachine ;
6883 }
6984
85+ private bool HasNoSystemHardware ( )
86+ {
87+ var hasHardware = false ;
88+
89+ try
90+ {
91+ foreach ( var hardware in SystemHardware )
92+ {
93+ using ( var searcher = new ManagementObjectSearcher ( $ "SELECT * FROM { hardware } ") )
94+ using ( var results = searcher . Get ( ) )
95+ {
96+ hasHardware |= results . Count > 0 ;
97+ }
98+ }
99+ }
100+ catch ( Exception e )
101+ {
102+ hasHardware = false ;
103+ logger . Error ( "Failed to query system hardware!" , e ) ;
104+ }
105+
106+ return ! hasHardware ;
107+ }
108+
70109 private bool HasVirtualDevice ( )
71110 {
72111 var hasVirtualDevice = false ;
0 commit comments