Kernel extensions are able to execute code at kernel levels but also make kernel level data available to higher level things, right? That's how Intel PowerGadget accesses kernel level info, because it has a kext that it pulls that info from.
My question is, How would I access info from a kext via my own Objective-C code? Can I access a function? Or a class? How would I do such a thing?
Modern macOS kernel extensions (when you absolutely must use them - for many types of driver, there are now alternatives in DriverKit or user space) use the I/O Kit. Using the
IOKituser space framework, you can access the I/O Kit services implemented by your kext.setProperties()function in your kext'sIOServicesubclass. (While taking extreme care to only allow setting "safe" properties and validating all inputs.)IOUserClientsubclass - the keys here are that callingIOServiceOpenfrom user space invokes thenewUserClientmethod in yourIOServicesubclass (which can be overridden or by default returns an instance of the class specified by the IOUserClientClass property in your Info.plist's IOKitPersonality), and that when you call one of theIOConnectCall*functions from user space, this calls theexternalMethodfunction in your IOUserClient subclass.