Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://waleedassar.blogspot.com
- //http://www.twitter.com/waleedassar
- //CPUID detects a supported SYSENTER/SYSEXIT even if they are not. This can be used to detect VirtualBox if Intel-VTx/AMD-V is disabled.
- #include "stdafx.h"
- #include "windows.h"
- #include "stdio.h"
- struct OSVERSIONINFOEx_
- {
- unsigned long dwOSVersionInfoSize;
- unsigned long dwMajorVersion;
- unsigned long dwMinorVersion;
- unsigned long dwBuildNumber;
- unsigned long dwPlatformId;
- unsigned char szCSDVersion[128];
- unsigned short wServicePackMajor;
- unsigned short wServicePackMinor;
- unsigned short wSuiteMask;
- unsigned char wProductType;
- unsigned char wReserved;
- };
- //-----------------------------------------------
- bool IsCPUID_Supported()
- {
- unsigned long x=0;
- __asm
- {
- pushad
- pushfd
- pop eax
- or eax,0x00200000
- push eax
- popfd
- pushfd
- pop eax
- and eax,0x00200000
- jz CPUID_NOT_SUPPORTED ;Are you still alive?
- mov x,1
- jmp bye
- CPUID_NOT_SUPPORTED:
- mov x,0
- bye:
- popad
- }
- return(x?true:false);
- }
- bool CPUID_Sep()
- {
- bool sep=false;
- if(IsCPUID_Supported())
- {
- __asm
- {
- xor eax,eax
- inc eax
- cpuid
- test edx,0x800
- jz No_Sysenter
- mov sep,1
- jmp end
- No_Sysenter:
- mov sep,0
- end:
- nop
- }
- }
- return sep;
- }
- int __cdecl Handler(EXCEPTION_RECORD* pRec,void*,unsigned char* pContext,void*)
- {
- if(pRec->ExceptionCode==0xC000001D) //Illegal instruction
- {
- if(CPUID_Sep())
- {
- MessageBox(0,"VirtualBox detected!","waliedassar",0);
- ExitProcess(0);
- }
- }
- (*(unsigned long*)(pContext+0xB8))+=2;
- return ExceptionContinueExecution;
- }
- void Test()
- {
- __asm
- {
- push offset Handler
- push dword ptr fs:[0x0]
- mov dword ptr fs:[0x0],esp
- push 0
- push 0
- push esp
- push 0
- call A
- jmp end
- A:
- mov eax,0x3B
- call here
- jmp end
- here:
- mov edx,esp
- __emit 0x0F
- __emit 0x34
- end:
- }
- MessageBox(0,"Expected behavior","waliedassar",0);
- ExitProcess(0);
- }
- int main(int argc, char* argv[])
- {
- OSVERSIONINFOEx_ OSI={sizeof(OSI)};
- GetVersionEx((LPOSVERSIONINFO)&OSI);
- if(OSI.dwMajorVersion==0x5 && OSI.dwMinorVersion==0x1)
- {
- if(OSI.wServicePackMajor==0x2 || OSI.wServicePackMajor==0x3) //SP2 or SP3
- Test();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement