1. 程式人生 > >mac ox驅動開發 c++版

mac ox驅動開發 c++版

bool and ces 表示 sudo sde truct str 析構

//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$ 

技術分享圖片
可能安裝個IORegistryExplorer 工具查看:
技術分享圖片

mac ox驅動開發 c++版