Gabriele Contini
2020-02-24 9afdac17dcc8956fd795797bfc5b6e1c09285342
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
#include "intrin.h"
 
#include <iostream>
#include "BIOSReader.h"
#include "Native.h"
 
int _tmain(int argc, _TCHAR* argv[])
{
    int cpui[4] = { 0 };
    __cpuid(cpui, 0x1);
 
    if ((cpui[2] >> 31) & 1)
    {
        std::cout << "Inside virual machine!";
        return 1;
    }
 
    if (InitEntryPoints())
    {
        BIOSReader reader;
        SystemInformation info = reader.readSystemInfo();
 
        const char *vmVendors[] =
        {
            "VMware", "Microsoft Corporation", "Virtual Machine", "innotek GmbH", "PowerVM", "Bochs", "KVM"
        };
 
        const int count = _countof(vmVendors);
        for (int i = 0; i != count; ++i)
        {
            const char *vendor = vmVendors[i];
 
            if (std::string::npos != info.Manufacturer.find(vendor) ||
                std::string::npos != info.ProductName.find(vendor) ||
                std::string::npos != info.SerialNum.find(vendor))
            {
                std::cout << "Inside virual machine!";
                return 1;
            }
        }
    }
    else
    {
        return -1;
    }
 
    std::cout << "Inside host machine!";
 
    return 0;
}