-
Notifications
You must be signed in to change notification settings - Fork 0
/
AntiEmulatorVM.cs
75 lines (67 loc) · 2.52 KB
/
AntiEmulatorVM.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Management;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ArtemisSecurity
{
public static class AntiEmulatorVM
{
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsDebuggerPresent();
public static void DetectEmulatorOrVM()
{
if (IsRunningInVM() || IsRunningInEmulator() || IsDebuggerAttached())
{
Console.WriteLine("VM, Emulator, or Debugger detected! Terminating...");
Environment.Exit(-1);
}
}
private static bool IsRunningInVM()
{
using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
{
foreach (var item in searcher.Get())
{
string manufacturer = item["Manufacturer"].ToString().ToLower();
string model = item["Model"].ToString().ToUpperInvariant();
if ((manufacturer == "microsoft corporation" && model.Contains("VIRTUAL")) ||
manufacturer.Contains("vmware") ||
manufacturer.Contains("xen") ||
manufacturer.Contains("virtualbox") ||
manufacturer.Contains("qemu"))
{
return true;
}
}
}
return false;
}
private static bool IsRunningInEmulator()
{
// Check for common emulator-specific environment variables
string[] emulatorEnvVars = { "ANDROID_EMULATOR_HYPERVISOR", "QEMU_AUDIO_DRV", "QEMU" };
foreach (var envVar in emulatorEnvVars)
{
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envVar)))
{
return true;
}
}
// Check for emulator-specific processes
string[] emulatorProcesses = { "qemu-system", "windroy", "nox" };
foreach (var processName in emulatorProcesses)
{
if (Process.GetProcessesByName(processName).Length > 0)
{
return true;
}
}
return false;
}
private static bool IsDebuggerAttached()
{
return IsDebuggerPresent() || Debugger.IsAttached;
}
}
}