Hi!
There are two fields in ES message: global_seq_num and seq_num, which are described as a continuous number sequence unless the kernel is "dropping events" because "kernel generated more events than the client could handle."
https://developer.apple.com/documentation/endpointsecurity/es_message_t/3684979-global_seq_num
https://developer.apple.com/documentation/endpointsecurity/es_message_t/3538607-seq_num
However, as we all know, system will kill ES client, if the message is not answered in (deadline) time.
I've a lot questions about this thing:
What the "drop" actually is? The event is not provided to es client from the kernel?
What does the "client could handle" means exactly? (I mean, es client will be already killed, if it can't respond to event in deadline)
Are the dropped events responded by the system immediately, or they do wait something?
Are only auth events could be dropped, or notify too?
What is the system resolution for dropped auth events? (allow I guess)
What I'm expected to do as a developer with these two fields - should I just log them and hope to find something out later, or can I react somehow during runtime if I met the break in *seq_num sequence?
Drivers
RSS for tagUnderstand the role of drivers in bridging the gap between software and hardware, ensuring smooth hardware functionality.
Post
Replies
Boosts
Views
Activity
iOS uses the USB HID protocol to communicate wiredly with external peripherals. Is this technology feasible? Why?
I am new to macOS development and presently tearing my hair out trying to get a driverkit extension to build. I have tried following the instructions here:
https://developer.apple.com/documentation/driverkit/communicating_between_a_driverkit_extension_and_a_client_app
namely, disabling SIP, but I am still unable to get my extension to build. The instructions say to set the code signing identity to "Sign to Run Locally" for all three targets, but this is not listed as an option for the driver extension.
I was trying to hide some external drives from desktop, I know I can do it from finder preferences, but it will hide all my external drives from desktop. I want drive A, B, C to be visible on desktop but don't want drive D to be visible.
Some website suggest this solution:
sudo SetFile -a V /Volumes/"Drive Name"
but it says I need command line tools, since I was in terminal, and prompt come from MacOS itself, I stared installation. But what are this tools actually is it sahe to install it?
And why this tool taking 2.35GB of storage just to hide one icon from desktop?
I have a custom HID device that works on Windows totally fine with the default HID driver. The HID device knows how to accept string commands to control it and respond accordingly. I am trying to control it on Mac using IOKit.
I am able to get the io_service_t reference to the IOHIDInterface for the device from the I/ORegistery. I use this to instantiate a class to represent the device. But when I try to establish a connection to the service, I keep getting -536870201 which corresponds to kIOReturnUnsupported. I'm not entirely sure what I am doing wrong here and I wasn't able to find anything online that could really help.
I have a custom HID USB device that I can control on Mac with IOKit via the default HID MacOS driver. I am using IOHIDManager to detect it and send reports to it. I would like to extend this capability to iPad but the full IOKit framework is not supported on iOS/iPadOS.
I saw that USBDriverKit is now supported on iPads with an M1 chip or newer. But, both MacOS and Windows can operate the device with their generic HID driver. As such, having to create a whole custom driver to interact with an HID device on iOS is really overkill.
Would registering it in the MFi Program and operating it with the External Accessory framework be the correct route to take here? Or is there another framework for controlling HID devices on iPad over USB that I am not aware of?
In another question on this forum (https://developer.apple.com/forums/thread/124775) eskimo stated that launching a system extension from an daemon is not the right approach and that the OSSystemExtensionRequest.activationRequest API should be called from an App.
My question is, does this same restriction apply to a LaunchAgent started App?
If so, to ensure activation as soon as possible is the only option to use a SMLoginItemSetEnabled helper to start the App on login?
I want to get the information of USB like, USB name, size, VID, PID, etc using DriverKit Extension but I'm facing difficulty finding such references or Sample code for the same.
Please help me with the Sample code to get USB info with the help of Dext.
Thanks
Hello,
The latest version of Metal (on macOS 14) seems to have the instance property for the Metal device architecture.
I was curious how this could be achieved on versions of macOS prior to 14 programatically?
xcrun metal-arch
The above command provides exactly what I need.
I was thinking that I could use Metal and IOKit to grab the architecture, but I am lead to believe that there is some kind of mapping in the metal-arch tool and it may not be that easy.
Any help would be greatly appreciated.
Thanks.
I built an app which hosts a CMIOExtension. The app works, and it can activate the extension. The extension loads in e.g. Photo Booth and shows the expected video (a white horizontal line which moves down the picture).
I have a couple of questions about this though.
The sample Camera Extension is built with a CMIOExtension dictionary with just one entry, CMIOExtensionMachServiceName which is $(TeamIdentifierPrefix)$(PRODUCT_BUNDLE_IDENTIFIER)
This Mach service name won't work though. When attempting to activate the extension, sysextd says that the extensions has an invalid mach service name or is not signed, the value must be prefixed with one of the App Groups in the entitlement.
So in order to get the sample extension to activate from my app, I have to change its CMIOExtensionMachServiceName to
<my team ID>.com.mycompany.my-app-group.<myextensionname>
Is this to be expected?
The template CMIOExtension generates its own video using a timer. My app is intended to capture video from a source, filter that video, then feed it to the CMIOExtension, somehow. The template creates an app group called "$(TeamIdentifierPrefix)com.example.app-group", which suggests that it might be possible to use XPC to send frames from the app to the extension.
However, I've been unable to do so. I've used
NSXPCConnection * connection = [[NSXPCConnection alloc] initWithMachServiceName:, using the CMIOExtensionMachServiceName with no options and with the NSXPCConnectionPrivileged option. I've tried NSXPCConnection * connection = [[NSXPCConnection alloc] initWithServiceName: using the extension's bundle identifier. In all cases when I send the first message I get an error in the remote object proxy's handler:
Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named <whatever name I try> was invalidated: failed at lookup with error 3 - No such process."
According to the "Daemons and Services Programming Guide" an XPC service should have a CFBundlePackageType of XPC!, but a CMIOExtension is of type SYSX. It can't be both.
Does the CMIOExtension loading apparatus cook up a synthetic name for the XPC service, and if so, what is it? If none, how is one expected to get pixel buffers into the camera extension?
I can't find any useful help about the content described in the title on Apple's official website. The relevant help on its official website is almost all based on OC language, and even their sample programs are written in OC language. Can I ask if SWIFT can only use the COM port through the bridge of OC-SWIFT?
Hey!
I'am trying to write my own driver for usb serial device. I'am trying to subclass from IOUserUSBSerial
#include <DriverKit/IOService.iig>
#include <USBSerialDriverKit/IOUserUSBSerial.iig>
class NewDriver: public IOUserUSBSerial
{
public:
virtual kern_return_t
Start(IOService * provider) override;
};
but get a lot of errors such as
"IOUserUSBSerial::handleRxPacket(unsigned char*&, unsigned int&)", referenced from:
vtable for NewDriver in NewDriver.iig.o
"IOUserUSBSerial::handleInterruptPacket(unsigned char const*, unsigned int)", referenced from:
vtable for NewDriver in NewDriver.iig.o
"IOUserUSBSerial::free()", referenced from:
vtable for NewDriver in NewDriver.iig.o
"IOUserUSBSerial::init()", referenced from:
vtable for NewDriver in NewDriver.iig.o
"IOUserUSBSerial::initWith(IOBufferMemoryDescriptor*)", referenced from:
vtable for NewDriver in NewDriver.iig.o
"IOUserUSBSerial::_Dispatch(IOUserUSBSerial*, IORPC)", referenced from:
NewDriver::Start_Impl(IOService*) in NewDriver-e6d71af2158103084ce0c1eba7c6088d.o
NewDriver::_Dispatch(NewDriver*, IORPC) in NewDriver.iig.o
"vtable for IOUserSerial", referenced from:
IOUserSerial::IOUserSerial() in NewDriver.iig.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for IOUserUSBSerial", referenced from:
IOUserUSBSerial::IOUserUSBSerial() in NewDriver.iig.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"non-virtual thunk to IOUserUSBSerial::free()", referenced from:
vtable for NewDriver in NewDriver.iig.o
"non-virtual thunk to IOUserUSBSerial::init()", referenced from:
vtable for NewDriver in NewDriver.iig.o
"non-virtual thunk to IOUserUSBSerial::initWith(IOBufferMemoryDescriptor*)", referenced from:
vtable for NewDriver in NewDriver.iig.o
"non-virtual thunk to IOUserUSBSerial::handleRxPacket(unsigned char*&, unsigned int&)", referenced from:
vtable for NewDriver in NewDriver.iig.o
"non-virtual thunk to IOUserUSBSerial::handleInterruptPacket(unsigned char const*, unsigned int)", referenced from:
vtable for NewDriver in NewDriver.iig.o
ld: symbol(s) not found for architecture x86_64
If I making any implementations of this methods errors staying on. What Im doing wrong? Is there anywhere examples for USBSerialDriverKit? Didn't find anything on github
Hey folks,
I have an application that ships a CoreMedia I/O system extension to create a virtual camera.
We separately ship an "uninstaller" app, which is a notarised AppKit app. This uninstaller removes the app, containers, and the system extension via the following API:
let request = OSSystemExtensionRequest.deactivationRequest(forExtensionWithIdentifier: pluginIdentifier, queue: .main)
request.delegate = self
OSSystemExtensionManager.shared.submitRequest(request)
The OSSystemExtensionRequest API does correctly deliver metadata via propertiesRequest(forExtensionWithIdentifier: …), but when we attempt to remove the extension using the above snippet, we get a failure OSSystemExtensionError.extensionNotFound.
The uninstaller app is signed with the same entitlements and certificate as the host app. It also embeds a copy of the system extension as required by the API.
I think the crux of the issue is: Should this be expected to work? We're all code-signed correctly etc, and the only difference is that the removal request is coming from an app with a different bundle identifier to the one that installed it start with.
Thanks!
I'm using IOKit to connect to a custom USB HID device. I'm using XCode 14 and running Swift/SwiftUI. So far I have had great success reading from the device with IOHIDDeviceGetReport and this can be done repeatedly with no issues. However, when I use IOHIDDeviceSetReport, I can only successfully set the report to the device one time correctly but any subsequent call to this function would just end up with an I/O Timeout. Any calls using IOHIDDeviceGetReport still works fine so the USB Device is still functioning correctly, but I couldn't receive any additional IOHIDDeviceSetReport call. If I unplug the USB and plug it in again, I can once again successfully send a command. This is, of course, not very practical for the end user to have to unplug and plug the device in after a single set command, and I don't quite understand what's going on with this.
Here's my SetOutputReport function to call the IOHIDDeviceSetReport. The IOHIDDevice must already be connected and opened before calling this function so it's not nil.
I don't have this "one shot send command" problem on the PC (Windows 7, 10, 11) or Android (v.11,12,13,14) implementation of this Custom USB HID device. It seems like there's something at the lower level of IOHIDDeviceSetReport on macOS which might be done differently than what's available on the PC or Android.
Many searches on the web yielded no useful results. There's an IOHIDDeviceSetReportWithCallback function and it also seems only to work one time as well.
private func SetOutputReport(dev: IOHIDDevice? ,reportID: Int, data:[UInt8], reportLength: Int) -> String{
let inputReportID = reportID
var buffer = data
buffer[0] = UInt8(inputReportID)
let bufferPointer = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
bufferPointer.initialize(from: &buffer, count: buffer.count)
//print(bufferPointer[0])
let bufferLength: CFIndex = buffer.count
var success: IOReturn = kIOReturnError
if(dev != nil){
success = IOHIDDeviceSetReport(dev!, kIOHIDReportTypeOutput, CFIndex(buffer[0]), bufferPointer, bufferLength)
}
print("Set report result \(krToString(success))")
return krToString(success)
}
I have implemented an AppProxyProvider (NETransparentProxyProvider) and I am able to capture traffic with it.
I am also able to define network rules allowing me to exclude some traffic:
let settings = NETransparentProxyNetworkSettings(tunnelRemoteAddress: "127.0.0.1:8080")
settings.includedNetworkRules = [
NENetworkRule(remoteNetwork: NWHostEndpoint(hostname: "0.0.0.0", port: "0", remotePrefix: 0, localNetwork: nil, localPrefix: 0, protocol: .TCP, direction: .outbound)
]
Now the documentation states that if I want to capture localhost traffic, I need to explicitly add the following rule:
NENetworkRule(remoteNetwork: NWHostEndpoint(hostname: "127.0.0.0", port: "0", remotePrefix: 8, localNetwork: nil, localPrefix: 0, protocol: .TCP, direction: .outbound)
and if I want to capture ipv6 localhost address:
NENetworkRule(remoteNetwork: NWHostEndpoint(hostname: "::1", port: "0", remotePrefix: 128, localNetwork: nil, localPrefix: 0, protocol: .TCP, direction: .outbound)
All this works great.
Now I am having trouble capturing external ipv6 traffic. For example my ISP supports ipv6 and facebook.com resolves to 2a03:2880:f128:181:face:b00c:0:25de on my machine.
I am unable to write any rule allowing me to capture with the system extension such traffic. Either I get errors that the network mask cannot be greater than 32 or the traffic simply doesn't flow through the extension.
Here's an example request that I would like to capture:
curl https://facebook.com -kvp
* Trying [2a03:2880:f128:181:face:b00c:0:25de]:443...
* Connected to facebook.com (2a03:2880:f128:181:face:b00c:0:25de) port 443 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN: server accepted h2
* Server certificate:
* subject: C=US; ST=California; L=Menlo Park; O=Meta Platforms, Inc.; CN=*.facebook.com
* start date: Aug 26 00:00:00 2023 GMT
* expire date: Nov 24 23:59:59 2023 GMT
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
* using HTTP/2
* h2 [:method: GET]
* h2 [:scheme: https]
* h2 [:authority: facebook.com]
* h2 [:path: /]
* h2 [user-agent: curl/8.1.2]
* h2 [accept: */*]
* Using Stream ID: 1 (easy handle 0x7fcb5c011e00)
> GET / HTTP/2
> Host: facebook.com
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/2 301
< location: https://www.facebook.com/
< strict-transport-security: max-age=15552000; preload
< content-type: text/html; charset="utf-8"
< x-fb-debug: uWVEw8FZUIXozHae5VgKvIDY5lgH/4Aph+h+nJNJpIr7jFZIFGy9LRLGCSwPudcFBdi4Mf4rLaKsNGCBxHDmrA==
< content-length: 0
< date: Fri, 17 Nov 2023 14:14:03 GMT
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host facebook.com left intact
Can this be achieved?
In a project, I'm using the DriverKit(and HIDDriverKit) framework.
I have encountered a problem in the connection between the client app and the driver, which is implemented by the "IOKit" framework.
By calling the function "IOServiceGetMatchingServices" the value of "iterator" returns correctly and then communication with the driver is done.
However, after releasing the version on the TestFlight, on some systems, the value of the "iterator" returned 0 and it is not possible to communicate with the driver.
I checked the status of the activated driver with the command "systemextensionsctl list" and there are no problems on the driver side and the values of "Enabled" and "Active" are starred.
AppSandbox = True, SIP: enable
ret = IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceNameMatching(dextIdentifier), &iterator);
if (ret != kIOReturnSuccess)
{
goto fail;
}
while ((service = IOIteratorNext(iterator)) != IO_OBJECT_NULL) {
ret = IOServiceOpen(service, mach_task_self(), 0, &connection);
if(ret == kIOReturnSuccess)
{
break;
}
else
{
syslog(LOG_WARNING, "IDmelonLog LIB: Can't open service");
}
IOObjectRelease(service);
}
I am currently in the process of developing a DEXT for a USB based external mass storage device using the USBDriverKit framework. IOUSBHostInterface is used as the provider to communicate with the interface's endpoints and I am successful in it. As per the IOUSBHostInterface documentation,
To use a host interface object, call Open to create a new session between the interface and your driver. After successfully opening your session, you can request information from the interface and set up pipes to communicate with the interface's endpoints. Remember to close the session you opened in the Stop method of your driver.
However, calling Open gains exclusive access to the USB interface and does not allow other services to access the interface. Also, to let go of the exclusive access, Close method can be called but in the Stop method which is called only once during the lifecycle of the extension (when the DEXT is unloaded).
As a result of this, Apple's mass storage related KEXTs (media and partition related specifically) do not match the interface and so the filesystem of the drive in question does not get mounted whenever the DEXT has matched the interface.
Is this exclusive access a limitation of USBDriverkit or is there any way to get around this issue in this case?
In my application, I have used DriverKit USB Transport - VendorID. Now whenever I am trying to install my application using driver kit development profile, it throws me error that profile is not valid. Now, If I try to install the app using Adhoc profile, then I am able to install it. Can you update us, is there any changes are there in 17.1 OS with development profile.
I'm working on a system management tool that should be able to Allow/Deny mass storage and portable devices.
In case if it is a USB flash drive I can detect Mount events using Endpoint Security framework. Then using IOServiceGetMatchingServices I can find the actual device that is trying to mount new volume, check if it is an allowed device and Allow or Deny mount.
But in case if it is an iPhone/iPad or Android device I can't rely on that solution as they don't mount new volumes but user can copy files to the phone. To cover this case I could respond with Deny for the ES_EVENT_TYPE_AUTH_IOKIT_OPEN event. But at that moment I know nothing about the device, only its class which is the same for a mouse and for iPhone.
I can add a notification for adding new USB devices, but then I would need somehow to understand that it is a phone/tablet and disconnect or suspend needed USB Device.
How could I disconnect or suspend a USB Device having only io_object_t?
In my old scanner driver I filled gICDScannerCallbackFunctions structure with callback links and then called ICD_ScannerMain(..)
Now I'm trying to rebuild the driver as driverkit extension, but it looks like ICADevices framework is not available here.
What API should the driver implement to communicate with the application and how to register it?