如何在Windows内核中获取文件大小
How to get file size in Windows kernel
我需要在Windows内核中获取文件大小。我将文件读入内核中的缓冲区,而代码如下。我挖了很多。
// read file
//LARGE_INTEGER byteOffset;
ntstatus = ZwCreateFile(&handle,
GENERIC_READ,
&objAttr, &ioStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
if (NT_SUCCESS(ntstatus)) {
byteOffset.LowPart = byteOffset.HighPart = 0;
ntstatus = ZwReadFile(handle, NULL, NULL, NULL, &ioStatusBlock,
Buffer, (ULONG)BufferLength, &byteOffset, NULL);
if (NT_SUCCESS(ntstatus)) {
//Buffer[BufferLength - 1] = ' ';
//DbgPrint("%sn", Buffer);
}
ZwClose(handle);
}
有人建议使用GetFileSize((,但我的VS2019报告了以下错误:
Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "GetFileSize" is undefined TabletAudioSample D:workspace4Windows-driver-samplesaudiosysvadadapter.cpp 702
如果我添加头文件:
#include <fileapi.h>
然后我收到了另一个错误报告:
Severity Code Description Project File Line Suppression State
Error (active) E1696 cannot open source file "fileapi.h" TabletAudioSample D:workspace4Windows-driver-samplesaudiosysvadadapter.cpp 24
谢谢!
GetFileSize 不是 WDK 函数。 使用 ZwQueryInformationFile 而不是 GetFileSize。
使用以下代码
FILE_STANDARD_INFORMATION fileInfo = {0};
ntStatus = ZwQueryInformationFile(
handle,
&ioStatusBlock,
&fileInfo,
sizeof(fileInfo),
FileStandardInformation
);
if (NT_SUCCESS(ntstatus)) {
//. fileInfo.EndOfFile is the file size of handle.
}
而不是代码中的 ZwReadFile。 并包括
这与 RbMm 评论的都一样,我希望我的示例代码也能为您提供帮助。
相关文章:
- 如何在Windows内核中获取文件大小
- 使用 C++ iOS::ate 获取错误的文件大小
- 如何使用文件系统库获取"true"文件大小?(C++17)
- 如何使用C 17获取文件大小
- HttpQueryInfo 获取文件大小
- 从CfileDialog获取文件大小
- 如何获取文件的大小
- 使用ifstream::seekg和tellg获取文件大小
- 有没有办法通过程序在特定时间获取文件部分加载内容的大小C++
- 如何获取文件大小和文件名和文件开始地址?
- 在 C# 中获取十六进制文件大小
- 如何在下载前获取文件大小
- 如何通过Windows API获取文件夹大小
- 打开文件并使用fseek获取文件大小-C++
- 在C/C++中获取文件大小、文件扩展名并将其分配到不同名称的新文件夹
- 在windows上用c++获取系统应用程序的文件大小
- 在windows中获取文件大小
- visual获取c++中的文件大小
- C++获取文件大小信息的更快方法
- 如何以C++为单位获取文件的大小?