2

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.

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

4

2 回答 2

2

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

于 2019-10-10T14:05:36.313 回答
1

不是一个完整的答案,但看起来有一种方法可以使用 IOKit 订阅设备通知。

Apple 在此处提供了 ionotifyCB.c:https ://opensource.apple.com/source/IOKitUser/IOKitUser-502/ionotifyCB.c.auto.html

它不是按原样为我构建的,但我能够通过一些小补丁使其工作:

@@ -23,5 +23,6 @@
 /*
-cc ionotifyCB.c -o /tmp/ion -Wall -Wno-four-char-constants -framework IOKit -undefined warning
+cc ionotifyCB.c -o /tmp/ion -Wall -Wno-four-char-constants -framework IOKit -framework CoreFoundation
 */
 
+#include <stdio.h>
 #include <ctype.h>
@@ -35,2 +36,3 @@
 #include <CoreFoundation/CFRunLoop.h>
+#include <IOKit/graphics/IOGraphicsLib.h>

于 2020-09-04T21:27:10.680 回答