简体   繁体   English

我可以确定操作系统是否在可可的虚拟机中运行吗?

[英]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.

相关问题 是否有可能在Cocoa中确定是否从别名中打开了文件? - Is it possible to determine in Cocoa whether a file was opened from an alias? 如何确定Cocoa(OS X)应用程序的启动时间 - How to determine Cocoa (OS X) application start time 如何在已安装的Cocoa应用程序上运行Gcov? - How can I run Gcov over an installed Cocoa application? 如何确定我的Cocoa Desktop应用程序是否在登录时要打开的应用程序列表中? - How can I determine if my Cocoa Desktop application is on the list of apps to be opened at login? 有什么方法可以使使用基本SDK 10.10的可可应用程序在OS X 10.9中正确运行 - Is there any way can make a cocoa application which use base SDK 10.10 can run correctly in OS X 10.9 如何使用可可在OS X中将视网膜切换到非视网膜 - How can I switch retina to non-retina in OS X with cocoa 确定字体是否可以在Cocoa Touch中呈现Unicode字符 - Determining whether or not a font can render a Unicode character in Cocoa Touch 如何确定运行时void *指针是指向Objective-C对象还是C ++对象 - How can I determine whether a void * pointer points to a objective-c object or a c++ object at runtime 如何知道相机是否支持mac os x中的分辨率 - How can I know whether camera supports a resolution or not in mac os x 如何确定在单元测试运行期间代码是否正在运行 - How to determine whether code is running during a unit test run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM