macos 如何在 OSX 上欺骗 USB 供应商 ID 和产品 ID 值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5831226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can USB vendor ID and product ID values be spoofed on OSX?
提问by Tom Dalling
We are considering using the vendor and product ID of a USB device (obtained via IOKit) to unlock certain features of an application. I'm aware that these values can be spoofed, but I'm not sure how easily it can be done on OSX. What is involved in spoofing the vendor and product ID? Is it something that a non-programmer can do fairly easily?
我们正在考虑使用 USB 设备的供应商和产品 ID(通过 IOKit 获得)来解锁应用程序的某些功能。我知道这些值可能会被欺骗,但我不确定在 OSX 上这样做有多容易。欺骗供应商和产品 ID 涉及什么?非程序员可以很容易地做到这一点吗?
采纳答案by Mecki
A non-programmer cannot do that. What you can do is writing a kernel extension (an IOKit driver) for the device, that has a matching dictionary matching the realvendor-/product-ID of the device, which causes the system to automatically load the kernel extension when this device is connected and pass a reference to the device object. The driver is now responsible for initializing the device and create all necessary user space information that is necessary for the IOKit framework (the user space library) to communicate with the device. Usually Apple has default IOKit drivers for most USB device classes (that's why you don't need an extra driver for every USB mouse or keyboard for example), but if there is a more specific driver found, then this driver will be used instead. And when creating the user space data, of course the driver may lieabout the vendor-/product-ID, causing the user space program to see false values. Since IOKit is written in C++ and heavily depends upon objects and object inheritance, it is not even necessary to write the driver from scratch, but instead it can inherit from Apple's default driver and just override some methods and otherwise rely upon the super implementation. However, writing IOKit kernel drivers is not that easy and even people developing Mac software for years may have no idea how to do that and the IOKit documentation is one of the worst ones Apple is offering.
非程序员无法做到这一点。你可以做的是为设备编写一个内核扩展(一个 IOKit 驱动程序),它有一个匹配的字典匹配真实的设备的 vendor-/product-ID,这会导致系统在连接此设备时自动加载内核扩展并传递对设备对象的引用。驱动程序现在负责初始化设备并创建 IOKit 框架(用户空间库)与设备通信所需的所有必要的用户空间信息。通常,Apple 为大多数 USB 设备类提供了默认的 IOKit 驱动程序(例如,这就是为什么您不需要为每个 USB 鼠标或键盘提供额外驱动程序的原因),但如果找到了更具体的驱动程序,则将使用此驱动程序。而在创建用户空间数据时,当然驱动程序可能会撒谎关于 vendor-/product-ID,导致用户空间程序看到错误值。由于 IOKit 是用 C++ 编写的并且严重依赖对象和对象继承,因此甚至不需要从头开始编写驱动程序,而是可以从 Apple 的默认驱动程序继承,只需覆盖一些方法,否则依赖于超级实现。然而,编写 IOKit 内核驱动程序并不是那么容易,甚至开发 Mac 软件多年的人也可能不知道如何做到这一点,而 IOKit 文档是 Apple 提供的最糟糕的文档之一。
So to answer your question: Is it possible? Yes. Is it fairly easy? No. Can non-programmers do it? Certainly not, unless someone else has written a ready to use extension for them, that they only need to install.
所以回答你的问题:这可能吗?是的。它相当容易吗?不。非程序员可以做吗?当然不是,除非其他人为他们编写了一个随时可用的扩展,他们只需要安装。
回答by Hasturkun
I suspect it would be fairly easy (for a programmer) to create a kext that creates a reasonably realistic IOUSBDevice object in kernel space. However, once done anyone would be able to load it.
我怀疑(对于程序员而言)创建一个 kext 会相当容易,该 kext 在内核空间中创建一个相当现实的 IOUSBDevice 对象。但是,一旦完成,任何人都可以加载它。
It may also be possible to build a codeless kext using AppleUSBMergeNub to masquerade a device as another (though I haven't tested this, it looks like it might work, assuming you only try to match the IOUSBDevice without actually using it).
也可以使用 AppleUSBMergeNub 构建一个无代码的 kext,将一个设备伪装成另一个设备(虽然我没有测试过这个,但它看起来可能有效,假设您只是尝试匹配 IOUSBDevice 而没有实际使用它)。
It would probably be easier to just hiHyman your API calls in userspace and give your software the answers it expects.
在用户空间中劫持您的 API 调用并为您的软件提供它期望的答案可能会更容易。
回答by thaiiy
It's actually rather EASY, and I'm definitely not a programmer!
这实际上相当容易,而且我绝对不是程序员!
Found the guide here http://rolande.wordpress.com/2012/10/25/getting-the-aten-usb-serial-adapter-working-with-mac-osx-lion
Thanks, Rolande!
谢谢,罗兰德!
I was able to change the IDs of a USB Ethernet adaptor I bought on eBay to use another driver with Mac OS X 10.8.
我能够更改我在 eBay 上购买的 USB 以太网适配器的 ID,以便在 Mac OS X 10.8 中使用另一个驱动程序。
回答by Tom Dalling
Since nobody has answered so far, I've stumbled across a pagewhich basically says that you can get an Arduino and program it to return any VID/PID/serial that you want. I still can't find any software-only way to do this.
由于到目前为止没有人回答,我偶然发现了一个页面,它基本上说你可以得到一个 Arduino 并对其进行编程以返回你想要的任何 VID/PID/串行。我仍然找不到任何纯软件的方法来做到这一点。
回答by lexdean
I can create A OCX in Delphi code to do that And supply infomation to send/receive data to the USB with other states like:- is it still connected.
我可以在 Delphi 代码中创建一个 OCX 来做到这一点,并提供信息以向 USB 发送/接收数据,并具有其他状态,例如:- 是否仍然连接。
Natraly I need a little more detail than that in case that same chip is connected from another product. example frendly name, device desription.............
当然,如果同一个芯片是从另一个产品连接的,我需要更多的细节。示例友好名称、设备描述......................