使用ZwCreateFile在驱动中打开文件,可是总是返回FILE_SUPERSEDED,导致打开失败!
WCHAR *pDescPath = L"\\??\\C:\\Fuck\\fuck.txt";
UNICODE_STRING unstr_descpath;
RtlInitUnicodeString(&unstr_descpath,pDescPath);
HANDLE hSrcFile, hDestFile;
PVOID buffer = NULL;
ULONG length = 0;
IO_STATUS_BLOCK Io_Status_Block = {0};
OBJECT_ATTRIBUTES obj_attrib;
NTSTATUS status;
BOOLEAN bRet = FALSE;
{
//初始化文件属性
InitializeObjectAttributes(&obj_attrib,
&unstr_descpath, //源文件名
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
// 打开源文件
status = ZwCreateFile( &hSrcFile,
GENERIC_READ | GENERIC_WRITE,
&obj_attrib,//包含要打开的文件名
&Io_Status_Block,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );
if(Io_Status_Block.Information == FILE_SUPERSEDED )
{
DbgPrint(("FILE_SUPERSEDED\n"));
//总是会进入此处
}
}
------解决方案--------------------
locStatus = ZwCreateFile(
&TempFile,
GENERIC_READ
------解决方案--------------------
GENERIC_WRITE,
&ObjAtt,
&ioStatusBlock,
&pdx->CacheFileSize,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE
------解决方案--------------------
FILE_RANDOM_ACCESS
------解决方案--------------------
FILE_SYNCHRONOUS_IO_NONALERT
------解决方案--------------------
FILE_NO_INTERMEDIATE_BUFFERING,
NULL,
0);