mac ox驱动开发 c++版

//IOKitTest.h

#include <IOKit/IOService.h>

class com_osxkernel_driver_IOKitTest : public IOService
{
    OSDeclareDefaultStructors(com_osxkernel_driver_IOKitTest)

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);
};

//IOKitTest.cpp

#include "IOKitTest.h"
#include <IOKit/IOLib.h>

//定义超类
#define super IOService
//表示提供构造与析构函数的声明 以及元数据
OSDefineMetaClassAndStructors(com_osxkernel_driver_IOKitTest, IOService)

//构造函数
bool com_osxkernel_driver_IOKitTest::init (OSDictionary* dict)
{
    bool res = super::init(dict);
    IOLog("IOKitTest::init\n");
    return res;
}

void com_osxkernel_driver_IOKitTest::free (void)
{
    IOLog("IOKitTest::free\n");
    super::free();
}
//检查硬件设备
IOService* com_osxkernel_driver_IOKitTest::probe (IOService* provider, SInt32* score)
{
    IOService *res = super::probe(provider, score);
    IOLog("IOKitTest::probe\n");
    return res;
}

bool com_osxkernel_driver_IOKitTest::start (IOService *provider)
{
    bool res = super::start(provider);
    IOLog("IOKitTest::start\n");
    return res;
}

void com_osxkernel_driver_IOKitTest::stop (IOService *provider)
{
    IOLog("IOKitTest::stop\n");
    super::stop(provider);
}

注意点:
内核版本
编译器版本
安装:

liuhailong:~ liuhailong$ sudo chown -R root:wheel /Users/liuhailong/Library/Developer/Xcode/DerivedData/IOKitTest-grjzacxpxpyxiidhzzobgihdxfqm/Build/Products/Debug/IOKitTest.kext 
liuhailong:~ liuhailong$ sudo kextload /Users/liuhailong/Library/Developer/Xcode/DerivedData/IOKitTest-grjzacxpxpyxiidhzzobgihdxfqm/Build/Products/Debug/IOKitTest.kext 
liuhailong:~ liuhailong$ sudo kextunload /Users/liuhailong/Library/Developer/Xcode/DerivedData/IOKitTest-grjzacxpxpyxiidhzzobgihdxfqm/Build/Products/Debug/IOKitTest.kext 
liuhailong:~ liuhailong$ 

mac ox驱动开发 c++版
可以安装个IORegistryExplorer 工具查看:
mac ox驱动开发 c++版

转载于:https://blog.51cto.com/haidragon/2164356

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值