乙個簡單的串列埠過濾驅動

2021-05-27 07:13:31 字數 2695 閱讀 6812

學習驅動開發一段時間了,在嘗試著從最簡單的驅動開發著手學習,我再嘗試著編寫乙個最簡單的串列埠過濾驅動,可是多次嘗試都沒有成功,總是一載入就藍屏。看了網上的例子他們都是採用的ioattachdevicetodevicestack,而我採用的是ioattachdevice,現在把網上的**整理成最簡單的形式給大家分享一下,希望初學者能從中受益。我會再後面的部落格裡詳細介紹。

#include #include static pdevice_object m_fltobj;

static pdevice_object m_topobj;

//定義乙個讀的完成處理函式

ntstatus fengreadcomplete(in pdevice_object deviectobject, in pirp irp, in pvoid context)

dbgprint("\r\n");

} if( irp->pendingreturned)

iomarkirppending( irp);

return irp->iostatus.status;

}ntstatus driver1_dispatchdevicecontrol(in pdevice_object deviceobject,in pirp irp)

else if(irpsp->majorfunction == irp_mj_write)

dbgprint("\r\n");

} else if(irpsp->majorfunction == irp_mj_read)

ioskipcurrentirpstacklocation(irp);

return iocalldriver(m_topobj, irp);

} irp->iostatus.information = 0;

irp->iostatus.status = status_invalid_parameter;

iocompleterequest(irp, io_no_increment);

return status;

}void driver1_driverunload(in pdriver_object driverobject)

#pragma code_seg("init")

ntstatus driverentry(in out pdriver_object driverobject,in punicode_string registrypath)

driverobject->driverunload = driver1_driverunload;

rtlinitunicodestring(&namestr, l"\\device\\serial0");

status = iogetdeviceobjectpointer( &namestr, file_all_access, &fileobj, &devobj);

if(status == status_success)

obdereferenceobject(fileobj);

if(status == status_success)

dbgprint(("driverentry 成功\r\n"));

m_topobj= topdev;

m_fltobj->flags &= ~do_device_initializing;

return status_success;

} return status_success;

}

把irp請求處理再次簡化就變成了下面的形式,我為什麼要這樣簡化就是想告訴大家驅動過濾的簡單框架。

#include #include static pdevice_object m_fltobj;

static pdevice_object m_topobj;

ntstatus driver1_dispatchdevicecontrol(in pdevice_object deviceobject,in pirp irp)

void driver1_driverunload(in pdriver_object driverobject)

#pragma code_seg("init")

ntstatus driverentry(in out pdriver_object driverobject,in punicode_string registrypath)

driverobject->driverunload = driver1_driverunload;

rtlinitunicodestring(&namestr, l"\\device\\serial0");

status = iogetdeviceobjectpointer( &namestr, file_all_access, &fileobj, &devobj);

if(status == status_success)

obdereferenceobject(fileobj);

if(status == status_success)

dbgprint(("driverentry 成功\r\n"));

m_topobj= topdev;

m_fltobj->flags &= ~do_device_initializing;

return status_success;

} return status_success;

}

乙個串列埠輸入過濾驅動

在看了 寒江獨釣 windows核心安全程式設計 一書,根據書中所講編寫,中只對irp mj write進行了過濾處理 檔名comcap.c include include define ntstrsafe lib define ccp max com id 32 設定最大com埠個數 儲存所有過濾...

乙個簡單的keyboard驅動

這個驅動使能了幾個cpld控制的按鍵,f1,f2,f3,f4,home,up,down,left,right,esc,enter。1.cpld kpd probe static int cpld kpd probe struct platform device pdev cpld input dev...

驅動篇 乙個簡單的led驅動

1.構造裝置結構體 struct light dev cdev結構體 struct cdev 2.設定裝置資訊 struct light dev light devp 設定裝置結構體變數 int light major light major 設定主裝置號3.設定並填充file operations...