检查操作系统是否跑在VMare

/ns/wz/sys/data/20020813021543.htm

检查操作系统是否跑在VMare

Author: alert7
Email: alert7@whitecell.org
Homepage:http://www.whitecell.org


/*
* gcc -Wall -o checkVM checkVM.c
* check linux OS in VMare ?
* by alert7
*
*/

#include <stdio.h>
#include <stdlib.h>

struct idtr {
unsigned short limit;
unsigned int base;
} __attribute__ ((packed));

unsigned int get_addr_idt() {
struct idtr idtr;
asm("sidt %0" : "=m" (idtr));
return idtr.base;
}
int main(int argc, char ** argv)
{
unsigned int ptr_idt;

ptr_idt=get_addr_idt();
printf("IDT Addr %p \n",ptr_idt);
if ( (ptr_idt>>24)==0xc0)
printf("Real Linux\n");
else printf("Maybe in VMare\n");
return 0;
}