forked from HighEncryption/SyncPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
116 lines (94 loc) · 3.81 KB
/
NativeMethods.cs
File metadata and controls
116 lines (94 loc) · 3.81 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
namespace SyncPro.Adapters.WindowsFileSystem
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal static class NativeMethods
{
#region Kernel32
internal const int GENERIC_READ = unchecked((int) 0x80000000);
internal const int FILE_FLAG_BACKUP_SEMANTICS = unchecked((int) 0x02000000);
internal const int OPEN_EXISTING = unchecked((int)3);
internal const uint FSCTL_GET_OBJECT_ID = 0x0009009c;
internal const uint FSCTL_CREATE_OR_GET_OBJECT_ID = 0x000900c0;
public struct BY_HANDLE_FILE_INFORMATION
{
public uint FileAttributes;
#pragma warning disable 618
public FILETIME CreationTime;
public FILETIME LastAccessTime;
public FILETIME LastWriteTime;
#pragma warning restore 618
public uint VolumeSerialNumber;
public uint FileSizeHigh;
public uint FileSizeLow;
public uint NumberOfLinks;
public uint FileIndexHigh;
public uint FileIndexLow;
}
[StructLayout(LayoutKind.Sequential)]
public struct FILE_OBJECTID_BUFFER
{
public struct Union
{
#pragma warning disable 0649
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] BirthVolumeId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] BirthObjectId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] DomainId;
#pragma warning restore 0649
}
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] ObjectId;
public Union BirthInfo;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
public byte[] ExtendedInfo;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetFileInformationByHandle(IntPtr hFile, out BY_HANDLE_FILE_INFORMATION lpFileInformation);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeFileHandle CreateFile(
string lpFileName,
int dwDesiredAccess,
FileShare dwShareMode,
IntPtr lpSecurityAttributes,
FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool DeviceIoControl(
SafeFileHandle hDevice,
uint dwIoControlCode,
IntPtr lpInBuffer,
uint nInBufferSize,
[Out] IntPtr lpOutBuffer,
int nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
#endregion
//#region msvcrt
//[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
//public static extern int memcmp(byte[] b1, byte[] b2, long count);
//public static bool ByteArrayEquals(byte[] b1, byte[] b2)
//{
// // If both buffers are null, then they are equal.
// if (b1 == null && b2 == null)
// {
// return true;
// }
// // If either buffer is null (one is null and one is non-null), they aren't equal.
// if (b1 == null || b2 == null)
// {
// return false;
// }
// // Validate buffers are the same length. This also ensures that the count does not exceed the length of either buffer.
// return b1.Length == b2.Length && memcmp(b1, b2, b1.Length) == 0;
//}
//#endregion
}
}