Code cleanup.
This commit is contained in:
parent
bd5eab03a1
commit
ae7dcc0b0b
4 changed files with 14 additions and 13 deletions
|
@ -136,17 +136,15 @@ namespace SafeExamBrowser.SystemComponents
|
|||
|
||||
private void InitializeMacAddress()
|
||||
{
|
||||
using (var searcher = new ManagementObjectSearcher("Select MACAddress from Win32_NetworkAdapterConfiguration WHERE DNSDomain IS NOT NULL"))
|
||||
using (var searcher = new ManagementObjectSearcher("SELECT MACAddress FROM Win32_NetworkAdapterConfiguration WHERE DNSDomain IS NOT NULL"))
|
||||
using (var results = searcher.Get())
|
||||
{
|
||||
|
||||
if (results != null && results.Count > 0)
|
||||
{
|
||||
using (var networkAdapter = results.Cast<ManagementObject>().First())
|
||||
{
|
||||
foreach (var property in networkAdapter.Properties)
|
||||
{
|
||||
|
||||
if (property.Name.Equals("MACAddress"))
|
||||
{
|
||||
MacAddress = Convert.ToString(property.Value).Replace(":", "").ToUpper();
|
||||
|
@ -164,6 +162,7 @@ namespace SafeExamBrowser.SystemComponents
|
|||
private void InitializePnPDevices()
|
||||
{
|
||||
var deviceList = new List<string>();
|
||||
|
||||
using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT DeviceID FROM Win32_PnPEntity"))
|
||||
using (var results = searcher.Get())
|
||||
{
|
||||
|
@ -180,8 +179,8 @@ namespace SafeExamBrowser.SystemComponents
|
|||
}
|
||||
}
|
||||
}
|
||||
PlugAndPlayDeviceIds = deviceList.ToArray();
|
||||
|
||||
PlugAndPlayDeviceIds = deviceList.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,16 +6,19 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.SystemComponents.Contracts;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace SafeExamBrowser.SystemComponents
|
||||
{
|
||||
public class VirtualMachineDetector : IVirtualMachineDetector
|
||||
{
|
||||
private static readonly string[] PCI_VENDOR_BLACKLIST = { "vbox", "vid_80ee", "qemu", "ven_1af4", "ven_1b36", "subsys_11001af4" }; //Virtualbox: VBOX, 80EE RedHat: QUEMU, 1AF4, 1B36
|
||||
/// <summary>
|
||||
/// Virtualbox: VBOX, 80EE
|
||||
/// RedHat: QUEMU, 1AF4, 1B36
|
||||
/// </summary>
|
||||
private static readonly string[] PCI_VENDOR_BLACKLIST = { "vbox", "vid_80ee", "qemu", "ven_1af4", "ven_1b36", "subsys_11001af4" };
|
||||
private static readonly string VIRTUALBOX_MAC_PREFIX = "080027";
|
||||
private static readonly string QEMU_MAC_PREFIX = "525400";
|
||||
|
||||
|
@ -44,13 +47,12 @@ namespace SafeExamBrowser.SystemComponents
|
|||
|
||||
if (macAddress != null && macAddress.Count() > 2)
|
||||
{
|
||||
isVirtualMachine |= (macAddress.StartsWith(QEMU_MAC_PREFIX) || macAddress.StartsWith(VIRTUALBOX_MAC_PREFIX));
|
||||
isVirtualMachine |= macAddress.StartsWith(QEMU_MAC_PREFIX) || macAddress.StartsWith(VIRTUALBOX_MAC_PREFIX);
|
||||
}
|
||||
|
||||
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.");
|
||||
|
|
|
@ -292,11 +292,11 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows
|
|||
private DriveInfo[] GetDrives()
|
||||
{
|
||||
var drives = DriveInfo.GetDrives();
|
||||
int noDrives = (int)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
|
||||
var noDrives = (int) Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
|
||||
|
||||
if (noDrives > 0)
|
||||
{
|
||||
return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(drive.RootDirectory.ToString()[0]) - 65))) == 0).ToArray();
|
||||
return drives.Where(drive => (noDrives & (int) Math.Pow(2, drive.RootDirectory.ToString()[0] - 65)) == 0).ToArray();
|
||||
}
|
||||
|
||||
return drives;
|
||||
|
|
|
@ -292,11 +292,11 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows
|
|||
private DriveInfo[] GetDrives()
|
||||
{
|
||||
var drives = DriveInfo.GetDrives();
|
||||
int noDrives = (int)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
|
||||
var noDrives = (int) Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
|
||||
|
||||
if (noDrives > 0)
|
||||
{
|
||||
return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(drive.RootDirectory.ToString()[0]) - 65))) == 0).ToArray();
|
||||
return drives.Where(drive => (noDrives & (int) Math.Pow(2, drive.RootDirectory.ToString()[0] - 65)) == 0).ToArray();
|
||||
}
|
||||
|
||||
return drives;
|
||||
|
|
Loading…
Reference in a new issue