How to detect if a PB program is running inside a VM

Just starting out? Need help? Post your questions and find answers here.
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

How to detect if a PB program is running inside a VM

Post by glomph »

Happy new year to all.

It is possible to detect if a PB program is running inside a Virtual Machine.

Saw same stuff here:
http://www.codeproject.com/Articles/982 ... -a-Virtual

Unfortunately I'm not able to translate that code into PB.
Maybe someone has tried something like this and could help.

Glomph
User avatar
idle
Always Here
Always Here
Posts: 5925
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How to detect if a PB program is running inside a VM

Post by idle »

you should be able to use cpuid info with the flag #hypervisor but you may still need to do additional checks.

see here http://www.purebasic.fr/english/viewtop ... 12&t=61060

and use IsCPU(#hypervisor)
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: How to detect if a PB program is running inside a VM

Post by glomph »

Thank you very much Idle

That's a start!

Glomph
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: How to detect if a PB program is running inside a VM

Post by glomph »

....and even more fine:
It works on MAC too.
:D
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: How to detect if a PB program is running inside a VM

Post by jassing »

I worked on a project that had to refuse to run on a VM. we found using the ID of the NIC a good way; ultimately we used a NIC database and a CPU check as backup/secondary -- sometimes the CPU check was passed to the host OS, so you didn't get the right value...
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: How to detect if a PB program is running inside a VM

Post by glomph »

@ jassing,
thanks you for your advice.

Surely you point the right direction.

Never before I had to look a NIC,
so I nead a little more help,
to get through.

Have all a nice day
Glomph
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: How to detect if a PB program is running inside a VM

Post by jassing »

Getting the NIC information should be trivial -- and I'm sure there are code samples/examples on these forums.
Now the list of NIC info... that's a different story... It wasn't an exhaustive list, but we did sample all the "free" VM's, VMWare, Microsofts, and a few other that had trials...
I no longer work on that project, but I will see if I have the list in my personal archives....

We had to do multiple checks as each VM seemed to offer it's own unique issues that would fail some "generic" test...
Post Reply