macos - macOS 上的 USB 外设仲裁

标签 macos cocoa usb iokit diskarbitration

macOS 上的 DiskArbitration 框架提供了一种简单的方法来拦截卷安装并使用 DARegisterDiskMountApprovalCallback 对其进行授权或不授权。

我正在为所有其他 USB 设备寻找类似的东西,例如 HID 设备、网络接口(interface)以及一般的每个 USB 外围设备。

我正在朝着IOKit的方向前进:Introduction to USB Device Interface Guide我可以看到如何与 USB 设备通信,但我找不到任何类似于仲裁机制的东西。

有什么想法吗?内核扩展不是一个选项。

<小时/>

ma​​cOS 11 更新

macOS 引入了名为 ES_EVENT_TYPE_AUTH_IOKIT_OPEN 的新 AUTH 事件。 该事件被正确调用,但挖掘了我资助的对象 header :

/**
 * @brief Open a connection to an I/O Kit IOService
 *
 * @field user_client_type A constant specifying the type of connection to be
 *        created, interpreted only by the IOService's family.
 *        This field corresponds to the type argument to IOServiceOpen().
 * @field user_client_class Meta class name of the user client instance.
 *
 * This event is fired when a process calls IOServiceOpen() in order to open
 * a communications channel with an I/O Kit driver.  The event does not
 * correspond to driver <-> device communication and is neither providing
 * visibility nor access control into devices being attached.
 */
typedef struct {
    uint32_t user_client_type;
    es_string_token_t user_client_class;
    uint8_t reserved[64];
} es_event_iokit_open_t;

:(

这打乱了我的计划:

The event does not correspond to driver <-> device communication and is neither providing visibility nor access control into devices being attached.

知道如何以其他方式获取设备信息吗?

最佳答案

自 macOS 10.15 起,您可以使用 EndpointSecurity API 来授权 IOKit 用户客户端,即每当用户进程尝试 IOServiceOpen() 时都会收到回调。

与此相关的事件是 ES_EVENT_TYPE_NOTIFY_IOKIT_OPEN/es_event_iokit_open_t .

我认为这不适用于内核内客户端,对于那些您需要走 kext 路线的客户端。

在 10.15 之前,kext 通常是唯一的选择 - MAC 框架内核 API 具有与新的 EndpointSecurity 类似的策略回调。

关于macos - macOS 上的 USB 外设仲裁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58308415/

相关文章:

c# - 使用带有和不带有驱动程序或 API 的 C# 的 USB 打印机

macos - 无法在 Mac OS 终端上找到 jdk9

macos - 如何在 OSX 上安装 GTK+/PyGTK?

swift - 字符串之间带有标记的 XMLElement

ruby - 无法在 OS X Mavericks Xcode 5.1 上安装 CocoaPods

cocoa - 从 Cocoa 应用程序发送短信

cocoa - valueForKey 是否为 : NSMutableDictionary use copy for NSStrings?

ios - iPod/iPhone USB 产品 ID

objective-c - 获取文件路径文件打开对话框 cocoa ?

c# - 在 C# 中向 USB 连接的 GPRS 调制解调器发送 AT 命令