NTSTATUS ZwCreateFile(
_Out_ PHANDLE FileHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_In_opt_ PLARGE_INTEGER AllocationSize,
_In_ ULONG FileAttributes,
_In_ ULONG ShareAccess,
_In_ ULONG CreateDisposition,
_In_ ULONG CreateOptions,
_In_opt_ PVOID EaBuffer,
_In_ ULONG EaLength
);
VOID InitializeObjectAttributes(
[out] POBJECT_ATTRIBUTES InitializedAttributes,
[in] PUNICODE_STRING ObjectName,
[in] ULONG Attributes,
[in] HANDLE RootDirectory,
[in, optional] PSECURITY_DESCRIPTOR SecurityDescriptor
);
初始化OBJECT_ATTRIBUTES结构。
- InitializedAttributes:返回的OBJECT_ATTRIBUTES结构。
- ObjectName:对象名称(文件名,必须为符号链接或设备名,如:”\??\c:”),用UNICODE_STRING描述。
- Attributes:大小写敏感。
- RootDirectory:一般为NULL。
- SecurityDescriptor:一般为NULL。
NTSTATUS ZwOpenFile(
_Out_ PHANDLE FileHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_In_ ULONG ShareAccess,
_In_ ULONG OpenOptions
);
NTSTATUS ZwSetInformationFile(
_In_ HANDLE FileHandle,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_In_ PVOID FileInformation,
_In_ ULONG Length,
_In_ FILE_INFORMATION_CLASS FileInformationClass
);
NTSTATUS ZwQueryInformationFile(
_In_ HANDLE FileHandle,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_Out_ PVOID FileInformation,
_In_ ULONG Length,
_In_ FILE_INFORMATION_CLASS FileInformationClass
);
(1)当FileInformationClass是FileStandardInformation时,输入输出的数据是FILE_STANDARD_INFORMATION结构体。
typedef struct _FILE_STANDARD_INFORMATION {
LARGE_INTEGER AllocationSize; //为文件分配的大小
LARGE_INTEGER EndOfFile; //距离文件结尾还有多少字节
ULONG NumberOfLinks; //有多少个链接文件
BOOLEAN DeletePending; //是否准备删除
BOOLEAN Directory; //是否为目录
} FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
(2)当FileInformationClass是FileBasicInformation时,输入输出的数据是FILE_BASIC_INFORMATION结构体。
typedef struct _FILE_BASIC_INFORMATION {
LARGE_INTEGER CreationTime; //文件创建时间
LARGE_INTEGER LastAccessTime; //最后访问时间
LARGE_INTEGER LastWriteTime; //最后写时间
LARGE_INTEGER ChangeTime; //修改时间
ULONG FileAttributes; //文件属性
} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
(3)当FileInformationClass是FileNameInformation时,输入输出的数据是FILE_NAME_INFORMATION结构体。
typedef struct _FILE_NAME_INFORMATION {
ULONG FileNameLength; //文件名长度
WCHAR FileName[1]; //文件名
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
(4)当FileInformationClass是FilePositionInformation时,输入输出的数据是FILE_POSITION_INFORMATION结构体。
typedef struct _FILE_POSITION_INFORMATION {
LARGE_INTEGER CurrentByteOffset; //代表当前文件指针的位置
} FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
NTSTATUS ZwWriteFile(
_In_ HANDLE FileHandle,
_In_opt_ HANDLE Event,
_In_opt_ PIO_APC_ROUTINE ApcRoutine,
_In_opt_ PVOID ApcContext,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_In_ PVOID Buffer,
_In_ ULONG Length,
_In_opt_ PLARGE_INTEGER ByteOffset,
_In_opt_ PULONG Key
);
NTSTATUS ZwReadFile(
_In_ HANDLE FileHandle,
_In_opt_ HANDLE Event,
_In_opt_ PIO_APC_ROUTINE ApcRoutine,
_In_opt_ PVOID ApcContext,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_Out_ PVOID Buffer,
_In_ ULONG Length,
_In_opt_ PLARGE_INTEGER ByteOffset,
_In_opt_ PULONG Key
);