[英]Can I determine whether the OS is run in a virtual machine in cocoa?
Maybe this is a cross-system issue, and maybe not. 也许这是一个跨系统的问题,也许不是。 But I am just working on Mac OS X, therefore I focus on Cocoa.
但是我只是在Mac OS X上工作,因此我专注于Cocoa。
As my title described, can I detect whether my application is run in an virtual environment programmatically? 如标题所述,我可以检测我的应用程序是否以编程方式在虚拟环境中运行吗? (not only vmware , but also some other virtual environment like Sandboxie in Windows)
(不仅是vmware ,还有其他一些虚拟环境,例如Windows中的Sandboxie )
There won't be any native Cocoa API's to specifically ask if you are running in a virtual machine vs real hardware. 不会有任何本机的Cocoa API专门询问您是在虚拟机还是在真实硬件中运行。
However, if you know the potential environments you are running under you should be able to use IOKit to query the hardware of the virtual machine. 但是,如果您知道正在运行的潜在环境,则应该能够使用IOKit查询虚拟机的硬件。
Virtual Machines will have considerably different hardware than a real Mac so you should be able to detect a real Mac vs a VM based on hardware configuration. 虚拟机的硬件与真正的Mac将有很大的不同,因此您应该能够基于硬件配置检测真正的Mac与VM。
I can not give you any direct code, however, there is a section on Apple's site that discusses accessing hardware with IOKit in general: 我不能给您任何直接的代码,但是,Apple网站上有一节专门讨论了如何使用IOKit访问硬件:
https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html
IOKit is an advanced subject so if you do not have a lot of experience with the lower-level APIs you may find it a bit confusing as compared to Cocoa. IOKit是一门高级课程,因此,如果您没有使用低级API的丰富经验,与Cocoa相比,您可能会感到有点困惑。
也许您可以交叉编译virt-what并加以利用。
In addition to I/O Kit you could use C POSIX functions. 除了I / O Kit,您还可以使用C POSIX函数。 Check the man pages.
检查手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.