c++ - Why doesn't GCC compile this code? -
i java, python programmer trying fiddle c++. have following code snippet -
#include <windows.h> bool isinsidevmware() { bool rc = true; __try { __asm { push edx push ecx push ebx mov eax, 'vmxh' mov ebx, 0 // value not magic value mov ecx, 10 // vmware version mov edx, 'vx' // port number in eax, dx // read port // on return eax returns version cmp ebx, 'vmxh' // reply vmware? setz [rc] // set return value pop ebx pop ecx pop edx } } __except(exception_execute_handler) { rc = false; } return rc; }
i getting following compile error -
__try' undeclared (first use function)
__except' undeclared (first use function)
what vague message mean? because try undeclared should try use first??
edit:
ide - codeblocks
compiler - gcc
this code relies on microsoft specific functionality of __try
, __except
. there no other way solve this, doing in
instruction user-mode process in windows fail. in vmware, such operation intercepted vmware vmm (virtual machine monitor, called hypervisor). checks special values in registers , "accepts" instruction new value in ebx
indicate "yes, i'm vmware system". if run on plain old windows system, general protection fault trying use io-port isn't available application [in general, io ports aren't availbe user-mode application code].
you need compile using microsoft compiler (and suitable "enable exception handling" flag set - sorry, can't remember flag is, tell if it's not on it's wrong). gcc doesn't support feature.
however, can test vmware using cpuid instruction instead of using in
. work better in gcc compiler, not fault processor if there no vm present [for pedants: long processor later version of 486 1990's]. instead, not give right values in registers (no change register values). may need write cpuid
inline assembler function, shouldn't difficult google up.
see kb-article on vmwares site: http://kb.vmware.com/selfservice/microsites/search.do?language=en_us&cmd=displaykc&externalid=1009458
alternatively, if insist on using windows structured exception handling, can yourself:
push handler // save address of handler. push fs:[0] // save address of previous handler mov fs:[0], esp // save pointer current exception record. ... // stuff setting registers, doing in, etc. jmp cleanup handler: mov [rc], 0 // set "rc= false". cleanup: pop fs:[0] add esp, 4 // remove handler
(note, wrote bit of googling - it's long time since used on windows, may not work)
Comments
Post a Comment