前段時間做了乙個基於ipfilterdriver的ip過濾驅動,使用了一段時間卻出現了不少問題:
1、首先,ipfilterdriver只能掛接乙個驅動。也就是說,如果其他的驅動先掛接了ipfilterdriver,那麼我們的安裝將失敗;
2、其次,有的2000pro系統下居然缺少ipfilterdriver驅動元件;
3、最後,某些系統會出現997錯誤,即「重疊io操作正在進行」。
基於上述問題,重新實現了乙個tcp裝置的過濾驅動程式tcpfilter,使用它來攔截ip訪問操作。
在2000以上的系統中,都實現了乙個tcp裝置"//device//tcp",大部分上層的intel網路通訊都是通過這個裝置完成的,如果我們實現乙個tcp裝置的上層過濾程式,便能攔截到使用者的網路訪問。tcp裝置過濾程式的實現和其他驅動的過濾程式沒什麼兩樣,其**如下:
rtlinitunicodestring( &usfiltername, filter_name );
iocreatedevice( pdrvobj,
sizeof(device_extension),
&usfiltername, // filter driver name
file_device_unknown,
0, true,
&g_pfilterdevobj );
rtlinitunicodestring(&dosdevicename, dos_device_name);
iocreatesymboliclink( &dosdevicename, &usfiltername );
rtlinitunicodestring( &ustargetname, target_name );
iogetdeviceobjectpointer( &ustargetname,
file_all_access,
&ptargetfileobj,
&ptargetdevobj );
// initialize the device extension
pdevext = (pdevice_extension) g_pfilterdevobj->deviceextension;
pdevext->pdeviceobject = g_pfilterdevobj; // back pointer
// pile this new filter on top of the existing target
pdevext->ptargetdevice = // downward pointer
ioattachdevicetodevicestack( g_pfilterdevobj, pdo);
for (i=0; i<=irp_mj_maximum_function; i++)
if (i!=irp_mj_power)
pdrvobj->majorfunction[i] = dispatch;
dispatch函式的完整**如下:
ntstatus dispatch(
in pdevice_object pdevobj,
in pirp pirp ) }}
else if(majorfunction == irp_mj_device_control)
iocompleterequest(pirp, io_no_increment);
return status;
}passthru:
// copy args to the next level
pnextirpstack = iogetnextirpstacklocation( pirp );
/* iocopycurrentirpstacklocationtonext( pirp );
// *pnextirpstack = *pirpstack;
// dbgprint("dispatch: majorfun: %d, minorfun: %d.", pirpstack->majorfunction,
// pirpstack->minorfunction);
// set up a completion routine to handle the bubbling
// of the "pending" mark of an irp
iosetcompletionroutine(
pirp,
genericcompletion,
null,
true, true, true );
*/// 如果使用上面的**會出現no_more_irp_stack_locations藍屏
ioskipcurrentirpstacklocation( pirp );
// pass the irp to the target.
return iocalldriver(
pfilterext->ptargetdevice,
pirp );
}dispatch函式捕獲上層的所有命令,首先攔截上層的tcp連線操作,如果上層連線的位址沒通過測試(checkipaddress),則中斷此次連線return status_remote_not_listening。其次,捕獲應用層發給驅動的命令字,最後,把所有其他的命令傳遞給下層驅動處理。
dispatch函式接收到的命令由tdi客戶端傳送,如果想詳細了解tdi的通訊過程可以參考ddk或使用上述函式跟蹤。tdi的網路命令其majorfunction == irp_mj_internal_device_control,當tdi企圖建立遠端連線時,minorfunction == tdi_connect。此時遠端位址的解析方式可參考上述完整**。
剛開始的時候,我使用的是iocopycurrentirpstacklocationtonext。但啟動驅動不久便會出現藍屏,bug碼為:no_more_irp_stack_locations,費了很長時間也沒解決此問題,最後索性改為ioskipcurrentirpstacklocation才一切正常。至今仍不知問題出在**,望高人指點迷津。
本來實現了乙個unload函式,可每次解除安裝驅動的時候都藍屏,錯誤碼driver_unloaded_without_cancelling_pending_operations,搞不定他,所以硬著頭皮每次重起系統來除錯程式。我寫的unload函式的**如下,希望有高人指點。
void
driverunload(in pdriver_object driverobject)
過濾器(6) 過濾器的攔截
本系列部落格彙總在這裡 過濾器彙總 我們來做個測試,寫乙個過濾器,指定過濾的資源為 index.jsp,然後我們在瀏覽器中直接訪問 index.jsp,你會發現過濾器執行了!但是,當我們在 helloservlet 中使用伺服器端的跳轉request.getrequestdispathcer ind...
過濾器(filter)實現
花了2天時間,實現了過濾器功能,針對資料進行篩選,包含以下7個過濾器 date currency number tolowercase touppercase orderby filter 其中前5個針對資料格式轉換,orderby 和 filter 針對陣列過濾。orderby 支援多個屬性 a ...
過濾器的功能實現
非登入狀態下,訪問目標頁面,登入之後直接進入目標頁面而非首頁 webfilter urlpatterns public class checkloginfilter implements filter override public void dofilter servletrequest requ...