Is there a way to synchronously retrieve configuration information from the app or read configuration information from a file within the Start
method of DriverKit
?
I have attempted to use OSMappedFile
to read a file, but my driver crashes or I receive the error message "Sandbox: com.injection.epusbfilter.dext(20610) deny(1) file-read-data /private/tmp/driverkit_config.txt" in the console, even though I have set com.apple.security.app-sandbox
to false
.
OSMappedFile *mappedFile;
do {
const char *path = "/private/tmp/cfg";
// 创建 OSMappedFile 实例
kern_return_t result = OSMappedFile::createFromPath(path, 0, 0, &mappedFile);
if (result != KERN_SUCCESS) {
Log("Failed to create and map the file.");
ret = -1;
break;
}
*size = mappedFile->size();
// 获取映射到内存中的数据
char *charData = reinterpret_cast<char *>(const_cast<void *>(mappedFile->data()));
Log("get cfg:%s", charData);
if (strlen(charData) > 0) {
if (charData[0] == '1') {
ret = 1;
break;
}
}
else {
ret = -2;
break;
}
} while(false);
mappedFile->free();