青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

S.l.e!ep.¢%

像打了激速一樣,以四倍的速度運(yùn)轉(zhuǎn),開心的工作
簡單、開放、平等的公司文化;尊重個(gè)性、自由與個(gè)人價(jià)值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
FileMon源碼學(xué)習(xí)筆記(二)
2008-11-24 10:41

FileMon源碼中另一個(gè)比較疑惑的地方,F(xiàn)ileMon創(chuàng)建了兩類設(shè)備,一個(gè)是用于和ring3通信的GUI設(shè)備,另一個(gè)是hook的過濾設(shè)備,但在代碼中,當(dāng)收到發(fā)向GUI設(shè)備的IRP_MJ_DEVICE_CONTROL時(shí),代碼竟是去調(diào)用屬于hook設(shè)備的功能函數(shù),而在這個(gè)功能函數(shù)里面通過條件判斷是否是GUI設(shè)備來分別處理,而對(duì)于發(fā)給GUI設(shè)備的其他IRP都在直接在GUI的處理函數(shù)中直接處理的,不知道作者這樣寫是否有什么深層的含義,不過對(duì)于我這種初學(xué)者來說,這樣的寫法倒是容易引起混亂,還是不同設(shè)備的功能函數(shù),分開來寫好一點(diǎn)。下面附上相關(guān)代碼:

//=========================================================

//GUI設(shè)備的功能函數(shù),注意IRP_MJ_DEVICE_CONTROL的實(shí)現(xiàn)

//=========================================================

NTSTATUS
FilemonDeviceRoutine(
??? IN PDEVICE_OBJECT DeviceObject,
??? IN PIRP Irp
??? )
{
??? PIO_STACK_LOCATION irpStack;
??? PVOID?????????????? inputBuffer;
??? PVOID?????????????? outputBuffer;
??? ULONG?????????????? inputBufferLength;
??? ULONG?????????????? outputBufferLength;
??? ULONG?????????????? ioControlCode;

??? //
??? // Go ahead and set the request up as successful
??? //
??? Irp->IoStatus.Status????? = STATUS_SUCCESS;
??? Irp->IoStatus.Information = 0;

??? //
??? // Get a pointer to the current location in the Irp. This is where
??? // the function codes and parameters are located.
??? //
??? irpStack = IoGetCurrentIrpStackLocation (Irp);

??? //
??? // Get the pointer to the input/output buffer and its length
??? //
??? inputBuffer??????? = Irp->AssociatedIrp.SystemBuffer;
??? inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;
??? outputBuffer?????? = Irp->AssociatedIrp.SystemBuffer;
??? outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
??? ioControlCode????? = irpStack->Parameters.DeviceIoControl.IoControlCode;

??? switch (irpStack->MajorFunction) {
??? case IRP_MJ_CREATE:

??????? DbgPrint(("Filemon: IRP_MJ_CREATE\n"));

??????? //
??????? // Start the sequence number at 0
??????? //
??????? Sequence = 0;
??????? break;

??? case IRP_MJ_CLOSE:

??????? DbgPrint(("Filemon: IRP_MJ_CLOSE\n"));

??????? //
??????? // A GUI is closing communication
??????? //
??????? FilterOn = FALSE;

??????? //
??????? // If the GUI has no more references to us, reset the output
??????? // buffers and hash table.
??????? //
??????? FilemonResetLog();
??????? FilemonHashCleanup();

??????? //
??????? // Stop capturing drives
??????? //
??????? HookDriveSet( 0, DeviceObject->DriverObject );
??????? UnhookSpecialFs( NPFS );
??????? UnhookSpecialFs( MSFS );
??????? break;

??? case IRP_MJ_DEVICE_CONTROL:

??????? //
??????? // This path will never execute because we have registered a
??????? // fast I/O path for device control. That means that the fast I/O entry
??????? // point will ALWAYS be called for Device Control operations
??????? //
??????? DbgPrint (("Filemon: IRP_MJ_DEVICE_CONTROL\n"));

??????? //
??????? // Get output buffer if its passed as an MDL
??????? //
??????? if( Irp->MdlAddress ) {

??????????? outputBuffer = MmGetSystemAddressForMdl( Irp->MdlAddress );
??????? }

??????? //
??????? // Its a request from the GUI. Simply call our fast handler.
??????? //
??????? FilemonFastIoDeviceControl( irpStack->FileObject, TRUE,
??????????????????????????????????? inputBuffer, inputBufferLength,
??????????????????????????????????? outputBuffer, outputBufferLength,
??????????????????????????????????? ioControlCode, &Irp->IoStatus, DeviceObject );
??????? break;
??? }

??? //
??? // Complete the IRP
??? //
??? IoCompleteRequest( Irp, IO_NO_INCREMENT );
??? return STATUS_SUCCESS;??
}

