我挂了ZwSetInformationFile通过文件名进行过滤,但是不知道为什么,判断不成功!
NTSTATUS NewZwSetInformationFile(IN HANDLE  FileHandle,    
 OUT PIO_STATUS_BLOCK  IoStatusBlock,    
 IN PVOID  FileInformation,    
 IN ULONG  Length,    
 IN FILE_INFORMATION_CLASS  FileInformationClass    )
{

    PFILE_OBJECT pFileObject;
   NTSTATUS ret = ObReferenceObjectByHandle(FileHandle,GENERIC_READ,*IoFileObjectType,KernelMode,(PVOID*)&pFileObject,0);
    
   if(NT_SUCCESS(ret))
    {
if(!_wcsicmp(pFileObject->FileName.Buffer,L"\\Desk_top.ini"))
{
KdPrint(("FileName:%wZ \n",pFileObject->FileName.Buffer));
     return STATUS_ACCESS_DENIED;
     }
   }
   KdPrint(("DeleteFileName:%wZ \n",pFileObject->FileName.Buffer));
    
   return Old_ZwSetInformationFile(FileHandle,IoStatusBlock,FileInformation,Length,FileInformationClass);        
}

解决方案 »

  1.   

    傻的。没见过有人钩ZwSetInformationFile这么钩的,还专门去弄了个pFileObject想得到文件名是吧?FileInformationClass.FileName就OK乐
      

  2.   

    FileInformationClass.FileName 有这个么??FileInformationClass Value Meaning 
    FileBasicInformation 
    Change the information that is supplied in a FILE_BASIC_INFORMATION structure. The caller must have opened the file with the FILE_WRITE_ATTRIBUTES flag set in the DesiredAccess parameter. FileDispositionInformation 
    Usually, sets the DeleteFile member of a FILE_DISPOSITION_INFORMATION to TRUE, so the file can be deleted when ZwClose is called to release the last open handle to the file object. The caller must have opened the file with the DELETE flag set in the DesiredAccess parameter. FileEndOfFileInformation 
    Change the current end-of-file information, supplied in a FILE_END_OF_FILE_INFORMATION structure. The operation can either truncate or extend the file. The caller must have opened the file with the FILE_WRITE_DATA flag set in the DesiredAccess parameter.FileIoPriorityHintInformation 
    Change the current default IRP priority hint for the file handle. The new value is supplied in a FILE_IO_PRIORITY_HINT_INFORMATION structure.
    Note  This structure must be 8-byte aligned.
     
    FileLinkInformation Create a hard link to an existing file, which is specified in a FILE_LINK_INFORMATION structure. Not all file systems support hard links; for example NTFS does while FAT does not.
     
    FilePositionInformation 
    Change the current file information, which is stored in a FILE_POSITION_INFORMATION structure. FileRenameInformation 
    Change the current file name, which is supplied in a FILE_RENAME_INFORMATION structure. The caller must have DELETE access to the file. FileShortNameInformation 
    Change the current short file name, which is supplied in a FILE_NAME_INFORMATION structure. The file must be on an NTFS volume, and the caller must have opened the file with the DesiredAccess DELETE flag set in the DesiredAccess parameter. FileValidDataLengthInformation 
    Change the current valid data length for the file, which is supplied in a FILE_VALID_DATA_LENGTH_INFORMATION structure. The file must be on an NTFS volume, and the caller must have opened the file with the FILE_WRITE_DATA flag set in the DesiredAccess parameter. Nonadministrators and remote users must have the SeManageVolumePrivilege privilege. 
      

  3.   

    ObReferenceObjectByHandle returns an NTSTATUS value. The possible return values include:STATUS_SUCCESSSTATUS_OBJECT_TYPE_MISMATCHSTATUS_ACCESS_DENIEDSTATUS_INVALID_HANDLE
    根据返回值可以判断出原因。
      

  4.   

    说错了最后一个枚举写FileShortNameInformation,然后从(FILE_NAME_INFORMATION)FileInformation->FileName得文件名
      

  5.   

    不关FileObject的事情,FileObject一般在文件过滤驱动中才会用到
      

  6.   

    pFileObject->FileName.Buffer我印象中是全路径
    先输出pFileObject->FileName.Buffer看看是不是全路径。
      

  7.   

    你那个我没有想明白
    IN FILE_INFORMATION_CLASS  FileInformationClass是变量!!
    你那样不是写死了么,这个不是要看用户怎么调用!用户传的是什么枚举类型就是什么的!我比较菜,说错了理解下哈!
      

  8.   

    FILE_INFORMATION_CLASS是枚举参数。什么叫写死了?你想怎么活写?变量怎么了?
      

  9.   

    你根据FileInformationClass的值来确定用什么结构...Switch case一下
      

  10.   

    用ZwQueryInformationFile可以获取完整路径及名称。
    文件对象中的名称有时不是完整路径,而且不是一致有效的。
      

  11.   

    不知道为啥就是获取不到路径!FILE_NAME_INFORMATION si = {0};
        IO_STATUS_BLOCK isb = {0};
        NTSTATUS res= ZwQueryInformationFile(FileHandle,&isb,&si,sizeof(FILE_NAME_INFORMATION),FileNameInformation);
        
        if(NT_SUCCESS(res))
        {
         KdPrint(("FileName:[%s]",si.FileName));
        }
        KdPrint(("FileName ERROR %d",res));
      

  12.   

    输出缓冲区太小了,应该分配足够大小的缓冲区,再将缓冲区地址赋给一个FILE_NAME_INFORMATION型指针,用该指针访问返回的名称。