-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathisvm.c
38 lines (31 loc) · 909 Bytes
/
isvm.c
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
// source: https://www.pelock.com/articles/anti-reverse-engineering-malware-vs-antivirus-software
// some changes needed ;)
// tested with vmware workstation & virtualbox
#include <windows.h>
#include <stdio.h>
BOOL IsVM()
{
HKEY hKey;
int i;
char szBuffer[1024];
char *szProducts[] = { "VMWARE", "VBOX", "VIRTUAL", "VMware" };
DWORD dwSize = sizeof(szBuffer) - 1;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Services\\Disk\\Enum", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
RegQueryValueEx(hKey, "0", NULL, NULL, (unsigned char *)szBuffer, &dwSize );
for (i = 0; i < _countof(szProducts); i++)
{
if (strstr(szBuffer, szProducts[i]))
{
RegCloseKey(hKey);
return TRUE;
}
}
RegCloseKey(hKey);
}
return FALSE;
}
int main(void)
{
printf("isvm: %d\n",IsVM());
}