⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iphookglobal.h

📁 WMD驱动编程,本人收集整理的10多个例子和编程环境配置文档,特别是8139驱动,加了许多说明,并测试通过.
💻 H
字号:
///////////////////////////////////////////////////////////////////////////////
//
//	(C) Copyright 1999 - 2000 Mark Roddy
//	All Rights Reserved
//
//	Hollis Technology Solutions
//	94 Dow Road
//	Hollis, NH 03049
//	info@hollistech.com
//
//	Synopsis: 
// 
//
//	Version Information:
//
//	$Header: /iphook/sys/driver/IpHookGlobal.h 4     1/27/00 10:35p Markr $ 
//
///////////////////////////////////////////////////////////////////////////////
#pragma once
//
// this was a simple structure but alas it has developed class
// it ought to be a class in fact and as it is the single global
// data object it ought to enforce its singleton nature.
//
class IP_HOOK_GLOBAL_DATA {

private:

	//
	// we track the thread that started a hook
	//
	PVOID owningContext;
	PDEVICE_OBJECT IpfDeviceObject;
	PFILE_OBJECT IpfFileObject;
	ULONG IpHookSequence;
	//
	// we don't know what the actual situation
	// is here - are we called serially at our
	// hook function? Are we called at DISPATCH_LEVEL?
	//
	// until we figure this out use a spinlock.
	// 
	spinLock Lock;
	
	LIST_ENTRY queue;
	LIST_ENTRY cancelQueue;
	PIRP currentIrp;
	PIPHOOK_BUFFER currentBuffer;

	//
	// a worker thread wakes up every now and then and flushes the
	// current buffer
	//
	HANDLE  workerThread;
	PVOID workerThreadObject;
	KEVENT	 stopEvent;


public:

	NTSTATUS createThread();

	NTSTATUS initDevice();

	void queueRequest(PIRP Irp);

	PIRP popQueue(BOOLEAN locked = FALSE);	

	PIPHOOK_DATA getBuffer();

	void flushBuffer(BOOLEAN locked = FALSE);

	void flushBufferIfData();

	void releaseAllBuffers(BOOLEAN locked = FALSE);

	IP_HOOK_GLOBAL_DATA();

	~IP_HOOK_GLOBAL_DATA();

	BOOLEAN IsOwner(PVOID context)
	{
		if (context == owningContext) {

			return TRUE;
		}

		return FALSE;
	}

	BOOLEAN owned()
	{
		return (owningContext != NULL);
	}

	PVOID owner()
	{
		return owningContext;
	}

	BOOLEAN setOwner(PVOID context)
	{
		//
		// we sort of kinda hafta serialize this
		//
		PVOID inUse = 
			InterlockedCompareExchangePointer(&owningContext, 
											  context,
											  NULL);

		if (inUse != NULL) {

			return FALSE;
		}

		return TRUE;
	}

	void freeOwner(PVOID context)
	{
		PVOID lockContext;

		lock(lockContext);

		if (IsOwner(context)) {

			releaseAllBuffers(TRUE);
			
			InterlockedExchangePointer(&owningContext, NULL);
		}

		unlock(lockContext);
	}

	ULONG getSequence()
	{
		return InterlockedIncrement((PLONG)&IpHookSequence);
	}

	PDEVICE_OBJECT getIpDevice()
	{
		return IpfDeviceObject;
	}

	void lock(PVOID& context)
	{
		Lock.lock(context);
	}

	void unlock(PVOID context)
	{
		Lock.unlock(context);
	}

};
///////////////////////////////////////////////////////////////////////////////
// 
// Change History Log
//
// $Log: /iphook/sys/driver/IpHookGlobal.h $
// 
// 4     1/27/00 10:35p Markr
// Prepare to release!
//
///////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -