• <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>
            蝸牛的家
            男兒當自強
            posts - 48,  comments - 21,  trackbacks - 0

            #include 
            "ntddk.h"
            #include 
            "ntddkbd.h"
            #include 
            "stdio.h"        

            #define KEY_UP        1
            #define KEY_DOWN      0  

            #define LCONTROL      ((USHORT)0x1D)
            #define CAPS_LOCK      ((USHORT)0x3A)  

            PDEVICE_OBJECT HookDeviceObject;
            PDEVICE_OBJECT kbdDevice;              

            NTSTATUS KSnifferDispatchRead( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp );
            NTSTATUS KSnifferReadComplete( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context );
            NTSTATUS KSnifferDispatchGeneral(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp );                  

            NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)        
            {
                CCHAR         ntNameBuffer[
            64];
                STRING         ntNameString;
                UNICODE_STRING      ntUnicodeString;
                NTSTATUS            status;
                
                DbgPrint(
            "DriverEntry \n");
                DriverObject
            ->MajorFunction[IRP_MJ_READ] = KSnifferDispatchRead;    
                DriverObject
            ->MajorFunction[IRP_MJ_CREATE]        =
                DriverObject
            ->MajorFunction[IRP_MJ_CLOSE]          =
                DriverObject
            ->MajorFunction[IRP_MJ_FLUSH_BUFFERS]  =
                DriverObject
            ->MajorFunction[IRP_MJ_CLEANUP]        =
                DriverObject
            ->MajorFunction[IRP_MJ_DEVICE_CONTROL] = KSnifferDispatchGeneral; 

                sprintf( ntNameBuffer, 
            "\\Device\\KeyboardClass0" );
                RtlInitAnsiString( 
            &ntNameString, ntNameBuffer );
                RtlAnsiStringToUnicodeString( 
            &ntUnicodeString, &ntNameString, TRUE );
              
                status 
            = IoCreateDevice( DriverObject,          
                             
            0,
                             NULL,
                             FILE_DEVICE_KEYBOARD,
                             
            0,
                             FALSE,
                             
            &HookDeviceObject );            //建立一鍵盤類設備

                
            if!NT_SUCCESS(status) ) 
                
            {
                 DbgPrint(
            "Init Error\n");
                 RtlFreeUnicodeString( 
            &ntUnicodeString );
                 
            return STATUS_SUCCESS;
                }

                HookDeviceObject
            ->Flags |= DO_BUFFERED_IO;
                status 
            = IoAttachDevice( HookDeviceObject, &ntUnicodeString, &kbdDevice );      //連接我們的過濾設備到\\Device\\KeyboardClass0設備上
                if!NT_SUCCESS(status) ) 
                
            {
                 DbgPrint(
            "Connect with keyboard failed!\n");
                 IoDeleteDevice( HookDeviceObject );
                 RtlFreeUnicodeString( 
            &ntUnicodeString );
                 
            return STATUS_SUCCESS;
                }

                RtlFreeUnicodeString( 
            &ntUnicodeString );
                DbgPrint(
            "Successfully connected to keyboard device\n");
                
            return STATUS_SUCCESS;
            }



            NTSTATUS KSnifferDispatchRead( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp )        
            //有按鍵按下時執行
            {
                PIO_STACK_LOCATION currentIrpStack 
            = IoGetCurrentIrpStackLocation(Irp);        //獲取當前的IRP包
                PIO_STACK_LOCATION nextIrpStack    = IoGetNextIrpStackLocation(Irp);
                
            *nextIrpStack = *currentIrpStack;
                IoSetCompletionRoutine( Irp, KSnifferReadComplete, DeviceObject, TRUE, TRUE, TRUE );     
            //調用完成例程
                return IoCallDriver( kbdDevice, Irp );
            }


            NTSTATUS KSnifferReadComplete( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context )
            {
                PIO_STACK_LOCATION        IrpSp;
                PKEYBOARD_INPUT_DATA      KeyData;
                
                IrpSp 
            = IoGetCurrentIrpStackLocation( Irp );
                
            if( NT_SUCCESS( Irp->IoStatus.Status ) ) 
                
            {
                    KeyData 
            = Irp->AssociatedIrp.SystemBuffer;
                    DbgPrint(
            "ScanCode: %x ", KeyData->MakeCode );
                    DbgPrint(
            "%s\n", KeyData->Flags ? "Up" : "Down" );      //輸出按鍵的掃描碼

                    
            if( KeyData->MakeCode == CAPS_LOCK) 
                    
            {
                        KeyData
            ->MakeCode = LCONTROL;                  //修改按鍵
                    }
              
                }

                
            if( Irp->PendingReturned ) 
                
            {
                    IoMarkIrpPending( Irp );
                }


                
            return Irp->IoStatus.Status;
            }


            NTSTATUS KSnifferDispatchGeneral(                
            //通用事件處理例程
                IN PDEVICE_OBJECT DeviceObject,
                IN PIRP          Irp )
            {
                PIO_STACK_LOCATION currentIrpStack 
            = IoGetCurrentIrpStackLocation(Irp);
                PIO_STACK_LOCATION nextIrpStack    
            = IoGetNextIrpStackLocation(Irp);

                Irp
            ->IoStatus.Status      = STATUS_SUCCESS;
                Irp
            ->IoStatus.Information = 0

                
            if( DeviceObject == HookDeviceObject ) 
                
            {
                    
            *nextIrpStack = *currentIrpStack;
                    
            return IoCallDriver( kbdDevice, Irp );
                }

                
            else
                
            {
                    
            return STATUS_SUCCESS;
                }

            }

            posted on 2008-08-22 10:49 黑色天使 閱讀(2254) 評論(2)  編輯 收藏 引用 所屬分類: 操作系統

            FeedBack:
            # re: 鍵盤過濾驅動源代碼[未登錄]
            2009-02-02 14:14 | soul
            再怎么懶也該加上unload例程吧  回復  更多評論
              
            # re: 鍵盤過濾驅動源代碼
            2009-02-10 13:19 | 黑色天使
            @soul
            再怎么懶也應該自己實現一部分吧  回復  更多評論
              

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久午夜无码鲁丝片午夜精品| 久久99免费视频| 久久精品国产2020| 国产V综合V亚洲欧美久久| 精品99久久aaa一级毛片| 久久综合亚洲色HEZYO社区| 精品久久久久久无码专区| 久久精品国产精品亚洲人人| 少妇久久久久久久久久| 亚洲а∨天堂久久精品9966| 久久精品人人槡人妻人人玩AV | 亚洲级αV无码毛片久久精品| 久久亚洲精品成人AV| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久ZYZ资源站无码中文动漫 | 久久综合久久综合久久| 久久婷婷色综合一区二区| 99久久婷婷国产一区二区| 久久66热人妻偷产精品9| 久久天天躁狠狠躁夜夜2020一| 国产精品美女久久久免费| 人妻少妇久久中文字幕| 久久91精品国产91| 人妻无码久久精品| 欧美亚洲另类久久综合婷婷| 亚洲狠狠久久综合一区77777| 久久久久亚洲Av无码专| 国内精品久久久久久久久电影网| 亚洲美日韩Av中文字幕无码久久久妻妇 | 性做久久久久久久久久久| 国内精品久久国产大陆| 久久只有这精品99| 久久综合五月丁香久久激情| 久久久久亚洲精品中文字幕| 亚洲午夜精品久久久久久浪潮| 久久精品国产亚洲5555| 久久国产精品无码网站| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久乐国产精品亚洲综合| 天天影视色香欲综合久久| 99精品国产综合久久久久五月天|