驅動開發之二 嘗試掛接file system

2021-06-07 04:45:57 字數 2204 閱讀 6819

hookfilesystem.c

**//嘗試掛接file system

#include "hookfilesystem.h"

handle        hfilehandle;

object_attributes        objectattrib;

pdevice_object        pfiledeviceobject;

struct _driver_object *pdeviceobject;

pdriver_dispatch realcreatedispatch;

ntstatus driverentry(in pdriver_object driverobject ,in punicode_string registrypath)

//設定dispatch

driverobject->majorfunction[irp_mj_create] = driverdispatch;

driverobject->majorfunction[irp_mj_close] = driverdispatch;

//設定unload

driverobject->driverunload = driverunload;

//hook file system

hookfilesystem();

return 0;        

}ntstatus

driverdispatch(

in pdevice_object deviceobject,

in pirp           irp

)void driverunload(in pdriver_object pdriverobject)

void hookfilesystem(void)

//通過檔案控制代碼得到與之向對應的檔案物件

ntstatus = obreferenceobjectbyhandle(hfilehandle,file_read_data,0,0,&pfileobject,null);

if(!nt_success(ntstatus))

//在通過該檔案物件查詢相對應的檔案裝置

pfiledeviceobject = iogetrelateddeviceobject(pfileobject);

//檔案物件引用計數器減一

obdereferenceobject(pfileobject);

zwclose(hfilehandle);

if(pfiledeviceobject==null)

pdeviceobject = pfiledeviceobject->driverobject;

if(pdeviceobject->majorfunction[irp_mj_create] == hookcreatedispatch)

//儲存irp_mj_create處理的位址

realcreatedispatch = pdeviceobject->majorfunction[irp_mj_create];

//hook create dispatch

pdeviceobject->majorfunction[irp_mj_create] = hookcreatedispatch;

return;        

}ntstatus

hookcreatedispatch(    

in pdevice_object deviceobject,

in pirp           irp

)return 0;        

}hookfilesystem.h

**#ifndef _include_

#define _include_

#include

ntstatus

driverdispatch(

in pdevice_object deviceobject,

in pirp           irp

);void driverunload(in pdriver_object driverobject);

void hookfilesystem(void);

ntstatus

hookcreatedispatch(    

in pdevice_object deviceobject,

in pirp           irp

);#endif

驅動開發之二 嘗試掛接file system

hookfilesystem.c 嘗試掛接file system include hookfilesystem.h handle hfilehandle object attributes objectattrib pdevice object pfiledeviceobject struct dr...

首次嘗試測試驅動開發的體會

測試驅動開發的定義 最近在學習 重構 裡面強調,實施重構的乙個前提是,必須建立乙個可靠的測試環境。裡面還提到了測試驅動開發,以及測試驅動開發的好處。正好最近在開發乙個小的專案,所以便在這個專案中嘗試了一下測試驅動開發,感覺不錯,這裡分享一下我的體會。我開發使用的是c 我使用的測試框架是google的...

SylixOS CAN匯流排驅動之二

sylixos can 裝置除錯 除錯環境是在已經移植好sylixos的硬體開發平台上進行。由於imax6有2個控制器所以硬體上把can0和can1的兩個can h相連,兩個can l相連。can0和can1乙個做傳送乙個做接收,硬體連線完畢。注 不同板子的硬體平台可能不一樣,所以請根據自己板子的實...