-
Notifications
You must be signed in to change notification settings - Fork 36
/
Program.cs
52 lines (46 loc) · 1.69 KB
/
Program.cs
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
//
// Author: Jack Halon (@jack_halon)
// Project: SharpCall (https://github.com/jhalon/SharpCall)
// License: BSD 3-Clause
//
using System;
using System.Runtime.InteropServices;
using static SharpCall.Native;
using static SharpCall.Syscalls;
namespace SharpCall
{
class Program
{
static void Main(string[] args)
{
Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle;
UNICODE_STRING filename = new UNICODE_STRING();
RtlInitUnicodeString(ref filename, @"\??\C:\Users\User\Desktop\test.txt");
IntPtr objectName = Marshal.AllocHGlobal(Marshal.SizeOf(filename));
Marshal.StructureToPtr(filename, objectName, true);
OBJECT_ATTRIBUTES FileObjectAttributes = new OBJECT_ATTRIBUTES
{
Length = (int)Marshal.SizeOf(typeof(OBJECT_ATTRIBUTES)),
RootDirectory = IntPtr.Zero,
ObjectName = objectName,
Attributes = 0x00000040, // OBJ_CASE_INSENSITIVE
SecurityDescriptor = IntPtr.Zero,
SecurityQualityOfService = IntPtr.Zero
};
IO_STATUS_BLOCK IoStatusBlock = new IO_STATUS_BLOCK();
long allocationSize = 0;
var status = NTCreateFile(
out fileHandle,
FileAccess.FILE_GENERIC_WRITE,
ref FileObjectAttributes,
ref IoStatusBlock,
ref allocationSize,
FileAttributes.Normal,
FileShare.Write,
CreationDisposition.FILE_OVERWRITE_IF,
CreateOption.FILE_SYNCHRONOUS_IO_NONALERT,
IntPtr.Zero,
0);
}
}
}