I am trying to redirect the open of certain files to another file using a minifilter. Right now I am redirecting to a file on the same disk volume.
I started with the scanner.c example in the WDK. If the filename matches *.doc, I call:
FLT_PREOP_CALLBACK_STATUS ScanRedirect( PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects )
{
UNICODE_STRING us;
PWCHAR pBuffer;
PFILE_OBJECT FileObject;
NTSTATUS status;
FileObject = Data->Iopb->TargetFileObject;
RtlInitUnicodeString( &us, L"\Device\HardDiskVolume1\test.xxx");
pBuffer = (PWCHAR)ExAllocatePoolWithTag(NonPagedPool, us.MaximumLength, ‘EE00’ );
if ( !pBuffer )
return STATUS_INSUFFICIENT_RESOURCES;
RtlCopyMemory( pBuffer, us.Buffer, us.Length );
// Discard old name
if ( FileObject->FileName.Buffer ) {
ExFreePool(FileObject->FileName.Buffer );
}
FileObject->FileName.Length = us.Length;
FileObject->FileName.MaximumLength = us.MaximumLength;
FileObject->FileName.Buffer = pBuffer;
Data->IoStatus.Information = IO_REPARSE;
Data->IoStatus.Status = STATUS_REPARSE;
FltSetCallbackDataDirty( Data );
return STATUS_REPARSE;
}
But the redirect never works. CreateFile returns error: 317 “The system cannot find message for message number 317 in ‘system’”.
I tried just changing the existing buffer (avoiding the copy and allocate) and doing a reparse, but that gives the same results.
Any suggestions?