现在我正在开发自己的驱动程序。我在 i/o kitDriver 模板中开发。我构建了我的代码,它成功执行但终端出现问题。我在头文件中以以下方式开发了代码
#include <IOKit/IOService.h>
class com_osxkernel_driver_IOKIT : public IOService
{
OSDeclareDefaultStructors(com_osxkernel_driver_IOKIT)
public:
virtual bool init (OSDictionary* dictionary = NULL);
virtual void free (void);
virtual IOService* probe (IOService* provider, SInt32* score);
virtual bool start (IOService* provider);
virtual void stop (IOService* provider);
};
在.cpp
#include "IOKIT.h"
#include <IOKit/IOLib.h>
#define super IOService
OSDefineMetaClassAndStructors(com_osxkernel_driver_IOKIT, IOService)
bool com_osxkernel_driver_IOKIT::init (OSDictionary* dict)
{
bool res = super::init(dict);
IOLog("IOKI::init\n");
return res;
}
void com_osxkernel_driver_IOKIT::free(void)
{
IOLog("IOKIT::free\n");
super::free();
}
IOService* com_osxkernel_driver_IOKIT::probe (IOService* provider, SInt32* score)
{
IOService *res = super::probe(provider, score);
IOLog("IOKIT::probe\n");
return res;
}
bool com_osxkernel_driver_IOKIT::start(IOService*provider)
{
bool res = super::start(provider);
IOLog("IOKIT::start\n");
return res;
}
void com_osxkernel_driver_IOKIT::stop(IOService*provider)
{
IOLog("IOKIT::stop\n");
super::stop(provider);
}
然后我在 IOKIT-info.plist 之后成功构建了上面的代码
IOKitPersonalities 字典我添加的以下五个内容
Key Type Value
CFBundleIdentifier String com.osxkernel.${PRODUCT_NAME:rfc1034identifier}
IOClass String com_osxkernel_driver_IOKIT
IOMatchCategory String com_osxkernel_driver_IOKIT
IOProviderClass String IOResources
IOResourceMatch String IOKit
之后
在 OSBundleLibraries 字典中,我添加了两个条目
Key Type value
com.apple.kpi.iokit String 11.3.0
com.apple.kpi.libkern string 11.3.0
之后我再次成功构建它
来到终端加载我按照以下步骤
在终端之前,我找到 kext 文件路径并将该包复制到 /system/library/extension/
然后去终端
执行以下方式
ensiss-Mac-mini:~ ensis$ sudo su
Password:
sh-3.2# chown -R 775 /System/Library/Extensions/IOKIT.kext
sh-3.2# sudo kextload /System/Library/Extensions/IOKIT.kext
/System/Library/Extensions/IOKIT.kext failed to load - (libkern/kext) validation failure
(plist/executable); check the system/kernel logs for errors or try kextutil(8).
sh-3.2#
嘿伙计们,请帮助我,重要的事情之一是每当我执行由通用驱动程序开发的 kext 文件时,它都会在终端中非常成功地执行。
我也是这个内核编程的初学者