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

📄 fastio.cpp

📁 一个过滤层文件系统驱动的完整代码,实现了文件的加密,操作截获等
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	PAGED_CODE();
	ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));

	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;

	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoQueryOpen )) {

			PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );

			irpSp->DeviceObject = deviceObject;

			result = (fastIoDispatch->FastIoQueryOpen)(
				Irp,
				NetworkInformation,
				deviceObject );

			if (!result) {

				irpSp->DeviceObject = DeviceObject;
			}
			return result;
		}
	}
	return FALSE;
}

//----------------------------------------------------------------------
//
// FsTPMFastIoAcquireFile
//
//----------------------------------------------------------------------
VOID 
FsTPMFastIoAcquireFile( 
						 PFILE_OBJECT FileObject 
						 ) 
{
	// 暂不予支持
	return ;

	FsTPM_DbgPrint(("->FsTPMFastIoAcquireFile \n"));

	PDEVICE_OBJECT      deviceObject, checkDevice;
	PHOOK_EXTENSION     hookExt;
	PFAST_IO_DISPATCH fastIoDispatch;


	//
	// We've got to locate our own device object
	//
	checkDevice = FileObject->DeviceObject->Vpb->DeviceObject;
	while( checkDevice ) {

		if( checkDevice->DriverObject == FsTPMDriverObject ) {

			//
			// Found it
			//
			deviceObject = checkDevice;
			hookExt = (PHOOK_EXTENSION)deviceObject->DeviceExtension;
			fastIoDispatch=hookExt->Vcb.NextLowerDevice->DriverObject->FastIoDispatch;

			if (VALID_FAST_IO_DISPATCH_HANDLER(fastIoDispatch, AcquireFileForNtCreateSection))
			{


				fastIoDispatch->AcquireFileForNtCreateSection( FileObject );
			}
			return;
		}
		checkDevice = checkDevice->AttachedDevice;
	}
}


//----------------------------------------------------------------------
//
// FsTPMFastIoReleaseFile
//
//----------------------------------------------------------------------
VOID 
FsTPMFastIoReleaseFile( 
						 PFILE_OBJECT FileObject 
						 ) 
{
	// 暂不予支持
	return ;

	FsTPM_DbgPrint(("->FsTPMFastIoReleaseFile \n"));

	PDEVICE_OBJECT      deviceObject, checkDevice;
	PHOOK_EXTENSION     hookExt;
	PFAST_IO_DISPATCH fastIoDispatch;


	//
	// We've got to locate our own device object
	//
	checkDevice = FileObject->DeviceObject->Vpb->DeviceObject;
	while( checkDevice ) {

		if( checkDevice->DriverObject == FsTPMDriverObject ) {

			//
			// Found it
			//

			deviceObject = checkDevice;
			hookExt = (PHOOK_EXTENSION)deviceObject->DeviceExtension;
			fastIoDispatch=hookExt->Vcb.NextLowerDevice->DriverObject->FastIoDispatch;

			if (VALID_FAST_IO_DISPATCH_HANDLER(fastIoDispatch, AcquireFileForNtCreateSection))
			{

				fastIoDispatch->ReleaseFileForNtCreateSection( FileObject );
			}
			return;
		}
		checkDevice = checkDevice->AttachedDevice;
	}
}


NTSTATUS
FsTPMFastIoAcquireForModWrite(
								IN  PFILE_OBJECT    FileObject,
								IN  PLARGE_INTEGER  EndingOffset,
								OUT PERESOURCE     *ResourceToRelease,
								IN  PDEVICE_OBJECT  DeviceObject
								)
								/*++

								Routine Description:

								This routine is the fast I/O "pass through" routine for acquiring the
								file resource prior to attempting a modified write operation.

								This function simply invokes the next driver's cooresponding routine, or
								returns FALSE if the next driver does not implement the function.

								Arguments:

								FileObject - Pointer to the file object whose resource is to be acquired.

								EndingOffset - The offset to the last byte being written plus one.

								ResourceToRelease - Pointer to a variable to return the resource to 
								release.  Not defined if an error is returned.

								DeviceObject - Pointer to this driver's device object, the device on
								which the operation is to occur.

								Return Value:

								The function value is either success or failure based on whether or not
								fast I/O is possible for this file.

								--*/
{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoAcquireForModWrite \n"));

	PDEVICE_OBJECT    deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;
	NTSTATUS          returnStatus;

	PAGED_CODE();

	if (DeviceObject->DeviceExtension == NULL)
	{
		return STATUS_INVALID_DEVICE_REQUEST;
	}

	//
	// Pass through logic for this type of Fast I/O
	//
	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (!deviceObject) 
	{
		return STATUS_INVALID_DEVICE_REQUEST;  
	}
	fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

	if (VALID_FAST_IO_DISPATCH_HANDLER(fastIoDispatch, AcquireForModWrite)) {
		returnStatus = (fastIoDispatch->AcquireForModWrite)( FileObject,
			EndingOffset,
			ResourceToRelease,
			DeviceObject);
	} else {
		returnStatus = STATUS_INVALID_DEVICE_REQUEST;
	}

	return returnStatus;

}


