-
Notifications
You must be signed in to change notification settings - Fork 1
/
files.c
40 lines (29 loc) · 1.21 KB
/
files.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "files.h"
NTSTATUS openFile(PWCHAR fileName, PHANDLE fileHandle) {
OBJECT_ATTRIBUTES fileAttributes;
IO_STATUS_BLOCK statusBlock;
NTSTATUS status;
UNICODE_STRING fileNameUncdStr;
status = STATUS_SUCCESS;
RtlInitUnicodeString(&fileNameUncdStr, fileName);
InitializeObjectAttributes(&fileAttributes, &fileNameUncdStr,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
status = ZwCreateFile(fileHandle, FILE_READ_DATA | FILE_WRITE_DATA, &fileAttributes,
&statusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE, NULL, 0);
if (!NT_SUCCESS(status)) {
TRACE("Error in ZwCreateFile, ret - %x, status code %x, information %x", status, statusBlock.Status, statusBlock.Information);
status = statusBlock.Status;
}
return status;
}
NTSTATUS writeFile(HANDLE fileHandle, PVOID buffer, PLARGE_INTEGER offset, ULONG length) {
NTSTATUS status;
IO_STATUS_BLOCK statusBlock;
status = STATUS_SUCCESS;
status = ZwWriteFile(fileHandle, NULL, NULL, NULL, &statusBlock, buffer, length, offset, NULL);
if (!NT_SUCCESS(status)) {
TRACE("Error in ZwWriteFile, code %x", status);
}
return status;
}