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

📄 debug.c

📁 FSD file system driver
💻 C
📖 第 1 页 / 共 5 页
字号:
/* 
 * FFS File System Driver for Windows
 *
 * debug.c
 *
 * 2004.5.6 ~
 *
 * Lee Jae-Hong, http://www.pyrasis.com
 *
 * See License.txt
 *
 */

#if DBG

#include "ntifs.h"
#include "ffsdrv.h"
#include "stdarg.h"
#include "stdio.h"


/* Globals */

extern PFFS_GLOBAL FFSGlobal;

#define SYSTEM_PROCESS_NAME "System"

extern PFFS_GLOBAL FFSGlobal;

LONG   DebugLevel = DBG_USER;

ULONG  ProcessNameOffset = 0;

/* Definitions */

#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, FFSPrintf)
#pragma alloc_text (PAGE, FFSNIPrintf)
#pragma alloc_text (PAGE, FFSGetProcessNameOffset)
#pragma alloc_text (PAGE, FFSDbgPrintCall)
#pragma alloc_text (PAGE, FFSDbgPrintComplete)
#pragma alloc_text (PAGE, FFSNtStatusToString)
#endif // ALLOC_PRAGMA

/* Static Definitions ****************************************************/

static PUCHAR IrpMjStrings[] = {
	"IRP_MJ_CREATE",
	"IRP_MJ_CREATE_NAMED_PIPE",
	"IRP_MJ_CLOSE",
	"IRP_MJ_READ",
	"IRP_MJ_WRITE",
	"IRP_MJ_QUERY_INFORMATION",
	"IRP_MJ_SET_INFORMATION",
	"IRP_MJ_QUERY_EA",
	"IRP_MJ_SET_EA",
	"IRP_MJ_FLUSH_BUFFERS",
	"IRP_MJ_QUERY_VOLUME_INFORMATION",
	"IRP_MJ_SET_VOLUME_INFORMATION",
	"IRP_MJ_DIRECTORY_CONTROL",
	"IRP_MJ_FILE_SYSTEM_CONTROL",
	"IRP_MJ_DEVICE_CONTROL",
	"IRP_MJ_INTERNAL_DEVICE_CONTROL",
	"IRP_MJ_SHUTDOWN",
	"IRP_MJ_LOCK_CONTROL",
	"IRP_MJ_CLEANUP",
	"IRP_MJ_CREATE_MAILSLOT",
	"IRP_MJ_QUERY_SECURITY",
	"IRP_MJ_SET_SECURITY",
	"IRP_MJ_POWER",
	"IRP_MJ_SYSTEM_CONTROL",
	"IRP_MJ_DEVICE_CHANGE",
	"IRP_MJ_QUERY_QUOTA",
	"IRP_MJ_SET_QUOTA",
	"IRP_MJ_PNP"
};

static PUCHAR FileInformationClassStrings[] = {
	"Unknown FileInformationClass 0",
	"FileDirectoryInformation",
	"FileFullDirectoryInformation",
	"FileBothDirectoryInformation",
	"FileBasicInformation",
	"FileStandardInformation",
	"FileInternalInformation",
	"FileEaInformation",
	"FileAccessInformation",
	"FileNameInformation",
	"FileRenameInformation",
	"FileLinkInformation",
	"FileNamesInformation",
	"FileDispositionInformation",
	"FilePositionInformation",
	"FileFullEaInformation",
	"FileModeInformation",
	"FileAlignmentInformation",
	"FileAllInformation",
	"FileAllocationInformation",
	"FileEndOfFileInformation",
	"FileAlternateNameInformation",
	"FileStreamInformation",
	"FilePipeInformation",
	"FilePipeLocalInformation",
	"FilePipeRemoteInformation",
	"FileMailslotQueryInformation",
	"FileMailslotSetInformation",
	"FileCompressionInformation",
	"FileObjectIdInformation",
	"FileCompletionInformation",
	"FileMoveClusterInformation",
	"FileQuotaInformation",
	"FileReparsePointInformation",
	"FileNetworkOpenInformation",
	"FileAttributeTagInformation",
	"FileTrackingInformation"
};

static PUCHAR FsInformationClassStrings[] = {
	"Unknown FsInformationClass 0",
	"FileFsVolumeInformation",
	"FileFsLabelInformation",
	"FileFsSizeInformation",
	"FileFsDeviceInformation",
	"FileFsAttributeInformation",
	"FileFsControlInformation",
	"FileFsFullSizeInformation",
	"FileFsObjectIdInformation"
};

/*
 * FFSPrintf
 *   This function is variable-argument, level-sensitive debug print routine.
 *   If the specified debug level for the print statement is lower or equal
 *   to the current debug level, the message will be printed.
 *
 * Arguments:
 *   DebugPrintLevel - Specifies at which debugging level the string should
 *                     be printed
 *   DebugMessage - Variable argument ascii c string
 *
 * Return Value:
 *   N/A
 *
 * NOTES: 
 *   N/A
 */

