阅读:1208回复:1
求驱动程序里直接读写磁盘文件的源代码
小弟最近学写驱动,要在驱动程序里读取磁盘文件内容,可不知道怎么实现,求各位大牛附上实现读写的源代码,万分感谢。急急!!!!!1
|
|
沙发#
发布于:2008-04-15 00:33
RtlInitUnicodeString(&FileName, L"\\SystemRoot\\xxx.dat");
InitializeObjectAttributes(&ObjectAttributes, &FileName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL ); Status = ZwCreateFile(FileHandle, (SYNCHRONIZE | FILE_READ_DATA), &ObjectAttributes, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NO_INTERMEDIATE_BUFFERING, NULL, 0 ); if (!NT_SUCCESS(Status)) { *FileHandle = NULL; break; } Status = ZwQueryInformationFile(*FileHandle, &IoStatus, &StandardInfo, sizeof(FILE_STANDARD_INFORMATION), FileStandardInformation ); if (!NT_SUCCESS(Status)) { ZwClose(*FileHandle); *FileHandle = NULL; break; } Length = StandardInfo.EndOfFile.LowPart; buffer =ExAllocatePoolWithTag(NonPagedPool, Length , SFLT_POOL_TAG_MYSELF); Status = ZwReadFile(*FileHandle, NULL, NULL, NULL, &IoStatus, buffer, Length, NULL, NULL ); |
|