-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-read-write-file.c
62 lines (49 loc) · 1.32 KB
/
01-read-write-file.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// hello-native-app.c
// Copyright (C) 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>.
// This file is public domain software.
#include "common.h"
#define FILENAME L"\\SystemRoot\\01-read-write-file.txt"
INT
__cdecl
_main(
IN INT argc,
IN PCHAR argv[],
IN PCHAR envp[],
IN ULONG DebugFlag)
{
HANDLE hFile;
CHAR abData[256];
DWORD i, cbData;
DbgPrint("This is a debug output.\n");
hFile = DoOpenFile(FILENAME, TRUE);
if (hFile == INVALID_HANDLE_VALUE)
{
DbgPrint("hFile == INVALID_HANDLE_VALUE\n");
return -1;
}
DoPutSz(hFile, "ABCDEFG");
NtFlushBuffersFile(hFile, &IoStatusBlock);
DoCloseFile(hFile);
hFile = DoOpenFile(FILENAME, FALSE);
if (hFile == INVALID_HANDLE_VALUE)
{
DbgPrint("hFile == INVALID_HANDLE_VALUE\n");
return -1;
}
DoReadFile(hFile, abData, cbData, &cbData);
DoCloseFile(hFile);
for (i = 0; i < cbData; ++i)
{
abData[i] = abData[i] + 1;
}
hFile = DoOpenFile(FILENAME, TRUE);
if (hFile == INVALID_HANDLE_VALUE)
{
DbgPrint("hFile == INVALID_HANDLE_VALUE\n");
return -1;
}
DoWriteFile(hFile, abData, cbData);
DoPutSz(hFile, "\r\n");
DoCloseFile(hFile);
return 0;
}