阅读:1085回复:0
关于文件过滤驱动显示全路径名的问题
各位老大帮忙看一下 下面是修改sfilter的代码 但是用着用着就蓝屏了(FileObject已经在外面限制不是null了)
PUNICODE_STRING SfGetFileName( IN PFILE_OBJECT FileObject, IN OUT PGET_NAME_CONTROL NameControl ) { POBJECT_NAME_INFORMATION nameInfo; NTSTATUS status; ULONG size; ULONG bufferSize; NameControl->allocatedBuffer = NULL; nameInfo = (POBJECT_NAME_INFORMATION)NameControl->smallBuffer; bufferSize = sizeof(NameControl->smallBuffer); status =RtlVolumeDeviceToDosName( (PVOID)FileObject->DeviceObject, &(nameInfo->Name)); size=nameInfo->Name.Length; DbgPrint(\"The Size is:%d \\n\",size); if (status == STATUS_BUFFER_OVERFLOW) { bufferSize = size + sizeof(WCHAR); NameControl->allocatedBuffer = ExAllocatePoolWithTag( NonPagedPool, bufferSize, SFLT_POOL_TAG ); if (NULL == NameControl->allocatedBuffer) { RtlInitEmptyUnicodeString( (PUNICODE_STRING)&NameControl->smallBuffer, (PWCHAR)(NameControl->smallBuffer + sizeof(UNICODE_STRING)), (USHORT)(sizeof(NameControl->smallBuffer) - sizeof(UNICODE_STRING)) ); return (PUNICODE_STRING)&NameControl->smallBuffer; } nameInfo = (POBJECT_NAME_INFORMATION)NameControl->allocatedBuffer; status =RtlVolumeDeviceToDosName( (PVOID)FileObject->DeviceObject, &(nameInfo->Name)); size=nameInfo->Name.Length; DbgPrint(\"The Size2 is:%d \\n\",size); } if (NT_SUCCESS( status )) { ULONG newSize; PCHAR newBuffer; POBJECT_NAME_INFORMATION newNameInfo; newSize = size + FileObject->FileName.Length; if (NULL != FileObject->RelatedFileObject) { newSize += FileObject->RelatedFileObject->FileName.Length + sizeof(WCHAR); } if (newSize > bufferSize) { newBuffer = ExAllocatePoolWithTag( NonPagedPool, newSize, SFLT_POOL_TAG ); if (NULL == newBuffer) { RtlInitEmptyUnicodeString( (PUNICODE_STRING)&NameControl->smallBuffer, (PWCHAR)(NameControl->smallBuffer + sizeof(UNICODE_STRING)), (USHORT)(sizeof(NameControl->smallBuffer) - sizeof(UNICODE_STRING)) ); return (PUNICODE_STRING)&NameControl->smallBuffer; } newNameInfo = (POBJECT_NAME_INFORMATION)newBuffer; RtlInitEmptyUnicodeString( &newNameInfo->Name, (PWCHAR)(newBuffer + sizeof(OBJECT_NAME_INFORMATION)), (USHORT)(newSize - sizeof(OBJECT_NAME_INFORMATION)) ); RtlCopyUnicodeString( &newNameInfo->Name, &nameInfo->Name ); if (NULL != NameControl->allocatedBuffer) { ExFreePool( NameControl->allocatedBuffer ); } NameControl->allocatedBuffer = newBuffer; bufferSize = newSize; nameInfo = newNameInfo; } else { nameInfo->Name.MaximumLength = (USHORT)(bufferSize - sizeof(OBJECT_NAME_INFORMATION)); } if (NULL != FileObject->RelatedFileObject) { DbgPrint(\"FileObject->RelatedFileObject->FileName: %ws\",&(FileObject->RelatedFileObject->FileName.Buffer)); RtlAppendUnicodeStringToString( &nameInfo->Name, &FileObject->RelatedFileObject->FileName ); RtlAppendUnicodeToString( &nameInfo->Name, L\"\\\\\" ); } DbgPrint(\"FileObject->FileName:\",&(FileObject->FileName.Buffer)); RtlAppendUnicodeStringToString( &nameInfo->Name, &FileObject->FileName ); ASSERT(nameInfo->Name.Length <= nameInfo->Name.MaximumLength); } return &nameInfo->Name; } [编辑 - 5/16/05 by yuzhe] |
|