//=========================================================

//hook設(shè)備的功能函數(shù),在里面夾雜了處理GUI設(shè)備的IRP_MJ_DEVICE_CONTROL的代碼

//=========================================================
BOOLEAN
FilemonFastIoDeviceControl(
??? IN PFILE_OBJECT FileObject,
??? IN BOOLEAN Wait,
??? IN PVOID InputBuffer,
??? IN ULONG InputBufferLength,
??? OUT PVOID OutputBuffer,
??? IN ULONG OutputBufferLength,
??? IN ULONG IoControlCode,
??? OUT PIO_STATUS_BLOCK IoStatus,
??? IN PDEVICE_OBJECT DeviceObject
??? )
{
??? BOOLEAN???????????? retval = FALSE;
??? BOOLEAN???????????? logMutexReleased;
??? PHOOK_EXTENSION???? hookExt;
??? PLOG_BUF??????????? oldLog, savedCurrentLog;
??? CHAR??????????????? fullPathName[MAXPATHLEN], name[PROCNAMELEN], errorBuf[ERRORLEN];
??? KIRQL?????????????? oldirql;
??? LARGE_INTEGER?????? timeStampStart, timeStampComplete, timeResult;
??? LARGE_INTEGER?????? dateTime;

??? hookExt = DeviceObject->DeviceExtension;
??? if( hookExt->Type == GUIINTERFACE ) {

??????? //
??????? // Its a message from our GUI!
??????? //
??????? IoStatus->Status????? = STATUS_SUCCESS; // Assume success
??????? IoStatus->Information = 0;????? // Assume nothing returned

??????? switch ( IoControlCode ) {

??????? case IOCTL_FILEMON_VERSION:

??????????? //
??????????? // Version #
??????????? //
??????????? if( OutputBufferLength >= sizeof(ULONG)) {

??????????????? *(ULONG *)OutputBuffer = FILEMONVERSION;
??????????????? IoStatus->Information = sizeof(ULONG);

??????????? } else {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????? }???????????
??????????? break;

??????? case IOCTL_FILEMON_SETDRIVES:

??????????? //
??????????? // Hook and/or unhook drives
??????????? //
??????????? DbgPrint (("Filemon: set drives\n"));

??????????? if( InputBufferLength >= sizeof(ULONG) &&
???????????????? OutputBufferLength >= sizeof(ULONG)) {

??????????????? *(ULONG *)OutputBuffer = HookDriveSet( *(ULONG *)InputBuffer, DeviceObject->DriverObject );
??????????????? IoStatus->Information = sizeof(ULONG);

??????????? } else {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????? }
??????????? break;

??????? case IOCTL_FILEMON_HOOKSPECIAL:

??????????? if( InputBufferLength >= sizeof(FILE_SYSTEM_TYPE )) {

??????????????? if( !HookSpecialFs( DeviceObject->DriverObject, *(PFILE_SYSTEM_TYPE) InputBuffer )) {
???????????????
??????????????????? IoStatus->Status = STATUS_UNSUCCESSFUL;
??????????????? }
??????????? } else {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????? }
??????????? break;

??????? case IOCTL_FILEMON_UNHOOKSPECIAL:

??????????? if( InputBufferLength >= sizeof(FILE_SYSTEM_TYPE )) {

??????????????? UnhookSpecialFs( *(PFILE_SYSTEM_TYPE) InputBuffer );

??????????? } else {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????? }
??????????? break;

??????? case IOCTL_FILEMON_STOPFILTER:
???????????
??????????? //
??????????? // Turn off logging
??????????? //
??????????? DbgPrint(("Filemon: stop logging\n"));
??????????? FilterOn = FALSE;
??????????? break;

??????? case IOCTL_FILEMON_STARTFILTER:
?????????
??????????? //
??????????? // Turn on logging
??????????? //
??????????? DbgPrint(("Filemon: start logging\n"));
??????????? FilterOn = TRUE;
??????????? break;

??????? case IOCTL_FILEMON_SETFILTER:

??????????? //
??????????? // Gui is updating the filter functions
??????????? //
??????????? DbgPrint(("Filemon: set filter\n"));

??????????? if( InputBufferLength >= sizeof(FILTER) ) {

??????????????? FilterDef = *(PFILTER) InputBuffer;
??????????????? FilemonUpdateFilters();

??????????? } else {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????? }
??????????? break;

??????? case IOCTL_FILEMON_UNLOADQUERY:
#if DBG
??????????? //
??????????? // Is it possible to unload?
??????????? //
??????????? KeAcquireSpinLock( &CountMutex, &oldirql );
??????????? IoStatus->Information = OutstandingIRPCount;

??????????? //
??????????? // Any outstanding Irps?
??????????? //
??????????? if( !OutstandingIRPCount ) {

??????????????? //
??????????????? // Nope, so don't process anymore
??????????????? //
??????????????? UnloadInProgress = TRUE;

??????????????? KeReleaseSpinLock( &CountMutex, oldirql );

??????????????? //
??????????????? // Stop capturing drives
??????????????? //
??????????????? HookDriveSet( 0, DeviceObject->DriverObject );
??????????????? UnhookSpecialFs( NPFS );
??????????????? UnhookSpecialFs( MSFS );

??????????????? //
??????????????? // Detach from all devices
??????????????? //
??????????????? UnloadDetach();

??????????? } else {

??????????????? KeReleaseSpinLock( &CountMutex, oldirql );
??????????? }
#else // DBG
??????????? IoStatus->Information = 1;
#endif // DBG
??????????? break;

??????? case IOCTL_FILEMON_ZEROSTATS:

??????????? //
??????????? // Reset all output buffers
??????????? //
??????????? DbgPrint (("Filemon: zero stats\n"));

??????????? ExAcquireFastMutex( &LogMutex );

??????????? while( CurrentLog->Next ) {

??????????????? //
??????????????? // Free all but the first output buffer
??????????????? //
??????????????? oldLog = CurrentLog->Next;
??????????????? CurrentLog->Next = oldLog->Next;

??????????????? ExFreePool( oldLog );
??????????????? NumLog--;
??????????? }

??????????? //
??????????? // Set the output pointer to the start of the output buffer
??????????? //
??????????? CurrentLog->Len = 0;
??????????? Sequence = 0;

??????????? ExReleaseFastMutex( &LogMutex );
??????????? break;

??????? case IOCTL_FILEMON_GETSTATS:

??????????? //
??????????? // Copy the oldest output buffer to the caller
??????????? //
??????????? DbgPrint (("Filemon: get stats\n"));

??? //
??????????? // If the output buffer is too large to fit into the caller's buffer
??????????? //
??????????? if( LOGBUFSIZE > OutputBufferLength ) {

??????????????? IoStatus->Status = STATUS_BUFFER_TOO_SMALL;
??????????????? return FALSE;
??????????? }

??????????? //
??????????? // Probe the output buffer
??????????? //
??????????? try {????????????????

??????????????? ProbeForWrite( OutputBuffer,
?????????????????????????????? OutputBufferLength,
?????????????????????????????? sizeof( UCHAR ));

??????????? } except( EXCEPTION_EXECUTE_HANDLER ) {

??????????????? IoStatus->Status = STATUS_INVALID_PARAMETER;
??????????????? return FALSE;
??????????? }???????????

??????????? //
??????????? // We're okay, lock the buffer pool
??????????? //
??????????? ExAcquireFastMutex( &LogMutex );
??????????? if( CurrentLog->Len || CurrentLog->Next ) {

??????????????? //
??????????????? // Start output to a new output buffer
??????????????? //
??????????????? FilemonAllocateLog();

??????????????? //
??????????????? // Fetch the oldest to give to user
??????????????? //
??????????????? oldLog = FilemonGetOldestLog();

??????????????? if( oldLog != CurrentLog ) {

??????????????????? logMutexReleased = TRUE;
??????????????????? ExReleaseFastMutex( &LogMutex );

??????????????? } else {

??????????????????? logMutexReleased = FALSE;
??????????????? }

??????????????? //
??????????????? // Copy it to the caller's buffer
??????????????? //
??????????????? memcpy( OutputBuffer, oldLog->Data, oldLog->Len );

??????????????? //
??????????????? // Return length of copied info
??????????????? //
??????????????? IoStatus->Information = oldLog->Len;

??????????????? //
??????????????? // Deallocate buffer - unless its the last one
??????????????? //
??????????????? if( logMutexReleased ) {
???????????????????
??????????????????? ExFreePool( oldLog );

??????????????? } else {

??????????????????? CurrentLog->Len = 0;
??????????????????? ExReleaseFastMutex( &LogMutex );???????????????????
??????????????? }

??????????? } else {

??????????????? //
??????????????? // There is no unread data
??????????????? //
??????????????? ExReleaseFastMutex( &LogMutex );
???? IoStatus->Information = 0;
??????????? }
??????????? break;

??????? default:

??????????? //
??????????? // Unknown control
??????????? //
??????????? DbgPrint (("Filemon: unknown IRP_MJ_DEVICE_CONTROL\n"));
??????????? IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
??????????? break;
??????? }

??????? retval = TRUE;

??? } else {

??????? //
??????? // Its a call for a file system, so pass it through
??????? //
??????? if( FASTIOPRESENT( hookExt, FastIoDeviceControl ) ) {
???????
??????????? FilemonGetFullPath( FALSE, FileObject, hookExt, fullPathName );
??????????? TIMESTAMPSTART();

??????????? retval = hookExt->FileSystem->DriverObject->FastIoDispatch->FastIoDeviceControl(
??????????????? FileObject, Wait, InputBuffer, InputBufferLength, OutputBuffer,
??????????????? OutputBufferLength, IoControlCode, IoStatus, hookExt->FileSystem );

??????????? if(hookExt->Hooked) {

??????????????? TIMESTAMPSTOP();
??????????????? LogRecord( TRUE, NULL, &dateTime, &timeResult,
?????????????????????????? "%s\tFASTIO_DEVICE_CONTROL\t%s\tIOCTL: 0x%X\t%s",
?????????????????????????? FilemonGetProcess( name ), fullPathName,
?????????????????????????? IoControlCode,
?????????????????????????? retval ? ErrorString( IoStatus->Status, errorBuf ) : "FAILURE" );
??????????? }
??????? }
??? }

??? return retval;
}

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产欧美日韩91| 亚洲高清视频一区二区| 一本色道久久综合亚洲精品不| 亚洲伦理在线免费看| 欧美日本国产视频| 亚洲女女女同性video| 免费观看成人鲁鲁鲁鲁鲁视频| 亚洲精品久久久久久下一站 | 欧美亚洲一级| 在线日韩av永久免费观看| 欧美日韩美女一区二区| 欧美在线国产| 亚洲狼人综合| 老司机午夜精品视频| 亚洲综合成人在线| 亚洲国产欧美一区| 国产视频一区在线观看一区免费| 欧美日韩理论| 国产精品你懂的在线欣赏| 免费成人av资源网| 午夜精品久久久久久久久久久久 | 欧美aⅴ99久久黑人专区| 性久久久久久久久| 久久天堂精品| 欧美一区二区日韩一区二区| 一区二区三区高清在线 | 女生裸体视频一区二区三区 | 欧美成人精品一区二区| 欧美一区二区大片| 亚洲一区视频在线观看视频| 亚洲精品乱码久久久久久日本蜜臀 | 久久国产精品久久w女人spa| 亚洲一区国产一区| 久久久一本精品99久久精品66| 亚洲一级在线观看| 在线视频你懂得一区| 亚洲精品在线视频| 午夜精品久久久久久久久久久久久 | 欧美成人综合| 国产精品亚洲精品| 国产伦精品一区二区三区免费| 国产精品久久久久91| 欧美日韩在线播放| 国产综合婷婷| 国内成人精品视频| 99视频在线观看一区三区| 99re8这里有精品热视频免费| 亚洲人成77777在线观看网| 亚洲啪啪91| 欧美亚洲一级| 最新成人av网站| 亚洲精品中文在线| 久久av二区| 欧美日韩国产另类不卡| 国产精品videossex久久发布| 国产精品国产三级国产aⅴ入口| 在线观看欧美| 亚洲日本中文字幕| 久久人人爽人人| 免费久久99精品国产自| 亚洲视频1区| 欧美成人午夜| 红桃av永久久久| 亚洲国产天堂久久综合| 欧美在线视频免费观看| 另类欧美日韩国产在线| 亚洲无线视频| 欧美日韩午夜在线| 亚洲日本中文字幕| 免费看成人av| 久久av在线| 国产精品永久免费| 亚洲天堂偷拍| 久久成人羞羞网站| 一本色道88久久加勒比精品| 欧美二区在线观看| 国产精品伊人日日| 在线亚洲欧美视频| 亚洲人午夜精品免费| 久久久久久一区| 国产综合精品| 久久精品国产精品亚洲精品| 欧美护士18xxxxhd| 一区二区三区久久精品| 欧美精品麻豆| 国产一区二区三区在线观看精品 | 久久深夜福利免费观看| 欧美理论在线播放| 亚洲人体大胆视频| 欧美激情女人20p| 美女图片一区二区| 亚洲国产成人不卡| 欧美在线视频免费播放| 亚洲中午字幕| 国产欧美一区二区精品忘忧草| 午夜视频久久久久久| 欧美高清视频在线观看| 亚洲一区视频在线| 国产精品色婷婷| 欧美一区二区免费| 亚洲欧美一区二区三区极速播放 | 欧美一区激情| 国产在线拍偷自揄拍精品| 久久久久国产一区二区| 在线性视频日韩欧美| 国产精品久久久久国产a级| 午夜国产精品视频免费体验区| 亚洲视频1区| 国产亚洲精品bt天堂精选| 久久久久国产精品一区三寸| 久久蜜桃精品| 亚洲精品一区中文| 99精品免费| 欧美二区在线播放| 中文久久乱码一区二区| 亚洲一区二区三区激情| 国产日韩欧美三区| 久久夜色精品国产噜噜av| 裸体一区二区三区| 一本一本久久| 亚洲欧美日韩人成在线播放| 黑丝一区二区三区| 亚洲二区在线| 国产精品vip| 久久在线视频| 欧美精品在线看| 午夜精品视频在线观看| 久久久精品日韩欧美| 国产日韩欧美| 欧美国产一区二区三区激情无套| 欧美日韩福利| 久久国产精品毛片| 免费h精品视频在线播放| 亚洲午夜视频在线观看| 91久久中文| 国产欧美日韩视频| 欧美成人精品h版在线观看| 欧美日韩理论| 久久久久网址| 欧美精品在线一区二区| 欧美一区二区在线播放| 免费人成精品欧美精品| 亚洲欧洲一级| 国产精品99久久99久久久二8 | 久久黄金**| 亚洲乱码国产乱码精品精98午夜| 亚洲综合视频网| 亚洲理论电影网| 午夜视频精品| 国色天香一区二区| 亚洲九九精品| 国内激情久久| 一区二区三区国产盗摄| 在线日韩av| 亚洲欧美日韩成人高清在线一区| 亚洲欧洲一区二区在线播放| 亚洲欧美国产制服动漫| 在线视频欧美日韩| 久久亚洲一区二区| 欧美在线精品一区| 欧美日韩国产一区精品一区| 欧美+日本+国产+在线a∨观看| 国产精品视频自拍| 日韩网站在线观看| 国产麻豆精品久久一二三| 亚洲国产精品综合| 欧美日一区二区在线观看 | 欧美视频日韩视频| 亚洲国产精品电影| 国产中文一区| 亚洲性图久久| 在线一区二区三区做爰视频网站| 裸体素人女欧美日韩| 久久久久久久波多野高潮日日| 国产精品国产馆在线真实露脸 | 欧美一站二站| 亚洲欧美在线看| 欧美伦理视频网站| 欧美激情亚洲国产| 伊人激情综合| 欧美一区二区在线播放| 性久久久久久久久久久久| 欧美三级第一页| 日韩午夜电影av| 亚洲精选在线| 欧美激情视频网站| 亚洲国产高清在线| 亚洲国产精品va在线观看黑人| 欧美在线亚洲综合一区| 欧美中文在线观看| 国产精品网站在线| 亚洲一区免费网站| 亚洲女爱视频在线| 久久夜色精品国产欧美乱| 久久久久国产一区二区三区| 国产欧美综合在线| 性欧美video另类hd性玩具| 香港成人在线视频| 国产精品综合不卡av| 亚洲欧美国产高清|