Visual C++

EN NL TR

The previous program

Home

The next program

How to detect Virtual PC or VMWare from your program

Detecting VMWare

The method to detect VMWare is well documented on the internet.  It's pretty easy actually, you put value 10 (0x0A) in the ECX register and you put the magic value of 0x564D5868 in the EAX register.  Then you read a dword from port 0x5658.

It can only be done in assembler and it's done like this :

If VMWare is installed than this code will be executed correctly and the EBX register will contain the same magic value of 0x564D5868.  If VMWare is not installed than on Linux and Windows NT an exception will occur because these operating systems don't allow direct port access.  In DOS and Windows the read will succeed but EBX will remain unchanged.

This results in the following semi-C++ function (compatible with both Windows 9x and NT+) :

 

Detecting Virtual PC

There are two ways to detect Microsoft's Virtual PC.  Note: the methods described below have only been tested with Microsoft Virtual PC 2004 Trial.

Microsoft delivers add-on tools for enabling extra features on the Virtual PC.  These add-on tools fail to install on a read processor, this comes because Microsoft has put a DLL named vmcheck.dll within the installation file.  This DLL is placed in your TEMP-directory during the installation process.  This DLL exports a single function with the name "IsRunningInsideVirtualMachine".

Here I present a function that detects Virtual PC using this DLL, the DLL is loaded dynamicly so the program will start even if DLL isn't available :

If you don't want to use this DLL than you can use the code below (tested only with Microsoft Virtual PC 2004 Trial).  This assembler code doesn't make much sense on a real-processor, so it will crash programs not running inside Virtual PC :

 

Demo program

I've created a small test project for the routines showed above (with source code publicly available).  As an extra, the program will also detect if you are running this 32-bit program under a 64-bit version of Windows.  Here's a screenshot of it running on a real processor using the Evaluation Edition of Windows XP 64-Bit Edition :


 

Download

You can download a project showing the detection methods described above here (compressed ZIP files) :

The source code of Host Detection 3
The executable version of Host Detection 3

If you use this code, please acknowledge me by putting a link inside your code to this page, thank you!

NOTE: All the required files are included in the source code file in order to compile succesfully
 

Contact

If you have questions or remarks about this article or its contents, then feel free to contact me at <fibergeek @ codegurus.be>.  Don't forget to remove the white spaces or the e-mail won't arrive.

Also, the demo code contains a function IsSomethingUnknown( ), if you are able to execute this routine successfully, please contact me and let me know what kind of emulator you were using.

 

External links

VMWare
Virtual PC

 

The previous program

Home

The next program