NTSTATUS
FsTPMFastIoReleaseForModWrite(
								IN PFILE_OBJECT   FileObject,
								IN PERESOURCE     ResourceToRelease,
								IN PDEVICE_OBJECT DeviceObject
								)
								/*++

								Routine Description:

								This routine is the fast I/O "pass through" routine for releasing the
								resource previously acquired for performing a modified write operation
								to a file.

								This function simply invokes the next driver's cooresponding routine, or
								returns FALSE if the next driver does not implement the function.

								Arguments:

								FileObject - Pointer to the file object whose resource is to be released.

								ResourceToRelease - Specifies the modified writer resource for the file
								that is to be released.

								DeviceObject - Pointer to this driver's device object, the device on
								which the operation is to occur.

								Return Value:

								The function value is either success or failure based on whether or not
								fast I/O is possible for this file.

								--*/
{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoReleaseForModWrite \n"));

	PDEVICE_OBJECT    deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;
	NTSTATUS          returnStatus;

	PAGED_CODE();

	if (DeviceObject->DeviceExtension == NULL)
	{
		return STATUS_INVALID_DEVICE_REQUEST;
	}

	//
	// Pass through logic for this type of Fast I/O
	//
	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (!deviceObject) 
	{
		return STATUS_INVALID_DEVICE_REQUEST;  
	}
	fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;


	if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, ReleaseForModWrite )) 
	{
		returnStatus = (fastIoDispatch->ReleaseForModWrite)( FileObject,
			ResourceToRelease,
			DeviceObject);
	}
	else
	{
		returnStatus = STATUS_INVALID_DEVICE_REQUEST;
	}
	return returnStatus;
}


NTSTATUS
FsTPMFastIoAcquireForCcFlush(
							   IN PFILE_OBJECT   FileObject,
							   IN PDEVICE_OBJECT DeviceObject
							   )
							   /*++

							   Routine Description:

							   This routine is the fast I/O "pass through" routine for acquiring the
							   appropriate file system resource prior to a call to CcFlush.

							   This function simply invokes the next driver's cooresponding routine, or
							   returns FALSE if the next driver does not implement the function.

							   Arguments:

							   FileObject - Pointer to the file object whose resource is to be acquired.

							   DeviceObject - Pointer to this driver's device object, the device on
							   which the operation is to occur.

							   Return Value:

							   The function value is either success or failure based on whether or not
							   fast I/O is possible for this file.

							   --*/
{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoAcquireForCcFlush \n"));

	PDEVICE_OBJECT    deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;
	NTSTATUS          returnStatus;

	if (DeviceObject->DeviceExtension == NULL) {
		return STATUS_INVALID_DEVICE_REQUEST;
	}

	//
	// Pass through logic for this type of Fast I/O
	//
	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (!deviceObject) 
	{
		return STATUS_INVALID_DEVICE_REQUEST;  
	}
	fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

	if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, AcquireForCcFlush )) {
		returnStatus = (fastIoDispatch->AcquireForCcFlush)( FileObject,
			DeviceObject);
	} else {
		returnStatus = STATUS_INVALID_DEVICE_REQUEST;
	}


	return returnStatus;
}


NTSTATUS
FsTPMFastIoReleaseForCcFlush(
							   IN PFILE_OBJECT   FileObject,
							   IN PDEVICE_OBJECT DeviceObject
							   )
							   /*++

							   Routine Description:

							   This routine is the fast I/O "pass through" routine for releasing the
							   appropriate file system resource previously acquired for a CcFlush.

							   This function simply invokes the next driver's cooresponding routine, or
							   returns FALSE if the next driver does not implement the function.

							   Arguments:

							   FileObject - Pointer to the file object whose resource is to be released.

							   DeviceObject - Pointer to this driver's device object, the device on
							   which the operation is to occur.

							   Return Value:

							   The function value is either success or failure based on whether or not
							   fast I/O is possible for this file.

							   --*/
{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoReleaseForCcFlush \n"));

	PDEVICE_OBJECT    deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;
	NTSTATUS          returnStatus;

	if (DeviceObject->DeviceExtension == NULL) {
		return STATUS_INVALID_DEVICE_REQUEST;
	}

	//
	// Pass through logic for this type of Fast I/O
	//
	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (!deviceObject) 
	{
		return STATUS_INVALID_DEVICE_REQUEST;  
	}
	fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

	if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, ReleaseForCcFlush )) {
		returnStatus = (fastIoDispatch->ReleaseForCcFlush)( FileObject,
			DeviceObject);
	} else {
		returnStatus = STATUS_INVALID_DEVICE_REQUEST;
	}

	return returnStatus;
}



//
// This FsTPM's Fast I/O dispatch table. Note that NT assumes that
// file system drivers support some Fast I/O calls, so this table must
// be present for an file system filter driver
//
FAST_IO_DISPATCH    FastIOHook = {
	sizeof(FAST_IO_DISPATCH), 
		FsTPMFastIoCheckIfPossible,
		FsTPMFastIoRead,
		FsTPMFastIoWrite,
		FsTPMFastIoQueryBasicInfo,
		FsTPMFastIoQueryStandardInfo,
		FsTPMFastIoLock,
		FsTPMFastIoUnlockSingle,
		FsTPMFastIoUnlockAll,
		FsTPMFastIoUnlockAllByKey,
		FsTPMFastIoDeviceControl,
		FsTPMFastIoAcquireFile,
		FsTPMFastIoReleaseFile,
		FsTPMFastIoDetachDevice,

		//
		// new for NT 4.0
		//
		FsTPMFastIoQueryNetworkOpenInfo,
		FsTPMFastIoAcquireForModWrite,
		FsTPMFastIoMdlRead,
		FsTPMFastIoMdlReadComplete,
		FsTPMFastIoPrepareMdlWrite,
		FsTPMFastIoMdlWriteComplete,
		FsTPMFastIoReadCompressed,
		FsTPMFastIoWriteCompressed,
		FsTPMFastIoMdlReadCompleteCompressed,
		FsTPMFastIoMdlWriteCompleteCompressed,
		FsTPMFastIoQueryOpen,
		FsTPMFastIoReleaseForModWrite,
		FsTPMFastIoAcquireForCcFlush,
		FsTPMFastIoReleaseForCcFlush
};



















⌨️ 快捷键说明

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