Posts

Post not yet marked as solved
2 Replies
269 Views
A swift function name as getDataFromC which can connect with C function. A C function name as ExternalMethod which will receive the connect from swift. The parameter will be fill by call setData function. I can confirm that the entire structure return to getDataFromC was successful. Because I print the data of other structure members to check the correctness of the data. However, I don't know how to translate the largeData to [UInt8]. I try UnsafeMutableRawPointer type. I don't know what to do for the following action. I expected that output.largeData can be translate to [UInt8] type. //Bridging header file struct myStruct { void *largeData; int largeDataLength; int smallData[3]; } //C file void setData(myStruct* data) { int i = 0; uint8_t array[1024]; memset(array,0x66,1024); data->largeData = array; data->largeDataLength = 1024; data->smalData[0] = 0x99; data->smalData[0] = 0x88; data->smalData[0] = 0x77; } void ExternalMethod(myStruct* data) { setData(&output); } //Swift file func test() { var output = myStruct() getDataFromC(&output); var myPointer: UnsafeMutableRawPointer = output.largeData /* Here: I don't know how to translate data from myPointer to [UInt8] */ print("smallData: \(output.largeDataLength)") // 1024 transmission is correct print("smallData: \(output.smallData.0)") // 0x99 transmission is correct print("smallData: \(output.smallData.1)") // 0x88 transmission is correct print("smallData: \(output.smallData.2)") // 0x77 transmission is correct }
Posted
by JMicron.
Last updated
.
Post not yet marked as solved
1 Replies
395 Views
I declare a structure type in swift, name as CmdStruct struct CmdStruct { var cmd:[UInt8] init() { cmd = [UInt8](repeating: 0, count:16) } } In the case that the connection has been obtained. In sendCmd function, declare a variable which name as input which type of CmdStruct. After set data to input, call a DriverKit function IOConnectCallStructMethod. Here xcode shows a warning tip for the parameter 'input' for call IOConnectCallStructMethod: <Forming 'UnsafeRawPointer' to a variable of type 'CmdStruct'; this is likely incorrect because 'CmdStruct' may contain an object reference.> func sendCmd() { var ret:kern_return_t = kIOReturnSuccess var input = cmdStruct() var output:[UInt8] = [UInt8](repeating:0, count: 16) var inputSize = MemoryLayout<CmdStruct>.size // print value 8 var outputSize = output.count // print value 16 input.cmd[0] = 0x12 input.cmd[1] = 0x34 ret = IOConnectCallStructMethod(Connection, selector, &input, inputSize, &output, &outputSize) } In C file, driverkit function ExternalMethod will receive the parameter from swift side. And check the value of input->cmd[0] and input->cmd[1] in console. However, the values are not the expected 0x12 and 0x34. struct CmdStruct { uint8_t cmd[16]; }; kern_return_t myTest::ExternalMethod(uint64_t selector, IOUserClientMethodArguments* arguments, const IOuserClientMethodDispatch* dispatch, OSObject* target, void* reference) { int i = 0; CmdStruct* input = nullptr; if (arguments == nullptr) { ret = KIOReturnBadArgument; } if (arguments->structureInput != nullptr) { input = (CmdStruct*)arguments->structureInput->getBytestNoCopy(); } /* Here to print input->cmd[0] and input->cmd[1] data to console. */ } I expect that the correct value of input will be show on the driverkit side. I'm not sure which part is wrong. Here, I list some factors that may lead to incorrect value. How to fix the warning tip for parameter 'input' when call IOConnectCallStructMethod in swift. I get the inputSize value 8 by using MemoryLayout.size. But this structure contains a 16 bytes array. How to get the correct struct size in swift In C file side, using (CmdStruct*)arguments->structureInput->getBytestNoCopy() to transform data to C struct is correct?
Posted
by JMicron.
Last updated
.
Post not yet marked as solved
0 Replies
390 Views
Hi all, Whenever I install my kernel extension at first time, it shows "***.kext was blocked from opening because it is not from an identified developer" in System Preference > Security & Policy . I've download Developer ID Application in keychain, and it is not expired yet. In my Xcode > Build Settings > Signing: Code Signing Entitlements: empty Code Signing Identity: Developer ID Application Code Signing Inject Base Entitlements: No Code Signing Style: Automatic Development Team: My team Enable Hardened Runtime: Yes Other Code Signing Flags: --timestamp Provisioning Profile: Automatic And I've notarized my kernel extension, and its status is approval. Does someone encounter the same issue? Or does someone know which step I missed when I build and sign my kernel extension? Thanks a lot. Sean
Posted
by JMicron.
Last updated
.
Post not yet marked as solved
0 Replies
2k Views
Hi all,I installed a kernel extension with bundle version 2.0.2 in Mac OS 10.15Then I update a new kernel extension in bundle version 2.0.6 by below steps:Step 1. pre-install:sudo rm -rf /Library/Extensions/kextname.kextStep 2. Install pkg with kernel extension in v2.0.6Step 3. post-install:sudo kextutil -v /Library/Extensions/kextname.kext sudo kextcache -i /Step 4. Reboot my Macbook ProDo some test with my kernel extensions in v2.0.6, kernel extension seem not workingNote: my kernel extension is the driver of usb device.Step1: use tool to run some testStep2: unplug usb device,Step3: wait for 4~5 minutes,Step4: reconnect usb device,Step5: use tool to run test failUse below command to checksudo kextstat | grep mykeywordIt shows bundle id with v2.0.2Then, I use below commands to remove current kernel extension to debug this issuesudo rm -rf /Library/Extensions/kextname.kext sudo kextcache -i / sudo kextcache --clear-staging sudo rebootAfter reboot,my kernel extension is not existed in below path:/Library/Extensions//Library/StagedExtensions/Library/Extensions/Go to Apple Menu > About This Mac > Overview > System Report > Software > Extensionsmy kernel extension is not foundUse below command to checksudo kextstat | grep mykeywordIt still show bundle id with v2.0.2After I update Mac OS to 10.15.1it does not occur again.I've seen a similar issue reported in below linkhttps://forums.developer.apple.com/thread/124163Is my issue the same as above link?If yes, is there a way to clear and/or find the remained kernel extension manually?Thanks.Sean
Posted
by JMicron.
Last updated
.
Post marked as solved
7 Replies
4.4k Views
Hi all,when I use below steps to check my kext file on MacOS 10.15, it returns errors:Execute below commands on terminal: sudo chown -R root:wheel kextname.kext sudo chmod -R 755 kextname.kextsudo kextload kextname.kextTerminal shows below message: /path/kextname.kext failed to load - (libkern/kext) not found; check the system/kernel logs for errors or try kextutil(8).sudo kextutil kextname.kextTerminal shows below message:Kext rejected due to system policy: <OSKext 0x7fec84d68e80 [0x7fff8ddbfb00]> { URL = "file:///Library/StagedExtensions/Library/Extensions/kextname.kext/", ID = "com.myname.driver.***" }/Library/StagedExtensions/Library/Extensions/kextname.kext does not authenticate; omitting.Kext rejected due to system policy: <OSKext 0x7fa2514d9f80 [0x7fff8ddbfb00]> { URL = "file:///Library/StagedExtensions/Library/Extensions/kextname.kext/", ID = "com.myname.driver.***" }I've tried to execute command: codesign -vvv --deep --strict kextname.kext on terminalTerminal shows below message:kextname.kext: valid on diskkextname.kext: satisfies its Designated RequirementMy step to generate kext:1. Generate my certificate and upload it by my developer ID, and then download the certificate2. Use Xcode 11.1 to build kext successfully: Signing & Capabilities: - Automatically mange signing: unchecked - Signing Certificate: select Developer iD Application which I downloaded Build Settings: - Signing: Code Signing Identity: Developer ID Application Code Signing Inject Base Entitlements: No Development Team: my team name Enable Hardened Runtime: Yes Resources/Info.plist: - OSBundleLibraries com.apple.kpi.iokit: 19.0.0 com.apple.kpi.libkern: 19.0.0Is there a way to known the detail for "Kext rejected due to system policy" error? Or to solve it?Thanks.Sean
Posted
by JMicron.
Last updated
.