首页 > 解决方案 > macOS 上的 USB 外设仲裁

问题描述

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

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

我正在朝着IOKitUSB 设备接口指南简介的方向前进,我可以看到如何与 USB 设备通信,但我找不到任何类似于仲裁机制的东西。

任何想法?内核扩展不是一种选择。


macOS 11 更新

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

/**
 * @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.

关于如何以另一种方式获取设备信息的任何想法?

标签: macoscocoausbiokitdiskarbitration

解决方案


从 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 类似的策略回调。


推荐阅读