#include "windows.h"
DWORD __forceinline IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS ep);
bool IsInsideVPC();
bool IsInsideVMWare();
int CheckVPC();
int CheckVPC()
{
if (IsInsideVPC())
MessageBox(NULL, L"你在虚拟电脑Microsoft Virtual PC中!", L"提示", MB_OK | MB_ICONINFORMATION);
else if (IsInsideVMWare())
MessageBox(NULL, L"你在虚拟电脑VMWare中!", L"提示", MB_OK | MB_ICONINFORMATION);
else
MessageBox(NULL, L"你在真实的电脑中!", L"提示", MB_OK | MB_ICONINFORMATION);
return 0;
}
DWORD __forceinline IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS ep)
{
CONTEXT* ctx = ep->ContextRecord;
ctx->Ebx = -1;
ctx->Eip += 4;
return EXCEPTION_CONTINUE_EXECUTION;
}
bool IsInsideVPC()
{
bool rc = false;
__try
{
_asm push ebx
_asm mov ebx, 0 // It will stay ZERO if VPC is running
_asm mov eax, 1 // VPC function number
_asm __emit 0Fh
_asm __emit 3Fh
_asm __emit 07h
_asm __emit 0Bh
_asm test ebx, ebx
_asm setz[rc]
_asm pop ebx
}
// The except block shouldn't get triggered if VPC is running!!
__except (IsInsideVPC_exceptionFilter(GetExceptionInformation()))
{
}
return rc;
}
bool IsInsideVMWare()
{
bool rc = true;
__try
{
__asm
{
push edx
push ecx
push ebx
mov eax, 'VMXh'
mov ebx, 0
mov ecx, 10
mov edx, 'VX'
in eax, dx
cmp ebx, 'VMXh'
setz[rc]
pop ebx
pop ecx
pop edx
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
rc = false;
}
return rc;
}
int main()
{
return CheckVPC();
return 0;
}
检测程序是否处在虚拟机中
最新推荐文章于 2024-08-08 17:12:48 发布