File: hyperv.c

package info (click to toggle)
imvirt 0.9.6-13
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,364 kB
  • sloc: perl: 2,778; sh: 802; ansic: 316; makefile: 61
file content (50 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (6)
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
/* imvirt / HyperV detection code
 *
 * Authors:
 *   Thomas Liske <liske@ibh.de>
 *
 * Copyright Holder:
 *   2009 - 2012 (C) IBH IT-Service GmbH [http://www.ibh.de/]
 *
 * License:
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this package; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "detect.h"

int main(int argc, char **argv) {
    helper_main(argc, argv);

    uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
    char signature[13];

    CPUID(0x40000000, eax, ebx, ecx, edx);
    memcpy(&signature[0], &ebx, 4);
    memcpy(&signature[4], &ecx, 4);
    memcpy(&signature[8], &edx, 4);
    signature[12] = 0;

    if(!strcmp(signature, "Microsoft Hv")) {
	printf("Virtual Machine\n");
	return 1;
    }

    return 0;
}