Is it possible to load a kernel extension (kext
) through a C API instead of using the system()
call?
Asked
Active
Viewed 832 times
2 Answers
3
Yes, you want the KextManager API. In particular, KextManagerLoadKextWithIdentifier()
is probably the function you'll want to use to load an installed kext, versus KextManagerLoadKextWithURL()
if you want to load a kext that is not in /System/Library/Extensions or /Library/Extensions but e.g. in an .app bundle.

pmdj
- 22,018
- 3
- 52
- 103
0
CFStringRef km_path = CFStringCreateWithCString(kCFAllocatorDefault, "/Library/Extensions/KauthORama.kext",
kCFStringEncodingUTF8);
CFURLRef km_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, km_path,
kCFURLPOSIXPathStyle, true);
OSReturn status = KextManagerLoadKextWithURL(km_url, NULL);
if (status == kOSReturnSuccess){
syslog(LOG_NOTICE, "Loaded!");
}else{
syslog(LOG_NOTICE, "Lodaed error: %d", errno);
}

Ahmed Lotfy
- 3,806
- 26
- 28