Post

Replies

Boosts

Views

Activity

How to translate data from c language void * pointer to [UInt8 ] in swift code.
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 }
2
0
394
Dec ’23
How to deliver a struct which contain an array to driverkit by call driverkit function from swift code?
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?
1
0
641
Dec ’23
my kernel extension was blocked from opening because it is not from an identified developer
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
0
0
449
Dec ’20
kernel extension is still existed when I use kextcache command to clear cache
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
0
0
2.2k
Nov ’19