VOID
FFSPrintf(
	LONG  DebugPrintLevel,
	PCHAR DebugMessage,
	...)
{
	va_list             ap;
	LARGE_INTEGER       CurrentTime;
	TIME_FIELDS         TimeFields;

	ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

	if (DebugPrintLevel <= DebugLevel)
	{
		CHAR Buffer[0x100];
		va_start(ap, DebugMessage);

		KeQuerySystemTime(&CurrentTime);
		RtlTimeToTimeFields(&CurrentTime, &TimeFields);

		vsprintf(Buffer, DebugMessage, ap);

		DbgPrint(DRIVER_NAME": %2.2d:%2.2d:%2.2d:%3.3d %8.8x:   %s",
				TimeFields.Hour, TimeFields.Minute,
				TimeFields.Second, TimeFields.Milliseconds,
				PsGetCurrentThread(), Buffer);

		va_end(ap);
	}


	ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

} // FFSPrintf()


/*
 * FFSNIPrintf
 *   This function is variable-argument, level-sensitive debug print routine.
 *   If the specified debug level for the print statement is lower or equal
 *   to the current debug level, the message will be printed.
 *
 * Arguments:
 *   DebugPrintLevel - Specifies at which debugging level the string should
 *                     be printed
 *   DebugMessage - Variable argument ascii c string
 *
 * Return Value:
 *   N/A
 *
 * NOTES: 
 *   N/A
 */

VOID
FFSNIPrintf(
	LONG  DebugPrintLevel,
	PCHAR DebugMessage,
	...)
{
	va_list             ap;
	LARGE_INTEGER       CurrentTime;
	TIME_FIELDS         TimeFields;

	ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

	if (DebugPrintLevel <= DebugLevel)
	{
		CHAR Buffer[0x100];
		va_start(ap, DebugMessage);

		KeQuerySystemTime(&CurrentTime);
		RtlTimeToTimeFields(&CurrentTime, &TimeFields);

		vsprintf(Buffer, DebugMessage, ap);

		DbgPrint(DRIVER_NAME": %2.2d:%2.2d:%2.2d:%3.3d %8.8x: %s",
				TimeFields.Hour, TimeFields.Minute,
				TimeFields.Second, TimeFields.Milliseconds,
				PsGetCurrentThread(), Buffer);

		va_end(ap);
	}


	ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

} // FFSNIPrintf()

ULONG 
FFSGetProcessNameOffset(
	VOID)
{
	PEPROCESS   Process;
	ULONG       i;

	Process = PsGetCurrentProcess();

	for(i = 0; i < PAGE_SIZE; i++)
	{
		if(!strncmp(
					SYSTEM_PROCESS_NAME,
					(PCHAR) Process + i,
					strlen(SYSTEM_PROCESS_NAME)))
		{
			return i;
		}
	}

	FFSPrint((DBG_ERROR, ": *** FsdGetProcessNameOffset failed ***\n"));

	return 0;
}


VOID
FFSDbgPrintCall(
	IN PDEVICE_OBJECT   DeviceObject,
	IN PIRP             Irp)
{
	PIO_STACK_LOCATION      IoStackLocation;
	PFILE_OBJECT            FileObject;
	PUCHAR                  FileName;
	PFFS_FCB                Fcb;
	FILE_INFORMATION_CLASS  FileInformationClass;
	FS_INFORMATION_CLASS    FsInformationClass;

	IoStackLocation = IoGetCurrentIrpStackLocation(Irp);

	FileObject = IoStackLocation->FileObject;

	FileName = "Unknown";

	if (DeviceObject == FFSGlobal->DeviceObject)
	{
		FileName = "\\" DRIVER_NAME;
	}
	else if (FileObject && FileObject->FsContext)
	{
		Fcb = (PFFS_FCB)FileObject->FsContext;

		if (Fcb->Identifier.Type == FFSVCB)
		{
			FileName = "\\Volume";
		}
		else if (Fcb->Identifier.Type == FFSFCB && Fcb->AnsiFileName.Buffer)
		{
			FileName = Fcb->AnsiFileName.Buffer;
		}
	}

	switch (IoStackLocation->MajorFunction)
	{
		case IRP_MJ_CREATE:

			FileName = NULL;

			if (DeviceObject == FFSGlobal->DeviceObject)
			{
				FileName = "\\" DRIVER_NAME;
			}
			else if (IoStackLocation->FileObject->FileName.Length == 0)
			{
				FileName = "\\Volume";
			}

			if (FileName)
			{
				FFSPrintNoIndent((
							DBG_TRACE, "%s %s %s\n",
							FFSGetCurrentProcessName(),
							IrpMjStrings[IoStackLocation->MajorFunction],

⌨️ 快捷键说明

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