extern "C" void
TCGetNTNameFromNumber (LPWSTR ntname, int nDriveNo)
{
WCHAR tmp[3] =
{0, ':', 0};
int j = nDriveNo + (WCHAR) 'A';
tmp[0] = (short) j;
wcscpy (ntname, (LPWSTR) NT_MOUNT_PREFIX);
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%d\"\n", nDriveNo));
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%s\"\n", ntname));
wcsncat (ntname, tmp, 1);
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%s\"\n", ntname));
}
extern "C" NTSTATUS
DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS ntStatus;
WCHAR dosname[32], ntname[32];
ULONG devChars = 0;
// 定义一个 Unicode 字符串
UNICODE_STRING ntUnicodeString;
//RtlInitUnicodeString(&nameString, L"\\FileSystem\\Filters\\SFilter");
DriverObject->DriverExtension->AddDevice = AddDevice;
KdPrint(("SFilter!DriverEntry\n"));
TCGetNTNameFromNumber (ntname, 3);
KdPrint(("SFilter!DriverEntry: Create Driver ntname = \"%s\"\n", &ntname));
RtlInitUnicodeString (&ntUnicodeString, ntname);
KdPrint(("SFilter!DriverEntry: Create Driver ntUnicodeString = \"%s\"\n", &ntUnicodeString));
----------------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
#endif
#include <ntddk.h>
#ifdef __cplusplus
}
#endif
#ifdef NT4_DRIVER
#define DRIVER_STR WIDE
#else
#define DRIVER_STR
#endif
#define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\TrueCryptVolume")
PDEVICE_OBJECT gSFilterDriverObject = NULL;
/**//* This structure is allocated for non-root devices! WARNING: bRootDevice
must be the first member of the structure! */
typedef struct EXTENSION
{
} EXTENSION, *PEXTENSION;
typedef struct _DEVICE_EXTENSION
{
PDEVICE_OBJECT fdo;
PDEVICE_OBJECT NextStackDevice;
UNICODE_STRING ifSymLinkName;
}DEVICE_EXTENSION, *PDEVICE_EXTENSION;
extern "C" NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject)
{
NTSTATUS status;
PDEVICE_OBJECT fdo;
status = IoCreateDevice(
DriverObject,
sizeof(DEVICE_EXTENSION),
NULL,
FILE_DEVICE_DISK,
0,
FALSE,
&fdo);
if( !NT_SUCCESS(status))
return status;
PDEVICE_EXTENSION dx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
dx->fdo = fdo;
dx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
fdo->Flags &= ~DO_DEVICE_INITIALIZING;
return STATUS_SUCCESS;
}
extern "C" void
TCGetNTNameFromNumber (LPWSTR ntname, int nDriveNo)
{
WCHAR tmp[3] =
{0, ':', 0};
int j = nDriveNo + (WCHAR) 'A';
tmp[0] = (short) j;
wcscpy (ntname, (LPWSTR) NT_MOUNT_PREFIX);
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%d\"\n", nDriveNo));
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%s\"\n", ntname));
KdPrint(("TCGetNTNameFromNumber: Create Driver tmp = \"%s\"\n", tmp));
wcsncat (ntname, tmp, 1);
KdPrint(("TCGetNTNameFromNumber: Create Driver ntname = \"%s\"\n", ntname));
}
extern "C" NTSTATUS
DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
WCHAR dosname[32], ntname[32];
ULONG devChars = 0;
// 定义一个 Unicode 字符串
UNICODE_STRING ntUnicodeString;
//RtlInitUnicodeString(&nameString, L"\\FileSystem\\Filters\\SFilter");
DriverObject->DriverExtension->AddDevice = AddDevice;
KdPrint(("SFilter!DriverEntry\n"));
TCGetNTNameFromNumber (ntname, 3);
KdPrint(("SFilter!DriverEntry: Create Driver ntname = \"%s\"\n", &ntname));
RtlInitUnicodeString (&ntUnicodeString, ntname);
KdPrint(("SFilter!DriverEntry: Create Driver ntUnicodeString = \"%s\"\n", &ntUnicodeString));
/**//*
devChars = FILE_DEVICE_SECURE_OPEN;
PDEVICE_OBJECT pDeviceObject = NULL;
// 创建虚拟设备
ntStatus = IoCreateDevice (
DriverObject, /* Our Driver Object * /
sizeof (EXTENSION), /* Size of state information * /
&ntUnicodeString, /* Device name "\Device\Name" * /
FILE_DEVICE_DISK, /* Device type * /
devChars, /* Device characteristics * /
FALSE, /* Exclusive device * /
&pDeviceObject); /* Returned ptr to Device Object * /
if ( !NT_SUCCESS( ntStatus ) )
{
KdPrint(("SFilter!DriverEntry: Error Creating Control Device Object \"%wZ\", status=%08x\n", &ntUnicodeString, ntStatus));
}
else
{
KdPrint(("SFilter!DriverEntry: Success Creating Control Device Object \"%wZ\", status=%08x\n", &ntUnicodeString, ntStatus));
}*/
return ntStatus;
}
---
代码改成了这样后, 调试依然会蓝屏。
SFilter!DriverEntry
TCGetNTNameFromNumber: Create Driver ntname = "3"
TCGetNTNameFromNumber: Create Driver ntname = "\Device\TrueCryptVolume"
TCGetNTNameFromNumber: Create Driver tmp = "D"
TCGetNTNameFromNumber: Create Driver ntname = "\Device\TrueCryptVolume"
SFilter!DriverEntry: Create Driver ntname = "\Device\TrueCryptVolume"
SFilter!DriverEntry: Create Driver ntUnicodeString = "H"
*** Fatal System Error: 0x0000007e
(0xC0000005,0x46656D61,0xF9EA2770,0xF9EA246C)
Break instruction exception - code 80000003 (first chance)
A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.
A fatal system error has occurred.
需要回滚代码。明天再继续。