/// on pch.h
#ifndef DWORD
#define DWORD ULONG
#endif
/// on cdoinit.c
VOID CdoInitializeDebugLevel (
__in PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
This routine tries to read the filter DebugLevel parameter from
the registry. This value will be found in the registry location
indicated by the RegistryPath passed in.
Arguments:
RegistryPath - The path key passed to the driver during DriverEntry.
Return Value:
None.
--*/
{
OBJECT_ATTRIBUTES attributes;
HANDLE driverRegKey;
NTSTATUS status;
ULONG resultLength;
UNICODE_STRING valueName;
UCHAR buffer[sizeof( KEY_VALUE_PARTIAL_INFORMATION ) + sizeof( LONG )];
Globals.DebugLevel = DEBUG_TRACE_ALL; // DEBUG_TRACE_ERROR;
return;
/// On CdoOperations.c
NTSTATUS
CdoHandlePrivateFsControl (
__in PDEVICE_OBJECT DeviceObject,
__in ULONG IoControlCode,
__in_bcount_opt(InputBufferLength) PVOID InputBuffer,
__in ULONG InputBufferLength,
__out_bcount_opt(OutputBufferLength) PVOID OutputBuffer,
__in ULONG OutputBufferLength,
__out PIO_STATUS_BLOCK IoStatus,
__in_opt PIRP Irp
)
/*++
Routine Description:
This routine is invoked whenever an I/O Request Packet (IRP) w/a major
function code of IRP_MJ_FILE_SYSTEM_CONTROL is encountered for the CDO.
Arguments:
DeviceObject - Pointer to the device object for this driver.
IoControlCode - Control code for this IOCTL
InputBuffer - Input buffer
InputBufferLength - Input buffer length
OutputBuffer - Output buffer
OutputBufferLength - Output buffer length
IoStatus - IO status block for this request
Irp - Pointer to the request packet representing the I/O request.
Return Value:
The function value is the status of the operation.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER( DeviceObject );
UNREFERENCED_PARAMETER( IoControlCode );
UNREFERENCED_PARAMETER( InputBuffer );
UNREFERENCED_PARAMETER( InputBufferLength );
UNREFERENCED_PARAMETER( OutputBuffer );
UNREFERENCED_PARAMETER( OutputBufferLength );
UNREFERENCED_PARAMETER( Irp );
PAGED_CODE();
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl entry ( Irp = %p )\n"
"\tIoControlCode = 0x%x\n"
"\tInputBuffer = %p\n"
"\tInputBufferLength = 0x%x\n"
"\tOutputBuffer = %p\n"
"\tOutputBufferLength = 0x%x\n",
Irp,
IoControlCode,
InputBuffer,
InputBufferLength,
OutputBuffer,
OutputBufferLength) );
CdoAcquireResourceShared( &Globals.Resource );
IoStatus->Status = status;
IoStatus->Information = 0;
//
// Sanity - there must atleast be a reference open for us to get a IOCTL on the CDO
//
ASSERT( FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF ) );
if (!FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE)) {
//
// If there is no handle open to the CDO fail the operation
//
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateFsControl -> Failing IOCTL since no handle to CDO is open. ( Irp = %p, IoControlCode = 0x%x, Flags = 0x%x )\n",
Irp,
IoControlCode,
Globals.Flags) );
status = STATUS_INVALID_DEVICE_STATE;
CdoReleaseResource( &Globals.Resource );
goto CdoHandlePrivateFsControlCleanup;
}
//
// Here the filter may perform any action that requires that
// the handle to the CDO still be open
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl -> Processing IOCTL while handle to CDO is definitely open. ( Irp = %p, IoControlCode = 0x%x )\n",
Irp,
IoControlCode) );
/// 假设的回答是: 输出参数 = 输入参数 + 1
if ((NULL != OutputBuffer)
&& (NULL != InputBuffer)
&& (InputBufferLength >= sizeof(DWORD))
&& (OutputBufferLength >= sizeof(DWORD)))
{
*((DWORD *)OutputBuffer) = *((DWORD *)InputBuffer) + 1;
IoStatus->Status = STATUS_SUCCESS;
IoStatus->Information = sizeof(DWORD);
}
else
{
IoStatus->Status = STATUS_INVALID_PARAMETER;
IoStatus->Information = 0;
}
CdoReleaseResource( &Globals.Resource );
//
// Since the resource has been released the CDO may complete a cleanup before we
// do any of the following.
//
//
// Here the filter may perform any action that does not require that
// the handle to the CDO still be open. For example, the IOCTL may have
// been used to trigger off an asynchronous background task that will
// continue executing even after the handle has been closed
//
// Note that the system will still maintain a reference to the CDO. So,
// the filter will not see a Close on the CDO until it finishes servicing
// IRP_MJ_FILE_SYSTEM_CONTROL
//
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl -> Processing IOCTL while handle to CDO may not be open. ( Irp = %p, IoControlCode = 0x%x )\n",
Irp,
IoControlCode) );
status = STATUS_SUCCESS;
CdoHandlePrivateFsControlCleanup:
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl exit ( Irp = %p, IoControlCode = 0x%x, status = 0x%x )\n",
Irp,
IoControlCode,
status) );
return status;
}