Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
5using System.IO;
8using System.Text;
12
13internal static class Interop
14{
15 internal static class OleAut32
16 {
17 [DllImport("oleaut32.dll")]
18 internal static extern void VariantClear(IntPtr variant);
19
20 [DllImport("oleaut32.dll")]
21 internal static extern IntPtr SysAllocStringByteLen(byte[] str, uint len);
22
23 [DllImport("oleaut32.dll", CharSet = CharSet.Unicode)]
24 internal static extern IntPtr SysAllocStringLen(IntPtr src, uint len);
25
26 [DllImport("oleaut32.dll")]
27 internal static extern void SysFreeString(IntPtr bstr);
28 }
29
30 internal static class Globalization
31 {
32 internal enum ResultCode
33 {
34 Success,
38 }
39
40 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")]
41 internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity);
42
43 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")]
44 internal unsafe static extern ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity);
45
46 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")]
47 internal unsafe static extern bool EnumCalendarInfo(delegate* unmanaged<char*, IntPtr, void> callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context);
48
49 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
50 internal static extern int GetLatestJapaneseEra();
51
52 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
53 internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay);
54
55 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")]
56 internal unsafe static extern void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
57
58 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")]
59 internal unsafe static extern void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
60
61 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")]
62 internal unsafe static extern void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
63
64 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_InitOrdinalCasingPage")]
65 internal unsafe static extern void InitOrdinalCasingPage(int pageNumber, char* pTarget);
66
67 [DllImport("System.Globalization.Native", CharSet = CharSet.Ansi, EntryPoint = "GlobalizationNative_GetSortHandle")]
68 internal static extern ResultCode GetSortHandle(string localeName, out IntPtr sortHandle);
69
70 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_CloseSortHandle")]
71 internal static extern void CloseSortHandle(IntPtr handle);
72
73 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")]
74 internal unsafe static extern int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);
75
76 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
77 internal unsafe static extern int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
78
79 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")]
80 internal unsafe static extern int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
81
82 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
83 [return: MarshalAs(UnmanagedType.Bool)]
84 internal unsafe static extern bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);
85
86 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
87 [return: MarshalAs(UnmanagedType.Bool)]
88 internal unsafe static extern bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);
89
90 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")]
91 internal unsafe static extern int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);
92
93 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_GetSortVersion")]
94 internal static extern int GetSortVersion(IntPtr sortHandle);
95
96 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_LoadICU")]
97 internal static extern int LoadICU();
98
99 internal static void InitICUFunctions(IntPtr icuuc, IntPtr icuin, ReadOnlySpan<char> version, ReadOnlySpan<char> suffix)
100 {
101 InitICUFunctions(icuuc, icuin, version.ToString(), (suffix.Length > 0) ? suffix.ToString() : null);
102 }
103
104 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_InitICUFunctions")]
105 internal static extern void InitICUFunctions(IntPtr icuuc, IntPtr icuin, string version, string suffix);
106
107 [DllImport("System.Globalization.Native", EntryPoint = "GlobalizationNative_GetICUVersion")]
108 internal static extern int GetICUVersion();
109
110 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
111 internal unsafe static extern int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
112
113 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
114 internal unsafe static extern int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
115
116 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")]
117 [return: MarshalAs(UnmanagedType.Bool)]
118 internal unsafe static extern bool GetLocaleName(string localeName, char* value, int valueLength);
119
120 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")]
121 [return: MarshalAs(UnmanagedType.Bool)]
122 internal unsafe static extern bool GetLocaleInfoString(string localeName, uint localeStringData, char* value, int valueLength, string uiLocaleName = null);
123
124 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsPredefinedLocale")]
125 [return: MarshalAs(UnmanagedType.Bool)]
126 internal static extern bool IsPredefinedLocale(string localeName);
127
128 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")]
129 [return: MarshalAs(UnmanagedType.Bool)]
130 internal unsafe static extern bool GetLocaleTimeFormat(string localeName, bool shortFormat, char* value, int valueLength);
131
132 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")]
133 [return: MarshalAs(UnmanagedType.Bool)]
134 internal static extern bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value);
135
136 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")]
137 [return: MarshalAs(UnmanagedType.Bool)]
138 internal static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize);
139
140 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")]
141 internal static extern int GetLocales([Out] char[] value, int valueLength);
142
143 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")]
144 internal unsafe static extern int IsNormalized(NormalizationForm normalizationForm, char* src, int srcLen);
145
146 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")]
147 internal unsafe static extern int NormalizeString(NormalizationForm normalizationForm, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
148
149 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_WindowsIdToIanaId")]
150 internal unsafe static extern int WindowsIdToIanaId(string windowsId, IntPtr region, char* ianaId, int ianaIdLength);
151
152 [DllImport("System.Globalization.Native", CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IanaIdToWindowsId")]
153 internal unsafe static extern int IanaIdToWindowsId(string ianaId, char* windowsId, int windowsIdLength);
154 }
155
156 internal enum BOOL
157 {
158 FALSE,
159 TRUE
160 }
161
162 internal static class Kernel32
163 {
164 internal struct NlsVersionInfoEx
165 {
167
168 internal int dwNLSVersion;
169
170 internal int dwDefinedVersion;
171
172 internal int dwEffectiveId;
173
175 }
176
177 internal struct CONDITION_VARIABLE
178 {
179 private IntPtr Ptr;
180 }
181
182 internal struct CRITICAL_SECTION
183 {
185
186 private int LockCount;
187
188 private int RecursionCount;
189
191
193
195 }
196
197 internal struct FILE_BASIC_INFO
198 {
199 internal long CreationTime;
200
201 internal long LastAccessTime;
202
203 internal long LastWriteTime;
204
205 internal long ChangeTime;
206
207 internal uint FileAttributes;
208 }
209
210 internal struct FILE_ALLOCATION_INFO
211 {
212 internal long AllocationSize;
213 }
214
215 internal struct FILE_END_OF_FILE_INFO
216 {
217 internal long EndOfFile;
218 }
219
220 internal struct FILE_STANDARD_INFO
221 {
222 internal long AllocationSize;
223
224 internal long EndOfFile;
225
226 internal uint NumberOfLinks;
227
229
230 internal BOOL Directory;
231 }
232
233 internal struct FILE_TIME
234 {
235 internal uint dwLowDateTime;
236
237 internal uint dwHighDateTime;
238
239 internal long ToTicks()
240 {
241 return (long)(((ulong)dwHighDateTime << 32) + dwLowDateTime);
242 }
243
248 }
249
250 internal enum FINDEX_INFO_LEVELS : uint
251 {
255 }
256
264
265 internal enum GET_FILEEX_INFO_LEVELS : uint
266 {
269 }
270
271 internal struct CPINFO
272 {
273 internal int MaxCharSize;
274
275 internal unsafe fixed byte DefaultChar[2];
276
277 internal unsafe fixed byte LeadByte[12];
278 }
279
302
303 internal struct MEMORY_BASIC_INFORMATION
304 {
305 internal unsafe void* BaseAddress;
306
307 internal unsafe void* AllocationBase;
308
309 internal uint AllocationProtect;
310
311 internal UIntPtr RegionSize;
312
313 internal uint State;
314
315 internal uint Protect;
316
317 internal uint Type;
318 }
319
320 internal struct MEMORYSTATUSEX
321 {
322 internal uint dwLength;
323
324 internal uint dwMemoryLoad;
325
326 internal ulong ullTotalPhys;
327
328 internal ulong ullAvailPhys;
329
330 internal ulong ullTotalPageFile;
331
332 internal ulong ullAvailPageFile;
333
334 internal ulong ullTotalVirtual;
335
336 internal ulong ullAvailVirtual;
337
338 internal ulong ullAvailExtendedVirtual;
339 }
340
341 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
342 internal struct OSVERSIONINFOEX
343 {
345
346 public int dwMajorVersion;
347
348 public int dwMinorVersion;
349
350 public int dwBuildNumber;
351
352 public int dwPlatformId;
353
354 public unsafe fixed char szCSDVersion[128];
355
356 public ushort wServicePackMajor;
357
358 public ushort wServicePackMinor;
359
360 public ushort wSuiteMask;
361
362 public byte wProductType;
363
364 public byte wReserved;
365 }
366
368 {
369 internal uint ReparseTag;
370
371 internal ushort ReparseDataLength;
372
373 internal ushort Reserved;
374
375 internal ushort SubstituteNameOffset;
376
377 internal ushort SubstituteNameLength;
378
379 internal ushort PrintNameOffset;
380
381 internal ushort PrintNameLength;
382
383 internal uint Flags;
384 }
385
387 {
388 public uint ReparseTag;
389
390 public ushort ReparseDataLength;
391
392 public ushort Reserved;
393
394 public ushort SubstituteNameOffset;
395
396 public ushort SubstituteNameLength;
397
398 public ushort PrintNameOffset;
399
400 public ushort PrintNameLength;
401 }
402
403 internal struct SECURITY_ATTRIBUTES
404 {
405 internal uint nLength;
406
408
409 internal BOOL bInheritHandle;
410 }
411
412 internal struct SYSTEM_INFO
413 {
414 internal ushort wProcessorArchitecture;
415
416 internal ushort wReserved;
417
418 internal int dwPageSize;
419
421
423
425
426 internal int dwNumberOfProcessors;
427
428 internal int dwProcessorType;
429
430 internal int dwAllocationGranularity;
431
432 internal short wProcessorLevel;
433
434 internal short wProcessorRevision;
435 }
436
437 internal struct SYSTEMTIME
438 {
439 internal ushort Year;
440
441 internal ushort Month;
442
443 internal ushort DayOfWeek;
444
445 internal ushort Day;
446
447 internal ushort Hour;
448
449 internal ushort Minute;
450
451 internal ushort Second;
452
453 internal ushort Milliseconds;
454
455 internal bool Equals(in SYSTEMTIME other)
456 {
457 if (Year == other.Year && Month == other.Month && DayOfWeek == other.DayOfWeek && Day == other.Day && Hour == other.Hour && Minute == other.Minute && Second == other.Second)
458 {
459 return Milliseconds == other.Milliseconds;
460 }
461 return false;
462 }
463 }
464
465 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
467 {
468 internal int Bias;
469
470 internal unsafe fixed char StandardName[32];
471
473
474 internal int StandardBias;
475
476 internal unsafe fixed char DaylightName[32];
477
479
480 internal int DaylightBias;
481
482 internal unsafe fixed char TimeZoneKeyName[128];
483
485
486 internal unsafe string GetTimeZoneKeyName()
487 {
488 fixed (char* value = TimeZoneKeyName)
489 {
490 return new string(value);
491 }
492 }
493 }
494
495 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
496 internal struct TIME_ZONE_INFORMATION
497 {
498 internal int Bias;
499
500 internal unsafe fixed char StandardName[32];
501
503
504 internal int StandardBias;
505
506 internal unsafe fixed char DaylightName[32];
507
509
510 internal int DaylightBias;
511
513 {
514 fixed (TIME_ZONE_INFORMATION* ptr = &this)
515 {
516 fixed (TIME_DYNAMIC_ZONE_INFORMATION* ptr2 = &dtzi)
517 {
518 *ptr = *(TIME_ZONE_INFORMATION*)ptr2;
519 }
520 }
521 }
522
523 internal unsafe string GetStandardName()
524 {
525 fixed (char* value = StandardName)
526 {
527 return new string(value);
528 }
529 }
530
531 internal unsafe string GetDaylightName()
532 {
533 fixed (char* value = DaylightName)
534 {
535 return new string(value);
536 }
537 }
538 }
539
540 internal struct REG_TZI_FORMAT
541 {
542 internal int Bias;
543
544 internal int StandardBias;
545
546 internal int DaylightBias;
547
549
551
553 {
554 Bias = tzi.Bias;
555 StandardDate = tzi.StandardDate;
556 StandardBias = tzi.StandardBias;
557 DaylightDate = tzi.DaylightDate;
558 DaylightBias = tzi.DaylightBias;
559 }
560 }
561
562 internal struct WIN32_FILE_ATTRIBUTE_DATA
563 {
564 internal int dwFileAttributes;
565
566 internal FILE_TIME ftCreationTime;
567
568 internal FILE_TIME ftLastAccessTime;
569
570 internal FILE_TIME ftLastWriteTime;
571
572 internal uint nFileSizeHigh;
573
574 internal uint nFileSizeLow;
575
576 internal void PopulateFrom(ref WIN32_FIND_DATA findData)
577 {
578 dwFileAttributes = (int)findData.dwFileAttributes;
579 ftCreationTime = findData.ftCreationTime;
580 ftLastAccessTime = findData.ftLastAccessTime;
581 ftLastWriteTime = findData.ftLastWriteTime;
582 nFileSizeHigh = findData.nFileSizeHigh;
583 nFileSizeLow = findData.nFileSizeLow;
584 }
585 }
586
587 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
588 internal struct WIN32_FIND_DATA
589 {
590 internal uint dwFileAttributes;
591
592 internal FILE_TIME ftCreationTime;
593
594 internal FILE_TIME ftLastAccessTime;
595
596 internal FILE_TIME ftLastWriteTime;
597
598 internal uint nFileSizeHigh;
599
600 internal uint nFileSizeLow;
601
602 internal uint dwReserved0;
603
604 internal uint dwReserved1;
605
606 private unsafe fixed char _cFileName[260];
607
608 private unsafe fixed char _cAlternateFileName[14];
609
611 {
612 get
613 {
614 fixed (char* pointer = _cFileName)
615 {
616 return new ReadOnlySpan<char>(pointer, 260);
617 }
618 }
619 }
620 }
621
622 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
623 internal unsafe static extern int LCIDToLocaleName(int locale, char* pLocaleName, int cchName, uint dwFlags);
624
625 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
626 internal static extern int LocaleNameToLCID(string lpName, uint dwFlags);
627
628 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
629 internal unsafe static extern int LCMapStringEx(string lpLocaleName, uint dwMapFlags, char* lpSrcStr, int cchSrc, void* lpDestStr, int cchDest, void* lpVersionInformation, void* lpReserved, IntPtr sortHandle);
630
631 [DllImport("kernel32.dll")]
632 internal unsafe static extern int FindNLSStringEx(char* lpLocaleName, uint dwFindNLSStringFlags, char* lpStringSource, int cchSource, char* lpStringValue, int cchValue, int* pcchFound, void* lpVersionInformation, void* lpReserved, IntPtr sortHandle);
633
634 [DllImport("kernel32.dll")]
635 internal unsafe static extern int CompareStringEx(char* lpLocaleName, uint dwCmpFlags, char* lpString1, int cchCount1, char* lpString2, int cchCount2, void* lpVersionInformation, void* lpReserved, IntPtr lParam);
636
637 [DllImport("kernel32.dll")]
638 internal unsafe static extern int CompareStringOrdinal(char* lpString1, int cchCount1, char* lpString2, int cchCount2, bool bIgnoreCase);
639
640 [DllImport("kernel32.dll")]
641 internal unsafe static extern int FindStringOrdinal(uint dwFindStringOrdinalFlags, char* lpStringSource, int cchSource, char* lpStringValue, int cchValue, BOOL bIgnoreCase);
642
643 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
644 internal unsafe static extern bool IsNLSDefinedString(int Function, uint dwFlags, IntPtr lpVersionInformation, char* lpString, int cchStr);
645
646 [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
647 internal unsafe static extern BOOL GetUserPreferredUILanguages(uint dwFlags, uint* pulNumLanguages, char* pwszLanguagesBuffer, uint* pcchLanguagesBuffer);
648
649 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
650 internal unsafe static extern int GetLocaleInfoEx(string lpLocaleName, uint LCType, void* lpLCData, int cchData);
651
652 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
653 internal unsafe static extern bool EnumSystemLocalesEx(delegate* unmanaged<char*, uint, void*, BOOL> lpLocaleEnumProcEx, uint dwFlags, void* lParam, IntPtr reserved);
654
655 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
656 internal unsafe static extern bool EnumTimeFormatsEx(delegate* unmanaged<char*, void*, BOOL> lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, void* lParam);
657
658 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
659 internal static extern int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, out int lpValue);
660
661 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
662 internal static extern int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, IntPtr lpValue);
663
664 [DllImport("kernel32.dll")]
665 internal static extern int GetUserGeoID(int geoClass);
666
667 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
668 internal unsafe static extern int GetGeoInfo(int location, int geoType, char* lpGeoData, int cchData, int LangId);
669
670 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
671 internal unsafe static extern bool EnumCalendarInfoExEx(delegate* unmanaged<char*, uint, IntPtr, void*, BOOL> pCalInfoEnumProcExEx, string lpLocaleName, uint Calendar, string lpReserved, uint CalType, void* lParam);
672
673 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
674 internal unsafe static extern bool GetNLSVersionEx(int function, string localeName, NlsVersionInfoEx* lpVersionInformation);
675
676 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
677 internal unsafe static extern int ResolveLocaleName(string lpNameToResolve, char* lpLocaleName, int cchLocaleName);
678
679 [DllImport("kernel32.dll", SetLastError = true)]
680 internal unsafe static extern bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);
681
682 [DllImport("kernel32.dll", SetLastError = true)]
683 internal static extern IntPtr CreateIoCompletionPort(IntPtr FileHandle, IntPtr ExistingCompletionPort, UIntPtr CompletionKey, int NumberOfConcurrentThreads);
684
685 [DllImport("kernel32.dll", SetLastError = true)]
686 [return: MarshalAs(UnmanagedType.Bool)]
687 internal static extern bool PostQueuedCompletionStatus(IntPtr CompletionPort, int dwNumberOfBytesTransferred, UIntPtr CompletionKey, IntPtr lpOverlapped);
688
689 [DllImport("kernel32.dll", SetLastError = true)]
690 [return: MarshalAs(UnmanagedType.Bool)]
691 internal static extern bool GetQueuedCompletionStatus(IntPtr CompletionPort, out int lpNumberOfBytes, out UIntPtr CompletionKey, out IntPtr lpOverlapped, int dwMilliseconds);
692
693 [DllImport("kernel32.dll", ExactSpelling = true)]
694 internal unsafe static extern void InitializeConditionVariable(CONDITION_VARIABLE* ConditionVariable);
695
696 [DllImport("kernel32.dll", ExactSpelling = true)]
697 internal unsafe static extern void WakeConditionVariable(CONDITION_VARIABLE* ConditionVariable);
698
699 [DllImport("kernel32.dll", ExactSpelling = true)]
700 internal unsafe static extern bool SleepConditionVariableCS(CONDITION_VARIABLE* ConditionVariable, CRITICAL_SECTION* CriticalSection, int dwMilliseconds);
701
702 internal static int CopyFile(string src, string dst, bool failIfExists)
703 {
704 int flags = (failIfExists ? 1 : 0);
705 int cancel = 0;
706 if (!CopyFileEx(src, dst, IntPtr.Zero, IntPtr.Zero, ref cancel, flags))
707 {
708 return Marshal.GetLastWin32Error();
709 }
710 return 0;
711 }
712
713 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CopyFileExW", SetLastError = true)]
714 private static extern bool CopyFileExPrivate(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags);
715
716 internal static bool CopyFileEx(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags)
717 {
720 return CopyFileExPrivate(src, dst, progressRoutine, progressData, ref cancel, flags);
721 }
722
723 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateDirectoryW", SetLastError = true)]
724 private static extern bool CreateDirectoryPrivate(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes);
725
726 internal static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
727 {
729 return CreateDirectoryPrivate(path, ref lpSecurityAttributes);
730 }
731
732 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", ExactSpelling = true, SetLastError = true)]
733 private unsafe static extern SafeFileHandle CreateFilePrivate(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
734
735 internal unsafe static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
736 {
737 lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
738 return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
739 }
740
741 internal unsafe static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
742 {
743 lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
744 return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, null, dwCreationDisposition, dwFlagsAndAttributes, IntPtr.Zero);
745 }
746
747 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "DeleteFileW", SetLastError = true)]
748 private static extern bool DeleteFilePrivate(string path);
749
750 internal static bool DeleteFile(string path)
751 {
753 return DeleteFilePrivate(path);
754 }
755
756 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "DeleteVolumeMountPointW", SetLastError = true)]
757 internal static extern bool DeleteVolumeMountPointPrivate(string mountPoint);
758
759 internal static bool DeleteVolumeMountPoint(string mountPoint)
760 {
761 mountPoint = PathInternal.EnsureExtendedPrefixIfNeeded(mountPoint);
762 return DeleteVolumeMountPointPrivate(mountPoint);
763 }
764
765 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", ExactSpelling = true, SetLastError = true)]
766 private unsafe static extern IntPtr CreateFilePrivate_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
767
768 internal unsafe static IntPtr CreateFile_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
769 {
770 lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
771 return CreateFilePrivate_IntPtr(lpFileName, dwDesiredAccess, dwShareMode, null, dwCreationDisposition, dwFlagsAndAttributes, IntPtr.Zero);
772 }
773
774 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateSymbolicLinkW", ExactSpelling = true, SetLastError = true)]
775 private static extern bool CreateSymbolicLinkPrivate(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
776
777 internal static void CreateSymbolicLink(string symlinkFileName, string targetFileName, bool isDirectory)
778 {
779 string path = symlinkFileName;
780 symlinkFileName = PathInternal.EnsureExtendedPrefixIfNeeded(symlinkFileName);
781 targetFileName = PathInternal.EnsureExtendedPrefixIfNeeded(targetFileName);
782 int num = 0;
783 bool flag = (Environment.OSVersion.Version.Major == 10 && Environment.OSVersion.Version.Build >= 14972) || Environment.OSVersion.Version.Major >= 11;
784 if (flag)
785 {
786 num = 2;
787 }
788 if (isDirectory)
789 {
790 num |= 1;
791 }
792 if (!CreateSymbolicLinkPrivate(symlinkFileName, targetFileName, num))
793 {
795 }
796 int lastWin32Error;
797 if (!flag && (lastWin32Error = Marshal.GetLastWin32Error()) != 0)
798 {
799 throw Win32Marshal.GetExceptionForWin32Error(lastWin32Error, path);
800 }
801 }
802
803 [DllImport("kernel32.dll", ExactSpelling = true)]
804 internal unsafe static extern void InitializeCriticalSection(CRITICAL_SECTION* lpCriticalSection);
805
806 [DllImport("kernel32.dll", ExactSpelling = true)]
807 internal unsafe static extern void EnterCriticalSection(CRITICAL_SECTION* lpCriticalSection);
808
809 [DllImport("kernel32.dll", ExactSpelling = true)]
810 internal unsafe static extern void LeaveCriticalSection(CRITICAL_SECTION* lpCriticalSection);
811
812 [DllImport("kernel32.dll", ExactSpelling = true)]
813 internal unsafe static extern void DeleteCriticalSection(CRITICAL_SECTION* lpCriticalSection);
814
815 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
816 internal static extern bool DeviceIoControl(SafeHandle hDevice, uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, byte[] lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned, IntPtr lpOverlapped);
817
818 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "ExpandEnvironmentStringsW", ExactSpelling = true, SetLastError = true)]
819 internal static extern uint ExpandEnvironmentStrings(string lpSrc, ref char lpDst, uint nSize);
820
821 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "FindNextFileW", SetLastError = true)]
822 internal static extern bool FindNextFile(SafeFindHandle hndFindFile, ref WIN32_FIND_DATA lpFindFileData);
823
824 [DllImport("kernel32.dll")]
825 [SuppressGCTransition]
826 internal unsafe static extern BOOL FileTimeToSystemTime(ulong* lpFileTime, SYSTEMTIME* lpSystemTime);
827
828 [DllImport("kernel32.dll", SetLastError = true)]
829 internal static extern bool FindClose(IntPtr hFindFile);
830
831 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileExW", ExactSpelling = true, SetLastError = true)]
832 private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
833
834 internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
835 {
836 fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName);
837 return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
838 }
839
840 [DllImport("kernel32.dll", SetLastError = true)]
841 [return: MarshalAs(UnmanagedType.Bool)]
842 internal static extern bool FlushFileBuffers(SafeHandle hHandle);
843
844 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
845 internal static extern bool FreeLibrary(IntPtr hModule);
846
847 [DllImport("kernel32.dll")]
848 [SuppressGCTransition]
849 internal static extern int GetLastError();
850
851 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetComputerNameW", ExactSpelling = true)]
852 private static extern int GetComputerName(ref char lpBuffer, ref uint nSize);
853
854 internal static string GetComputerName()
855 {
856 Span<char> span = stackalloc char[16];
857 uint nSize = (uint)span.Length;
858 if (GetComputerName(ref MemoryMarshal.GetReference(span), ref nSize) == 0)
859 {
860 return null;
861 }
862 return span.Slice(0, (int)nSize).ToString();
863 }
864
865 [DllImport("kernel32.dll")]
866 internal unsafe static extern BOOL GetCPInfo(uint codePage, CPINFO* lpCpInfo);
867
868 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "GetCurrentDirectoryW", ExactSpelling = true, SetLastError = true)]
869 internal static extern uint GetCurrentDirectory(uint nBufferLength, ref char lpBuffer);
870
871 [DllImport("kernel32.dll")]
872 internal static extern IntPtr GetCurrentProcess();
873
874 [DllImport("kernel32.dll")]
875 internal static extern uint GetCurrentProcessId();
876
877 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetFileAttributesExW", ExactSpelling = true, SetLastError = true)]
878 private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
879
880 internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
881 {
883 return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
884 }
885
886 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
887 internal unsafe static extern bool GetFileInformationByHandleEx(SafeFileHandle hFile, int FileInformationClass, void* lpFileInformation, uint dwBufferSize);
888
889 [DllImport("kernel32.dll", SetLastError = true)]
890 internal static extern int GetFileType(SafeHandle hFile);
891
892 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetFinalPathNameByHandleW", ExactSpelling = true, SetLastError = true)]
893 internal unsafe static extern uint GetFinalPathNameByHandle(SafeFileHandle hFile, char* lpszFilePath, uint cchFilePath, uint dwFlags);
894
895 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
896 internal static extern uint GetFullPathNameW(ref char lpFileName, uint nBufferLength, ref char lpBuffer, IntPtr lpFilePart);
897
898 [DllImport("kernel32.dll", SetLastError = true)]
899 internal static extern int GetLogicalDrives();
900
901 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
902 internal static extern uint GetLongPathNameW(ref char lpszShortPath, ref char lpszLongPath, uint cchBuffer);
903
904 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetModuleFileNameW", ExactSpelling = true, SetLastError = true)]
905 internal static extern uint GetModuleFileName(IntPtr hModule, ref char lpFilename, uint nSize);
906
907 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
908 internal unsafe static extern bool GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped* lpOverlapped, ref int lpNumberOfBytesTransferred, bool bWait);
909
910 [DllImport("kernel32.dll", EntryPoint = "K32GetProcessMemoryInfo")]
911 internal static extern bool GetProcessMemoryInfo(IntPtr Process, ref PROCESS_MEMORY_COUNTERS ppsmemCounters, uint cb);
912
913 [DllImport("kernel32.dll", SetLastError = true)]
914 internal static extern bool GetProcessTimes(IntPtr handleProcess, out long creation, out long exit, out long kernel, out long user);
915
916 [DllImport("kernel32.dll")]
917 [SuppressGCTransition]
918 internal static extern IntPtr GetStdHandle(int nStdHandle);
919
920 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
921 internal static extern uint GetSystemDirectoryW(ref char lpBuffer, uint uSize);
922
923 [DllImport("kernel32.dll")]
924 internal static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
925
926 [DllImport("kernel32.dll")]
927 [SuppressGCTransition]
928 internal unsafe static extern void GetSystemTime(SYSTEMTIME* lpSystemTime);
929
930 [DllImport("kernel32.dll", SetLastError = true)]
931 internal static extern bool GetSystemTimes(out long idle, out long kernel, out long user);
932
933 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
934 internal static extern uint GetTempFileNameW(ref char lpPathName, string lpPrefixString, uint uUnique, ref char lpTempFileName);
935
936 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)]
937 internal static extern uint GetTempPathW(int bufferLen, ref char buffer);
938
939 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "GetVolumeInformationW", SetLastError = true)]
940 internal unsafe static extern bool GetVolumeInformation(string drive, char* volumeName, int volumeNameBufLen, int* volSerialNumber, int* maxFileNameLen, out int fileSystemFlags, char* fileSystemName, int fileSystemNameBufLen);
941
942 [DllImport("kernel32.dll")]
943 internal unsafe static extern BOOL GlobalMemoryStatusEx(MEMORYSTATUSEX* lpBuffer);
944
945 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", ExactSpelling = true, SetLastError = true)]
946 internal static extern IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
947
948 [DllImport("kernel32.dll")]
949 internal static extern IntPtr LocalAlloc(uint uFlags, nuint uBytes);
950
951 [DllImport("kernel32.dll")]
952 internal static extern IntPtr LocalReAlloc(IntPtr hMem, nuint uBytes, uint uFlags);
953
954 [DllImport("kernel32.dll")]
955 internal static extern IntPtr LocalFree(IntPtr hMem);
956
957 [DllImport("kernel32.dll", SetLastError = true)]
958 internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
959
960 [DllImport("kernel32.dll", SetLastError = true)]
961 internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
962
963 [DllImport("kernel32.dll")]
964 internal unsafe static extern int MultiByteToWideChar(uint CodePage, uint dwFlags, byte* lpMultiByteStr, int cbMultiByte, char* lpWideCharStr, int cchWideChar);
965
966 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "MoveFileExW", SetLastError = true)]
967 private static extern bool MoveFileExPrivate(string src, string dst, uint flags);
968
969 internal static bool MoveFile(string src, string dst, bool overwrite)
970 {
973 uint num = 2u;
974 if (overwrite)
975 {
976 num |= 1u;
977 }
978 return MoveFileExPrivate(src, dst, num);
979 }
980
981 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "OutputDebugStringW", ExactSpelling = true)]
982 internal static extern void OutputDebugString(string message);
983
984 [DllImport("kernel32.dll", ExactSpelling = true)]
985 [SuppressGCTransition]
986 internal unsafe static extern BOOL QueryPerformanceCounter(long* lpPerformanceCount);
987
988 [DllImport("kernel32.dll", ExactSpelling = true)]
989 internal unsafe static extern BOOL QueryPerformanceFrequency(long* lpFrequency);
990
991 [DllImport("kernel32.dll")]
992 internal static extern bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
993
994 [DllImport("kernel32.dll", SetLastError = true)]
995 internal unsafe static extern int ReadFile(SafeHandle handle, byte* bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* overlapped);
996
997 [DllImport("kernel32.dll", SetLastError = true)]
998 internal unsafe static extern int ReadFile(SafeHandle handle, byte* bytes, int numBytesToRead, out int numBytesRead, NativeOverlapped* overlapped);
999
1000 [DllImport("kernel32.dll", SetLastError = true)]
1001 internal unsafe static extern int ReadFileScatter(SafeHandle hFile, long* aSegmentArray, int nNumberOfBytesToRead, IntPtr lpReserved, NativeOverlapped* lpOverlapped);
1002
1003 [DllImport("kernel32.dll", SetLastError = true)]
1004 internal unsafe static extern int WriteFileGather(SafeHandle hFile, long* aSegmentArray, int nNumberOfBytesToWrite, IntPtr lpReserved, NativeOverlapped* lpOverlapped);
1005
1006 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RemoveDirectoryW", SetLastError = true)]
1007 private static extern bool RemoveDirectoryPrivate(string path);
1008
1009 internal static bool RemoveDirectory(string path)
1010 {
1012 return RemoveDirectoryPrivate(path);
1013 }
1014
1015 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "ReplaceFileW", SetLastError = true)]
1016 private static extern bool ReplaceFilePrivate(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
1017
1018 internal static bool ReplaceFile(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
1019 {
1020 replacedFileName = PathInternal.EnsureExtendedPrefixIfNeeded(replacedFileName);
1021 replacementFileName = PathInternal.EnsureExtendedPrefixIfNeeded(replacementFileName);
1022 backupFileName = PathInternal.EnsureExtendedPrefixIfNeeded(backupFileName);
1023 return ReplaceFilePrivate(replacedFileName, replacementFileName, backupFileName, dwReplaceFlags, lpExclude, lpReserved);
1024 }
1025
1026 [DllImport("kernel32.dll", SetLastError = true)]
1027 internal unsafe static extern bool SetConsoleCtrlHandler(delegate* unmanaged<int, BOOL> HandlerRoutine, bool Add);
1028
1029 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "SetCurrentDirectoryW", ExactSpelling = true, SetLastError = true)]
1030 internal static extern bool SetCurrentDirectory(string path);
1031
1032 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "SetFileAttributesW", SetLastError = true)]
1033 private static extern bool SetFileAttributesPrivate(string name, int attr);
1034
1035 internal static bool SetFileAttributes(string name, int attr)
1036 {
1038 return SetFileAttributesPrivate(name, attr);
1039 }
1040
1041 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
1042 internal unsafe static extern bool SetFileInformationByHandle(SafeFileHandle hFile, int FileInformationClass, void* lpFileInformation, uint dwBufferSize);
1043
1044 [DllImport("kernel32.dll", SetLastError = true)]
1045 internal static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer, uint dwMoveMethod);
1046
1047 [DllImport("kernel32.dll")]
1048 [SuppressGCTransition]
1049 internal static extern void SetLastError(int errorCode);
1050
1051 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
1052 [SuppressGCTransition]
1053 internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode);
1054
1055 [DllImport("kernel32.dll")]
1056 [SuppressGCTransition]
1057 internal unsafe static extern BOOL SystemTimeToFileTime(SYSTEMTIME* lpSystemTime, ulong* lpFileTime);
1058
1059 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
1060 internal static extern uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation);
1061
1062 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
1063 internal static extern uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);
1064
1065 [DllImport("kernel32.dll")]
1066 internal unsafe static extern BOOL TzSpecificLocalTimeToSystemTime(IntPtr lpTimeZoneInformation, SYSTEMTIME* lpLocalTime, SYSTEMTIME* lpUniversalTime);
1067
1068 [DllImport("kernel32.dll")]
1069 internal static extern bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask);
1070
1071 [DllImport("kernel32.dll")]
1072 internal static extern ulong VerSetConditionMask(ulong ConditionMask, uint TypeMask, byte Condition);
1073
1074 [DllImport("kernel32.dll", ExactSpelling = true)]
1075 internal unsafe static extern void* VirtualAlloc(void* lpAddress, UIntPtr dwSize, int flAllocationType, int flProtect);
1076
1077 [DllImport("kernel32.dll", ExactSpelling = true)]
1078 internal unsafe static extern bool VirtualFree(void* lpAddress, UIntPtr dwSize, int dwFreeType);
1079
1080 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
1081 internal unsafe static extern UIntPtr VirtualQuery(void* lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, UIntPtr dwLength);
1082
1083 [DllImport("kernel32.dll")]
1084 internal unsafe static extern int WideCharToMultiByte(uint CodePage, uint dwFlags, char* lpWideCharStr, int cchWideChar, byte* lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar);
1085
1086 [DllImport("kernel32.dll", SetLastError = true)]
1087 internal unsafe static extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
1088
1089 [DllImport("kernel32.dll", SetLastError = true)]
1090 internal unsafe static extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, NativeOverlapped* lpOverlapped);
1091
1092 [DllImport("kernel32.dll", SetLastError = true)]
1093 internal static extern bool CloseHandle(IntPtr handle);
1094
1095 [DllImport("kernel32.dll", SetLastError = true)]
1096 internal static extern bool SetEvent(SafeWaitHandle handle);
1097
1098 [DllImport("kernel32.dll", SetLastError = true)]
1099 internal static extern bool ResetEvent(SafeWaitHandle handle);
1100
1101 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateEventExW", ExactSpelling = true, SetLastError = true)]
1102 internal static extern SafeWaitHandle CreateEventEx(IntPtr lpSecurityAttributes, string name, uint flags, uint desiredAccess);
1103
1104 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "OpenEventW", ExactSpelling = true, SetLastError = true)]
1105 internal static extern SafeWaitHandle OpenEvent(uint desiredAccess, bool inheritHandle, string name);
1106
1107 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetEnvironmentVariableW", ExactSpelling = true, SetLastError = true)]
1108 internal static extern uint GetEnvironmentVariable(string lpName, ref char lpBuffer, uint nSize);
1109
1110 [DllImport("kernel32.dll", ExactSpelling = true)]
1111 internal unsafe static extern char* GetEnvironmentStringsW();
1112
1113 [DllImport("kernel32.dll", ExactSpelling = true)]
1114 internal unsafe static extern BOOL FreeEnvironmentStringsW(char* lpszEnvironmentBlock);
1115
1116 [DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", ExactSpelling = true, SetLastError = true)]
1117 private unsafe static extern int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void* lpBuffer, int nSize, IntPtr arguments);
1118
1119 internal static string GetMessage(int errorCode)
1120 {
1121 return GetMessage(errorCode, IntPtr.Zero);
1122 }
1123
1124 internal unsafe static string GetMessage(int errorCode, IntPtr moduleHandle)
1125 {
1126 int num = 12800;
1127 if (moduleHandle != IntPtr.Zero)
1128 {
1129 num |= 0x800;
1130 }
1131 Span<char> span = stackalloc char[256];
1132 fixed (char* lpBuffer = span)
1133 {
1134 int num2 = FormatMessage(num, moduleHandle, (uint)errorCode, 0, lpBuffer, span.Length, IntPtr.Zero);
1135 if (num2 > 0)
1136 {
1137 return GetAndTrimString(span.Slice(0, num2));
1138 }
1139 }
1140 if (Marshal.GetLastWin32Error() == 122)
1141 {
1142 IntPtr intPtr = default(IntPtr);
1143 try
1144 {
1145 int num3 = FormatMessage(num | 0x100, moduleHandle, (uint)errorCode, 0, &intPtr, 0, IntPtr.Zero);
1146 if (num3 > 0)
1147 {
1148 return GetAndTrimString(new Span<char>((void*)intPtr, num3));
1149 }
1150 }
1151 finally
1152 {
1153 Marshal.FreeHGlobal(intPtr);
1154 }
1155 }
1156 return $"Unknown error (0x{errorCode:x})";
1157 }
1158
1159 private static string GetAndTrimString(Span<char> buffer)
1160 {
1161 int num = buffer.Length;
1162 while (num > 0 && buffer[num - 1] <= ' ')
1163 {
1164 num--;
1165 }
1166 return buffer.Slice(0, num).ToString();
1167 }
1168
1169 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "OpenMutexW", ExactSpelling = true, SetLastError = true)]
1170 internal static extern SafeWaitHandle OpenMutex(uint desiredAccess, bool inheritHandle, string name);
1171
1172 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateMutexExW", ExactSpelling = true, SetLastError = true)]
1173 internal static extern SafeWaitHandle CreateMutexEx(IntPtr lpMutexAttributes, string name, uint flags, uint desiredAccess);
1174
1175 [DllImport("kernel32.dll", SetLastError = true)]
1176 internal static extern bool ReleaseMutex(SafeWaitHandle handle);
1177
1178 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "OpenSemaphoreW", ExactSpelling = true, SetLastError = true)]
1179 internal static extern SafeWaitHandle OpenSemaphore(uint desiredAccess, bool inheritHandle, string name);
1180
1181 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateSemaphoreExW", ExactSpelling = true, SetLastError = true)]
1182 internal static extern SafeWaitHandle CreateSemaphoreEx(IntPtr lpSecurityAttributes, int initialCount, int maximumCount, string name, uint flags, uint desiredAccess);
1183
1184 [DllImport("kernel32.dll", SetLastError = true)]
1185 internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
1186
1187 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "SetEnvironmentVariableW", ExactSpelling = true, SetLastError = true)]
1188 internal static extern bool SetEnvironmentVariable(string lpName, string lpValue);
1189
1190 [DllImport("kernel32.dll", SetLastError = true)]
1191 internal unsafe static extern int WriteFile(IntPtr handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);
1192 }
1193
1194 internal static class Normaliz
1195 {
1196 [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1197 internal unsafe static extern int IdnToAscii(uint dwFlags, char* lpUnicodeCharStr, int cchUnicodeChar, char* lpASCIICharStr, int cchASCIIChar);
1198
1199 [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1200 internal unsafe static extern int IdnToUnicode(uint dwFlags, char* lpASCIICharStr, int cchASCIIChar, char* lpUnicodeCharStr, int cchUnicodeChar);
1201
1202 [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1203 internal unsafe static extern BOOL IsNormalizedString(NormalizationForm normForm, char* source, int length);
1204
1205 [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1206 internal unsafe static extern int NormalizeString(NormalizationForm normForm, char* source, int sourceLength, char* destination, int destinationLength);
1207 }
1208
1209 internal static class HostPolicy
1210 {
1211 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
1212 internal delegate void corehost_resolve_component_dependencies_result_fn(string assemblyPaths, string nativeSearchPaths, string resourceSearchPaths);
1213
1214 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
1215 internal delegate void corehost_error_writer_fn(string message);
1216
1217 [DllImport("hostpolicy.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
1218 internal static extern int corehost_resolve_component_dependencies(string componentMainAssemblyPath, corehost_resolve_component_dependencies_result_fn result);
1219
1220 [DllImport("hostpolicy.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
1221 internal static extern IntPtr corehost_set_error_writer(IntPtr errorWriter);
1222 }
1223
1224 internal static class Advapi32
1225 {
1234
1236 {
1237 public long Ptr;
1238
1239 public int Size;
1240
1241 public int Type;
1242 }
1243
1244 internal unsafe delegate void EtwEnableCallback(in Guid sourceId, int isEnabled, byte level, long matchAnyKeywords, long matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, void* callbackContext);
1245
1246 internal enum EVENT_INFO_CLASS
1247 {
1250 SetTraits
1251 }
1252
1261
1262 internal struct TRACE_GUID_INFO
1263 {
1264 public int InstanceCount;
1265
1266 public int Reserved;
1267 }
1268
1270 {
1271 public int NextOffset;
1272
1273 public int EnableCount;
1274
1275 public int Pid;
1276
1277 public int Flags;
1278 }
1279
1280 internal struct TRACE_ENABLE_INFO
1281 {
1282 public int IsEnabled;
1283
1284 public byte Level;
1285
1286 public byte Reserved1;
1287
1288 public ushort LoggerId;
1289
1290 public int EnableProperty;
1291
1292 public int Reserved2;
1293
1294 public long MatchAnyKeyword;
1295
1296 public long MatchAllKeyword;
1297 }
1298
1299 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "EncryptFileW", SetLastError = true)]
1300 private static extern bool EncryptFilePrivate(string lpFileName);
1301
1302 internal static bool EncryptFile(string path)
1303 {
1305 return EncryptFilePrivate(path);
1306 }
1307
1308 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "DecryptFileW", SetLastError = true)]
1309 private static extern bool DecryptFileFilePrivate(string lpFileName, int dwReserved);
1310
1311 internal static bool DecryptFile(string path)
1312 {
1314 return DecryptFileFilePrivate(path, 0);
1315 }
1316
1317 [DllImport("advapi32.dll", ExactSpelling = true)]
1318 internal static extern int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
1319
1320 [DllImport("advapi32.dll", ExactSpelling = true)]
1321 internal unsafe static extern uint EventRegister(in Guid providerId, EtwEnableCallback enableCallback, void* callbackContext, ref long registrationHandle);
1322
1323 [DllImport("advapi32.dll", ExactSpelling = true)]
1324 internal unsafe static extern int EventSetInformation(long registrationHandle, EVENT_INFO_CLASS informationClass, void* eventInformation, uint informationLength);
1325
1326 [DllImport("advapi32.dll", ExactSpelling = true)]
1327 internal unsafe static extern int EnumerateTraceGuidsEx(TRACE_QUERY_INFO_CLASS TraceQueryInfoClass, void* InBuffer, int InBufferSize, void* OutBuffer, int OutBufferSize, out int ReturnLength);
1328
1329 [DllImport("advapi32.dll", ExactSpelling = true)]
1330 internal static extern uint EventUnregister(long registrationHandle);
1331
1332 internal unsafe static int EventWriteTransfer(long registrationHandle, in EventDescriptor eventDescriptor, Guid* activityId, Guid* relatedActivityId, int userDataCount, EventProvider.EventData* userData)
1333 {
1334 int num = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, relatedActivityId, userDataCount, userData);
1335 if (num == 87 && relatedActivityId == null)
1336 {
1337 Guid empty = Guid.Empty;
1338 num = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, &empty, userDataCount, userData);
1339 }
1340 return num;
1341 }
1342
1343 [DllImport("advapi32.dll", EntryPoint = "EventWriteTransfer", ExactSpelling = true)]
1344 private unsafe static extern int EventWriteTransfer_PInvoke(long registrationHandle, in EventDescriptor eventDescriptor, Guid* activityId, Guid* relatedActivityId, int userDataCount, EventProvider.EventData* userData);
1345
1346 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
1347 internal static extern bool LookupAccountNameW(string lpSystemName, ref char lpAccountName, ref byte Sid, ref uint cbSid, ref char ReferencedDomainName, ref uint cchReferencedDomainName, out uint peUse);
1348
1349 [DllImport("advapi32.dll")]
1350 internal static extern int RegCloseKey(IntPtr hKey);
1351
1352 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegDeleteValueW", ExactSpelling = true)]
1353 internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName);
1354
1355 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegEnumKeyExW", ExactSpelling = true)]
1356 internal static extern int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex, char[] lpName, ref int lpcbName, int[] lpReserved, [Out] char[] lpClass, int[] lpcbClass, long[] lpftLastWriteTime);
1357
1358 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegEnumValueW", ExactSpelling = true)]
1359 internal static extern int RegEnumValue(SafeRegistryHandle hKey, int dwIndex, char[] lpValueName, ref int lpcbValueName, IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData, int[] lpcbData);
1360
1361 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegOpenKeyExW", ExactSpelling = true)]
1362 internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
1363
1364 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", ExactSpelling = true)]
1365 internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] byte[] lpData, ref int lpcbData);
1366
1367 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", ExactSpelling = true)]
1368 internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref int lpData, ref int lpcbData);
1369
1370 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", ExactSpelling = true)]
1371 internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref long lpData, ref int lpcbData);
1372
1373 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", ExactSpelling = true)]
1374 internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] char[] lpData, ref int lpcbData);
1375
1376 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW", ExactSpelling = true)]
1377 internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, int dwType, string lpData, int cbData);
1378 }
1379
1380 internal static class BCrypt
1381 {
1382 internal enum NTSTATUS : uint
1383 {
1384 STATUS_SUCCESS = 0u,
1385 STATUS_NOT_FOUND = 3221226021u,
1386 STATUS_INVALID_PARAMETER = 3221225485u,
1387 STATUS_NO_MEMORY = 3221225495u,
1388 STATUS_AUTH_TAG_MISMATCH = 3221266434u
1389 }
1390
1391 [DllImport("BCrypt.dll", CharSet = CharSet.Unicode)]
1392 internal unsafe static extern NTSTATUS BCryptGenRandom(IntPtr hAlgorithm, byte* pbBuffer, int cbBuffer, int dwFlags);
1393 }
1394
1395 internal static class Crypt32
1396 {
1397 [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1398 internal static extern bool CryptProtectMemory(SafeBuffer pData, uint cbData, uint dwFlags);
1399
1400 [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1401 internal static extern bool CryptUnprotectMemory(SafeBuffer pData, uint cbData, uint dwFlags);
1402 }
1403
1404 internal enum BOOLEAN : byte
1405 {
1406 FALSE,
1407 TRUE
1408 }
1409
1410 internal static class NtDll
1411 {
1412 public enum CreateDisposition : uint
1413 {
1415 FILE_OPEN,
1420 }
1421
1422 public enum CreateOptions : uint
1423 {
1425 FILE_WRITE_THROUGH = 2u,
1433 FILE_NO_EA_KNOWLEDGE = 0x200u,
1434 FILE_RANDOM_ACCESS = 0x800u,
1435 FILE_DELETE_ON_CLOSE = 0x1000u,
1436 FILE_OPEN_BY_FILE_ID = 0x2000u,
1438 FILE_NO_COMPRESSION = 0x8000u,
1439 FILE_OPEN_REQUIRING_OPLOCK = 0x10000u,
1440 FILE_DISALLOW_EXCLUSIVE = 0x20000u,
1441 FILE_SESSION_AWARE = 0x40000u,
1442 FILE_RESERVE_OPFILTER = 0x100000u,
1443 FILE_OPEN_REPARSE_POINT = 0x200000u,
1444 FILE_OPEN_NO_RECALL = 0x400000u
1445 }
1446
1447 [Flags]
1448 public enum DesiredAccess : uint
1449 {
1450 FILE_READ_DATA = 1u,
1452 FILE_WRITE_DATA = 2u,
1453 FILE_ADD_FILE = 2u,
1454 FILE_APPEND_DATA = 4u,
1457 FILE_READ_EA = 8u,
1458 FILE_WRITE_EA = 0x10u,
1459 FILE_EXECUTE = 0x20u,
1460 FILE_TRAVERSE = 0x20u,
1461 FILE_DELETE_CHILD = 0x40u,
1462 FILE_READ_ATTRIBUTES = 0x80u,
1463 FILE_WRITE_ATTRIBUTES = 0x100u,
1464 FILE_ALL_ACCESS = 0xF01FFu,
1465 DELETE = 0x10000u,
1466 READ_CONTROL = 0x20000u,
1467 WRITE_DAC = 0x40000u,
1468 WRITE_OWNER = 0x80000u,
1469 SYNCHRONIZE = 0x100000u,
1470 STANDARD_RIGHTS_READ = 0x20000u,
1471 STANDARD_RIGHTS_WRITE = 0x20000u,
1472 STANDARD_RIGHTS_EXECUTE = 0x20000u,
1473 FILE_GENERIC_READ = 0x80000000u,
1474 FILE_GENERIC_WRITE = 0x40000000u,
1475 FILE_GENERIC_EXECUTE = 0x20000000u
1476 }
1477
1478 public struct IO_STATUS_BLOCK
1479 {
1480 [StructLayout(LayoutKind.Explicit)]
1481 public struct IO_STATUS
1482 {
1483 [FieldOffset(0)]
1484 public uint Status;
1485
1486 [FieldOffset(0)]
1488 }
1489
1491
1493 }
1494
1495 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
1497 {
1498 public uint NextEntryOffset;
1499
1500 public uint FileIndex;
1501
1503
1505
1507
1509
1510 public long EndOfFile;
1511
1512 public long AllocationSize;
1513
1515
1516 public uint FileNameLength;
1517
1518 public uint EaSize;
1519
1520 private char _fileName;
1521
1523 {
1524 get
1525 {
1526 fixed (char* pointer = &_fileName)
1527 {
1528 return new ReadOnlySpan<char>(pointer, (int)FileNameLength / 2);
1529 }
1530 }
1531 }
1532
1534 {
1535 if (info == null)
1536 {
1537 return null;
1538 }
1539 uint nextEntryOffset = info->NextEntryOffset;
1540 if (nextEntryOffset == 0)
1541 {
1542 return null;
1543 }
1544 return (FILE_FULL_DIR_INFORMATION*)((byte*)info + nextEntryOffset);
1545 }
1546 }
1547
1548 public enum FILE_INFORMATION_CLASS : uint
1549 {
1618 }
1619
1620 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
1621 internal struct RTL_OSVERSIONINFOEX
1622 {
1623 internal uint dwOSVersionInfoSize;
1624
1625 internal uint dwMajorVersion;
1626
1627 internal uint dwMinorVersion;
1628
1629 internal uint dwBuildNumber;
1630
1631 internal uint dwPlatformId;
1632
1633 internal unsafe fixed char szCSDVersion[128];
1634 }
1635
1637 {
1639
1640 public uint Flags;
1641 }
1642
1643 [DllImport("ntdll.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
1644 private unsafe static extern uint NtCreateFile(IntPtr* FileHandle, DesiredAccess DesiredAccess, OBJECT_ATTRIBUTES* ObjectAttributes, IO_STATUS_BLOCK* IoStatusBlock, long* AllocationSize, FileAttributes FileAttributes, FileShare ShareAccess, CreateDisposition CreateDisposition, CreateOptions CreateOptions, void* EaBuffer, uint EaLength);
1645
1647 {
1648 checked
1649 {
1650 fixed (char* ptr = &MemoryMarshal.GetReference(path))
1651 {
1652 UNICODE_STRING uNICODE_STRING = default(UNICODE_STRING);
1653 uNICODE_STRING.Length = (ushort)(path.Length * 2);
1654 uNICODE_STRING.MaximumLength = (ushort)(path.Length * 2);
1655 uNICODE_STRING.Buffer = (IntPtr)ptr;
1656 UNICODE_STRING uNICODE_STRING2 = uNICODE_STRING;
1659 System.Runtime.CompilerServices.Unsafe.SkipInit(out IO_STATUS_BLOCK iO_STATUS_BLOCK);
1661 return (status: item2, handle: item);
1662 }
1663 }
1664 }
1665
1666 [DllImport("ntdll.dll", ExactSpelling = true)]
1667 public static extern uint RtlNtStatusToDosError(int Status);
1668
1669 [DllImport("ntdll.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
1670 public unsafe static extern int NtQueryDirectoryFile(IntPtr FileHandle, IntPtr Event, IntPtr ApcRoutine, IntPtr ApcContext, IO_STATUS_BLOCK* IoStatusBlock, IntPtr FileInformation, uint Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, UNICODE_STRING* FileName, BOOLEAN RestartScan);
1671
1672 [DllImport("ntdll.dll", ExactSpelling = true)]
1673 internal unsafe static extern int NtQueryInformationFile(SafeFileHandle FileHandle, out IO_STATUS_BLOCK IoStatusBlock, void* FileInformation, uint Length, uint FileInformationClass);
1674
1675 [DllImport("ntdll.dll", ExactSpelling = true)]
1676 internal unsafe static extern uint NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, uint SystemInformationLength, uint* ReturnLength);
1677
1678 [DllImport("ntdll.dll", ExactSpelling = true)]
1679 private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation);
1680
1681 internal unsafe static int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi)
1682 {
1683 osvi = default(RTL_OSVERSIONINFOEX);
1684 osvi.dwOSVersionInfoSize = (uint)sizeof(RTL_OSVERSIONINFOEX);
1685 return RtlGetVersion(ref osvi);
1686 }
1687 }
1688
1689 internal struct UNICODE_STRING
1690 {
1691 internal ushort Length;
1692
1693 internal ushort MaximumLength;
1694
1695 internal IntPtr Buffer;
1696 }
1697
1708
1709 public enum ImpersonationLevel : uint
1710 {
1711 Anonymous,
1715 }
1716
1717 public enum ContextTrackingMode : byte
1718 {
1719 Static,
1720 Dynamic
1721 }
1722
1723 internal struct OBJECT_ATTRIBUTES
1724 {
1725 public uint Length;
1726
1728
1730
1732
1733 public unsafe void* SecurityDescriptor;
1734
1736
1737 public unsafe OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory, SECURITY_QUALITY_OF_SERVICE* securityQualityOfService = null)
1738 {
1739 Length = (uint)sizeof(OBJECT_ATTRIBUTES);
1740 RootDirectory = rootDirectory;
1741 ObjectName = objectName;
1742 Attributes = attributes;
1743 SecurityDescriptor = null;
1744 SecurityQualityOfService = securityQualityOfService;
1745 }
1746 }
1747
1748 [Flags]
1749 public enum ObjectAttributes : uint
1750 {
1751 OBJ_INHERIT = 2u,
1752 OBJ_PERMANENT = 0x10u,
1753 OBJ_EXCLUSIVE = 0x20u,
1754 OBJ_CASE_INSENSITIVE = 0x40u,
1755 OBJ_OPENIF = 0x80u,
1756 OBJ_OPENLINK = 0x100u
1757 }
1758
1759 internal static class Ole32
1760 {
1761 [DllImport("ole32.dll", CharSet = CharSet.Unicode)]
1762 internal static extern int CLSIDFromProgID(string lpszProgID, out Guid lpclsid);
1763
1764 [DllImport("ole32.dll")]
1765 internal static extern int CoCreateGuid(out Guid guid);
1766
1767 [DllImport("ole32.dll")]
1768 internal static extern int CoGetStandardMarshal(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out IntPtr ppMarshal);
1769
1770 [DllImport("ole32.dll")]
1771 internal static extern IntPtr CoTaskMemAlloc(nuint cb);
1772
1773 [DllImport("ole32.dll")]
1774 internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, nuint cb);
1775
1776 [DllImport("ole32.dll")]
1777 internal static extern void CoTaskMemFree(IntPtr ptr);
1778 }
1779
1780 internal static class Secur32
1781 {
1782 [DllImport("secur32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
1783 internal static extern BOOLEAN GetUserNameExW(int NameFormat, ref char lpNameBuffer, ref uint lpnSize);
1784 }
1785
1786 internal static class Shell32
1787 {
1788 [DllImport("shell32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)]
1789 internal static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string ppszPath);
1790 }
1791
1792 internal static class Ucrtbase
1793 {
1794 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1795 internal unsafe static extern void* _aligned_malloc(nuint size, nuint alignment);
1796
1797 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1798 internal unsafe static extern void _aligned_free(void* ptr);
1799
1800 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1801 internal unsafe static extern void* _aligned_realloc(void* ptr, nuint size, nuint alignment);
1802
1803 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1804 internal unsafe static extern void* calloc(nuint num, nuint size);
1805
1806 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1807 internal unsafe static extern void free(void* ptr);
1808
1809 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1810 internal unsafe static extern void* malloc(nuint size);
1811
1812 [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
1813 internal unsafe static extern void* realloc(void* ptr, nuint new_size);
1814 }
1815
1816 internal static class User32
1817 {
1818 internal struct USEROBJECTFLAGS
1819 {
1820 public int fInherit;
1821
1822 public int fReserved;
1823
1824 public int dwFlags;
1825 }
1826
1827 [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadStringW", ExactSpelling = true, SetLastError = true)]
1828 internal unsafe static extern int LoadString(IntPtr hInstance, uint uID, char* lpBuffer, int cchBufferMax);
1829
1830 [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutW")]
1831 public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult);
1832
1833 [DllImport("user32.dll", ExactSpelling = true)]
1834 internal static extern IntPtr GetProcessWindowStation();
1835
1836 [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
1837 public unsafe static extern bool GetUserObjectInformationW(IntPtr hObj, int nIndex, void* pvBuffer, uint nLength, ref uint lpnLengthNeeded);
1838 }
1839
1840 internal struct LongFileTime
1841 {
1842 internal long TicksSince1601;
1843
1848 }
1849
1850 internal static bool CallStringMethod<TArg1, TArg2, TArg3>(SpanFunc<char, TArg1, TArg2, TArg3, Globalization.ResultCode> interopCall, TArg1 arg1, TArg2 arg2, TArg3 arg3, out string result)
1851 {
1852 Span<char> span = stackalloc char[256];
1853 switch (interopCall(span, arg1, arg2, arg3))
1854 {
1855 case Globalization.ResultCode.Success:
1856 result = span.Slice(0, span.IndexOf('\0')).ToString();
1857 return true;
1858 case Globalization.ResultCode.InsufficentBuffer:
1859 span = new char[1280];
1860 if (interopCall(span, arg1, arg2, arg3) == Globalization.ResultCode.Success)
1861 {
1862 result = span.Slice(0, span.IndexOf('\0')).ToString();
1863 return true;
1864 }
1865 break;
1866 }
1867 result = null;
1868 return false;
1869 }
1870
1871 internal unsafe static void GetRandomBytes(byte* buffer, int length)
1872 {
1874 {
1875 case BCrypt.NTSTATUS.STATUS_NO_MEMORY:
1876 throw new OutOfMemoryException();
1877 default:
1878 throw new InvalidOperationException();
1879 case BCrypt.NTSTATUS.STATUS_SUCCESS:
1880 break;
1881 }
1882 }
1883}
static int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId)
static int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, int dwType, string lpData, int cbData)
static int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] byte[] lpData, ref int lpcbData)
static int RegEnumValue(SafeRegistryHandle hKey, int dwIndex, char[] lpValueName, ref int lpcbValueName, IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData, int[] lpcbData)
static bool EncryptFile(string path)
Definition Interop.cs:1302
static uint EventUnregister(long registrationHandle)
static int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref int lpData, ref int lpcbData)
static bool DecryptFileFilePrivate(string lpFileName, int dwReserved)
static int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex, char[] lpName, ref int lpcbName, int[] lpReserved, [Out] char[] lpClass, int[] lpcbClass, long[] lpftLastWriteTime)
static unsafe int EventWriteTransfer_PInvoke(long registrationHandle, in EventDescriptor eventDescriptor, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData)
static unsafe int EnumerateTraceGuidsEx(TRACE_QUERY_INFO_CLASS TraceQueryInfoClass, void *InBuffer, int InBufferSize, void *OutBuffer, int OutBufferSize, out int ReturnLength)
static bool LookupAccountNameW(string lpSystemName, ref char lpAccountName, ref byte Sid, ref uint cbSid, ref char ReferencedDomainName, ref uint cchReferencedDomainName, out uint peUse)
static int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] char[] lpData, ref int lpcbData)
static bool EncryptFilePrivate(string lpFileName)
static unsafe uint EventRegister(in Guid providerId, EtwEnableCallback enableCallback, void *callbackContext, ref long registrationHandle)
static unsafe int EventWriteTransfer(long registrationHandle, in EventDescriptor eventDescriptor, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData)
Definition Interop.cs:1332
static int RegOpenKeyEx(SafeRegistryHandle hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult)
unsafe delegate void EtwEnableCallback(in Guid sourceId, int isEnabled, byte level, long matchAnyKeywords, long matchAllKeywords, EVENT_FILTER_DESCRIPTOR *filterData, void *callbackContext)
static int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName)
static bool DecryptFile(string path)
Definition Interop.cs:1311
static unsafe int EventSetInformation(long registrationHandle, EVENT_INFO_CLASS informationClass, void *eventInformation, uint informationLength)
static int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref long lpData, ref int lpcbData)
static int RegCloseKey(IntPtr hKey)
static unsafe NTSTATUS BCryptGenRandom(IntPtr hAlgorithm, byte *pbBuffer, int cbBuffer, int dwFlags)
static bool CryptUnprotectMemory(SafeBuffer pData, uint cbData, uint dwFlags)
static bool CryptProtectMemory(SafeBuffer pData, uint cbData, uint dwFlags)
static bool IsPredefinedLocale(string localeName)
static int GetICUVersion()
static unsafe void ChangeCaseInvariant(char *src, int srcLen, char *dstBuffer, int dstBufferCapacity, bool bToUpper)
static unsafe int GetSortKey(IntPtr sortHandle, char *str, int strLength, byte *sortKey, int sortKeyLength, CompareOptions options)
static unsafe void ChangeCaseTurkish(char *src, int srcLen, char *dstBuffer, int dstBufferCapacity, bool bToUpper)
static unsafe bool GetLocaleName(string localeName, char *value, int valueLength)
static unsafe int IndexOf(IntPtr sortHandle, char *target, int cwTargetLength, char *pSource, int cwSourceLength, CompareOptions options, int *matchLengthPtr)
static unsafe bool GetLocaleTimeFormat(string localeName, bool shortFormat, char *value, int valueLength)
static void InitICUFunctions(IntPtr icuuc, IntPtr icuin, string version, string suffix)
static unsafe void ChangeCase(char *src, int srcLen, char *dstBuffer, int dstBufferCapacity, bool bToUpper)
static void CloseSortHandle(IntPtr handle)
static unsafe ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char *result, int resultCapacity)
static int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity)
static ResultCode GetSortHandle(string localeName, out IntPtr sortHandle)
static int GetSortVersion(IntPtr sortHandle)
static int GetLatestJapaneseEra()
static unsafe bool StartsWith(IntPtr sortHandle, char *target, int cwTargetLength, char *source, int cwSourceLength, CompareOptions options, int *matchedLength)
static unsafe int IsNormalized(NormalizationForm normalizationForm, char *src, int srcLen)
static unsafe int ToUnicode(uint flags, char *src, int srcLen, char *dstBuffer, int dstBufferCapacity)
static unsafe void InitOrdinalCasingPage(int pageNumber, char *pTarget)
static unsafe int CompareString(IntPtr sortHandle, char *lpStr1, int cwStr1Len, char *lpStr2, int cwStr2Len, CompareOptions options)
static void InitICUFunctions(IntPtr icuuc, IntPtr icuin, ReadOnlySpan< char > version, ReadOnlySpan< char > suffix)
Definition Interop.cs:99
static unsafe bool GetLocaleInfoString(string localeName, uint localeStringData, char *value, int valueLength, string uiLocaleName=null)
static unsafe bool EnumCalendarInfo(delegate *unmanaged< char *, IntPtr, void > callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context)
static bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value)
static int LoadICU()
static unsafe int NormalizeString(NormalizationForm normalizationForm, char *src, int srcLen, char *dstBuffer, int dstBufferCapacity)
static unsafe int IanaIdToWindowsId(string ianaId, char *windowsId, int windowsIdLength)
static int GetLocales([Out] char[] value, int valueLength)
static unsafe int LastIndexOf(IntPtr sortHandle, char *target, int cwTargetLength, char *pSource, int cwSourceLength, CompareOptions options, int *matchLengthPtr)
static unsafe int ToAscii(uint flags, char *src, int srcLen, char *dstBuffer, int dstBufferCapacity)
static unsafe int WindowsIdToIanaId(string windowsId, IntPtr region, char *ianaId, int ianaIdLength)
static unsafe bool EndsWith(IntPtr sortHandle, char *target, int cwTargetLength, char *source, int cwSourceLength, CompareOptions options, int *matchedLength)
static bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize)
static bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay)
static int corehost_resolve_component_dependencies(string componentMainAssemblyPath, corehost_resolve_component_dependencies_result_fn result)
delegate void corehost_resolve_component_dependencies_result_fn(string assemblyPaths, string nativeSearchPaths, string resourceSearchPaths)
static IntPtr corehost_set_error_writer(IntPtr errorWriter)
delegate void corehost_error_writer_fn(string message)
static unsafe int ResolveLocaleName(string lpNameToResolve, char *lpLocaleName, int cchLocaleName)
static int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, out int lpValue)
static unsafe void InitializeCriticalSection(CRITICAL_SECTION *lpCriticalSection)
static bool ReplaceFile(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
Definition Interop.cs:1018
static bool FindClose(IntPtr hFindFile)
static bool RemoveDirectoryPrivate(string path)
static unsafe bool GetVolumeInformation(string drive, char *volumeName, int volumeNameBufLen, int *volSerialNumber, int *maxFileNameLen, out int fileSystemFlags, char *fileSystemName, int fileSystemNameBufLen)
static bool SetEnvironmentVariable(string lpName, string lpValue)
static ulong VerSetConditionMask(ulong ConditionMask, uint TypeMask, byte Condition)
static IntPtr GetStdHandle(int nStdHandle)
static unsafe BOOL GetCPInfo(uint codePage, CPINFO *lpCpInfo)
static bool ReleaseMutex(SafeWaitHandle handle)
static unsafe int WriteFileGather(SafeHandle hFile, long *aSegmentArray, int nNumberOfBytesToWrite, IntPtr lpReserved, NativeOverlapped *lpOverlapped)
static bool SetCurrentDirectory(string path)
static unsafe bool EnumSystemLocalesEx(delegate *unmanaged< char *, uint, void *, BOOL > lpLocaleEnumProcEx, uint dwFlags, void *lParam, IntPtr reserved)
static unsafe int LCMapStringEx(string lpLocaleName, uint dwMapFlags, char *lpSrcStr, int cchSrc, void *lpDestStr, int cchDest, void *lpVersionInformation, void *lpReserved, IntPtr sortHandle)
static int GetLogicalDrives()
static uint GetEnvironmentVariable(string lpName, ref char lpBuffer, uint nSize)
static Microsoft.Win32.SafeHandles.SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags)
static bool ResetEvent(SafeWaitHandle handle)
static uint GetFullPathNameW(ref char lpFileName, uint nBufferLength, ref char lpBuffer, IntPtr lpFilePart)
static unsafe int WriteFile(IntPtr handle, byte *bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero)
static unsafe BOOL QueryPerformanceFrequency(long *lpFrequency)
static bool GetProcessMemoryInfo(IntPtr Process, ref PROCESS_MEMORY_COUNTERS ppsmemCounters, uint cb)
static unsafe UIntPtr VirtualQuery(void *lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, UIntPtr dwLength)
static unsafe void LeaveCriticalSection(CRITICAL_SECTION *lpCriticalSection)
static bool DeleteFilePrivate(string path)
static bool RemoveDirectory(string path)
Definition Interop.cs:1009
static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
Definition Interop.cs:834
static unsafe int WriteFile(SafeHandle handle, byte *bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped *lpOverlapped)
static void OutputDebugString(string message)
static bool DeleteVolumeMountPointPrivate(string mountPoint)
static SafeWaitHandle CreateSemaphoreEx(IntPtr lpSecurityAttributes, int initialCount, int maximumCount, string name, uint flags, uint desiredAccess)
static bool PostQueuedCompletionStatus(IntPtr CompletionPort, int dwNumberOfBytesTransferred, UIntPtr CompletionKey, IntPtr lpOverlapped)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
Definition Interop.cs:1124
static bool FreeLibrary(IntPtr hModule)
static unsafe BOOL GetUserPreferredUILanguages(uint dwFlags, uint *pulNumLanguages, char *pwszLanguagesBuffer, uint *pcchLanguagesBuffer)
static unsafe BOOL TzSpecificLocalTimeToSystemTime(IntPtr lpTimeZoneInformation, SYSTEMTIME *lpLocalTime, SYSTEMTIME *lpUniversalTime)
static void SetLastError(int errorCode)
static IntPtr LocalFree(IntPtr hMem)
static SafeWaitHandle OpenEvent(uint desiredAccess, bool inheritHandle, string name)
static unsafe bool GetNLSVersionEx(int function, string localeName, NlsVersionInfoEx *lpVersionInformation)
static uint GetTempPathW(int bufferLen, ref char buffer)
static unsafe bool CancelIoEx(SafeHandle handle, NativeOverlapped *lpOverlapped)
static unsafe SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
Definition Interop.cs:741
static unsafe IntPtr CreateFilePrivate_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
static uint GetSystemDirectoryW(ref char lpBuffer, uint uSize)
static unsafe SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
Definition Interop.cs:735
static int CopyFile(string src, string dst, bool failIfExists)
Definition Interop.cs:702
static bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount)
static unsafe void * VirtualAlloc(void *lpAddress, UIntPtr dwSize, int flAllocationType, int flProtect)
static void GetSystemInfo(out SYSTEM_INFO lpSystemInfo)
static unsafe bool VirtualFree(void *lpAddress, UIntPtr dwSize, int dwFreeType)
static unsafe bool SleepConditionVariableCS(CONDITION_VARIABLE *ConditionVariable, CRITICAL_SECTION *CriticalSection, int dwMilliseconds)
static uint GetCurrentProcessId()
static unsafe BOOL GlobalMemoryStatusEx(MEMORYSTATUSEX *lpBuffer)
static int LocaleNameToLCID(string lpName, uint dwFlags)
static unsafe int ReadFileScatter(SafeHandle hFile, long *aSegmentArray, int nNumberOfBytesToRead, IntPtr lpReserved, NativeOverlapped *lpOverlapped)
static bool MoveFile(string src, string dst, bool overwrite)
Definition Interop.cs:969
static bool CloseHandle(IntPtr handle)
static bool CopyFileEx(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags)
Definition Interop.cs:716
static bool GetProcessTimes(IntPtr handleProcess, out long creation, out long exit, out long kernel, out long user)
static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, char *lpWideCharStr, int cchWideChar, byte *lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar)
static bool DeleteFile(string path)
Definition Interop.cs:750
static unsafe void InitializeConditionVariable(CONDITION_VARIABLE *ConditionVariable)
static unsafe BOOL FileTimeToSystemTime(ulong *lpFileTime, SYSTEMTIME *lpSystemTime)
static IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags)
static unsafe BOOL QueryPerformanceCounter(long *lpPerformanceCount)
static int GetComputerName(ref char lpBuffer, ref uint nSize)
static unsafe int MultiByteToWideChar(uint CodePage, uint dwFlags, byte *lpMultiByteStr, int cbMultiByte, char *lpWideCharStr, int cchWideChar)
static unsafe int GetGeoInfo(int location, int geoType, char *lpGeoData, int cchData, int LangId)
static bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode)
static uint ExpandEnvironmentStrings(string lpSrc, ref char lpDst, uint nSize)
static uint GetLongPathNameW(ref char lpszShortPath, ref char lpszLongPath, uint cchBuffer)
static bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh)
static uint GetTempFileNameW(ref char lpPathName, string lpPrefixString, uint uUnique, ref char lpTempFileName)
static unsafe bool EnumCalendarInfoExEx(delegate *unmanaged< char *, uint, IntPtr, void *, BOOL > pCalInfoEnumProcExEx, string lpLocaleName, uint Calendar, string lpReserved, uint CalType, void *lParam)
static bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer, uint dwMoveMethod)
static SafeWaitHandle CreateMutexEx(IntPtr lpMutexAttributes, string name, uint flags, uint desiredAccess)
static unsafe void DeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection)
static bool CreateSymbolicLinkPrivate(string lpSymlinkFileName, string lpTargetFileName, int dwFlags)
static unsafe bool SetConsoleCtrlHandler(delegate *unmanaged< int, BOOL > HandlerRoutine, bool Add)
static unsafe int WriteFile(SafeHandle handle, byte *bytes, int numBytesToWrite, out int numBytesWritten, NativeOverlapped *lpOverlapped)
static unsafe bool SetFileInformationByHandle(SafeFileHandle hFile, int FileInformationClass, void *lpFileInformation, uint dwBufferSize)
static string GetMessage(int errorCode)
Definition Interop.cs:1119
static bool ReplaceFilePrivate(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
static unsafe IntPtr CreateFile_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
Definition Interop.cs:768
static unsafe int ReadFile(SafeHandle handle, byte *bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped *overlapped)
static unsafe int CompareStringOrdinal(char *lpString1, int cchCount1, char *lpString2, int cchCount2, bool bIgnoreCase)
static unsafe char * GetEnvironmentStringsW()
static IntPtr LocalReAlloc(IntPtr hMem, nuint uBytes, uint uFlags)
static bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime)
static bool CopyFileExPrivate(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags)
static uint GetModuleFileName(IntPtr hModule, ref char lpFilename, uint nSize)
static bool GetQueuedCompletionStatus(IntPtr CompletionPort, out int lpNumberOfBytes, out UIntPtr CompletionKey, out IntPtr lpOverlapped, int dwMilliseconds)
static unsafe int FindNLSStringEx(char *lpLocaleName, uint dwFindNLSStringFlags, char *lpStringSource, int cchSource, char *lpStringValue, int cchValue, int *pcchFound, void *lpVersionInformation, void *lpReserved, IntPtr sortHandle)
static unsafe BOOL FreeEnvironmentStringsW(char *lpszEnvironmentBlock)
static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
Definition Interop.cs:880
static bool MoveFileExPrivate(string src, string dst, uint flags)
static bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask)
static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
Definition Interop.cs:726
static uint GetCurrentDirectory(uint nBufferLength, ref char lpBuffer)
static bool DeleteVolumeMountPoint(string mountPoint)
Definition Interop.cs:759
static bool CreateDirectoryPrivate(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
static SafeWaitHandle OpenMutex(uint desiredAccess, bool inheritHandle, string name)
static unsafe void GetSystemTime(SYSTEMTIME *lpSystemTime)
static unsafe bool GetFileInformationByHandleEx(SafeFileHandle hFile, int FileInformationClass, void *lpFileInformation, uint dwBufferSize)
static IntPtr GetCurrentProcess()
static unsafe SafeFileHandle CreateFilePrivate(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
static unsafe int ReadFile(SafeHandle handle, byte *bytes, int numBytesToRead, out int numBytesRead, NativeOverlapped *overlapped)
static IntPtr CreateIoCompletionPort(IntPtr FileHandle, IntPtr ExistingCompletionPort, UIntPtr CompletionKey, int NumberOfConcurrentThreads)
static bool SetFileAttributesPrivate(string name, int attr)
static bool SetFileAttributes(string name, int attr)
Definition Interop.cs:1035
static bool FindNextFile(SafeFindHandle hndFindFile, ref WIN32_FIND_DATA lpFindFileData)
static unsafe void WakeConditionVariable(CONDITION_VARIABLE *ConditionVariable)
static bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh)
static unsafe int FindStringOrdinal(uint dwFindStringOrdinalFlags, char *lpStringSource, int cchSource, char *lpStringValue, int cchValue, BOOL bIgnoreCase)
static bool DeviceIoControl(SafeHandle hDevice, uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, byte[] lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned, IntPtr lpOverlapped)
static uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation)
static void CreateSymbolicLink(string symlinkFileName, string targetFileName, bool isDirectory)
Definition Interop.cs:777
static unsafe int LCIDToLocaleName(int locale, char *pLocaleName, int cchName, uint dwFlags)
static bool GetSystemTimes(out long idle, out long kernel, out long user)
static uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation)
static bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static int GetLastError()
static int GetFileType(SafeHandle hFile)
static unsafe int CompareStringEx(char *lpLocaleName, uint dwCmpFlags, char *lpString1, int cchCount1, char *lpString2, int cchCount2, void *lpVersionInformation, void *lpReserved, IntPtr lParam)
static bool SetEvent(SafeWaitHandle handle)
static unsafe BOOL SystemTimeToFileTime(SYSTEMTIME *lpSystemTime, ulong *lpFileTime)
static IntPtr LocalAlloc(uint uFlags, nuint uBytes)
static string GetComputerName()
Definition Interop.cs:854
static int GetUserGeoID(int geoClass)
static unsafe bool IsNLSDefinedString(int Function, uint dwFlags, IntPtr lpVersionInformation, char *lpString, int cchStr)
static SafeWaitHandle OpenSemaphore(uint desiredAccess, bool inheritHandle, string name)
static SafeWaitHandle CreateEventEx(IntPtr lpSecurityAttributes, string name, uint flags, uint desiredAccess)
static unsafe bool GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped *lpOverlapped, ref int lpNumberOfBytesTransferred, bool bWait)
static unsafe void EnterCriticalSection(CRITICAL_SECTION *lpCriticalSection)
static unsafe int GetLocaleInfoEx(string lpLocaleName, uint LCType, void *lpLCData, int cchData)
static SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags)
static bool FlushFileBuffers(SafeHandle hHandle)
static int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, IntPtr lpValue)
static unsafe uint GetFinalPathNameByHandle(SafeFileHandle hFile, char *lpszFilePath, uint cchFilePath, uint dwFlags)
static string GetAndTrimString(Span< char > buffer)
Definition Interop.cs:153
static unsafe bool EnumTimeFormatsEx(delegate *unmanaged< char *, void *, BOOL > lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, void *lParam)
static unsafe int NormalizeString(NormalizationForm normForm, char *source, int sourceLength, char *destination, int destinationLength)
static unsafe int IdnToAscii(uint dwFlags, char *lpUnicodeCharStr, int cchUnicodeChar, char *lpASCIICharStr, int cchASCIIChar)
static unsafe BOOL IsNormalizedString(NormalizationForm normForm, char *source, int length)
static unsafe int IdnToUnicode(uint dwFlags, char *lpASCIICharStr, int cchASCIIChar, char *lpUnicodeCharStr, int cchUnicodeChar)
static IntPtr CreateDisposition createDisposition
Definition Interop.cs:1646
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions ObjectAttributes void * eaBuffer
Definition Interop.cs:1646
static unsafe(uint status, IntPtr handle) CreateFile(ReadOnlySpan< char > path
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions ObjectAttributes void uint long * preallocationSize
Definition Interop.cs:1646
static IntPtr CreateDisposition DesiredAccess FileShare shareAccess
Definition Interop.cs:1646
static unsafe int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi)
Definition Interop.cs:1681
static IntPtr CreateDisposition DesiredAccess desiredAccess
Definition Interop.cs:1646
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions ObjectAttributes void uint eaLength
Definition Interop.cs:1646
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions ObjectAttributes void uint long SECURITY_QUALITY_OF_SERVICE * securityQualityOfService
Definition Interop.cs:1646
static IntPtr rootDirectory
Definition Interop.cs:1646
static unsafe int NtQueryDirectoryFile(IntPtr FileHandle, IntPtr Event, IntPtr ApcRoutine, IntPtr ApcContext, IO_STATUS_BLOCK *IoStatusBlock, IntPtr FileInformation, uint Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, UNICODE_STRING *FileName, BOOLEAN RestartScan)
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes fileAttributes
Definition Interop.cs:1646
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions ObjectAttributes objectAttributes
Definition Interop.cs:1646
static unsafe uint NtQuerySystemInformation(int SystemInformationClass, void *SystemInformation, uint SystemInformationLength, uint *ReturnLength)
static unsafe int NtQueryInformationFile(SafeFileHandle FileHandle, out IO_STATUS_BLOCK IoStatusBlock, void *FileInformation, uint Length, uint FileInformationClass)
static int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation)
static IntPtr CreateDisposition DesiredAccess FileShare FileAttributes CreateOptions createOptions
Definition Interop.cs:1646
static unsafe uint NtCreateFile(IntPtr *FileHandle, DesiredAccess DesiredAccess, OBJECT_ATTRIBUTES *ObjectAttributes, IO_STATUS_BLOCK *IoStatusBlock, long *AllocationSize, FileAttributes FileAttributes, FileShare ShareAccess, CreateDisposition CreateDisposition, CreateOptions CreateOptions, void *EaBuffer, uint EaLength)
static int CoGetStandardMarshal(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out IntPtr ppMarshal)
static IntPtr CoTaskMemRealloc(IntPtr pv, nuint cb)
static void CoTaskMemFree(IntPtr ptr)
static IntPtr CoTaskMemAlloc(nuint cb)
static int CoCreateGuid(out Guid guid)
static int CLSIDFromProgID(string lpszProgID, out Guid lpclsid)
static IntPtr SysAllocStringLen(IntPtr src, uint len)
static void SysFreeString(IntPtr bstr)
static IntPtr SysAllocStringByteLen(byte[] str, uint len)
static void VariantClear(IntPtr variant)
static BOOLEAN GetUserNameExW(int NameFormat, ref char lpNameBuffer, ref uint lpnSize)
static int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string ppszPath)
static unsafe void * _aligned_malloc(nuint size, nuint alignment)
static unsafe void * realloc(void *ptr, nuint new_size)
static unsafe void _aligned_free(void *ptr)
static unsafe void free(void *ptr)
static unsafe void * _aligned_realloc(void *ptr, nuint size, nuint alignment)
static unsafe void * malloc(nuint size)
static unsafe void * calloc(nuint num, nuint size)
static IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult)
static IntPtr GetProcessWindowStation()
static unsafe bool GetUserObjectInformationW(IntPtr hObj, int nIndex, void *pvBuffer, uint nLength, ref uint lpnLengthNeeded)
static unsafe int LoadString(IntPtr hInstance, uint uID, char *lpBuffer, int cchBufferMax)
ObjectAttributes
Definition Interop.cs:1750
ContextTrackingMode
Definition Interop.cs:1718
static unsafe void GetRandomBytes(byte *buffer, int length)
Definition Interop.cs:1871
static bool CallStringMethod< TArg1, TArg2, TArg3 >(SpanFunc< char, TArg1, TArg2, TArg3, Globalization.ResultCode > interopCall, TArg1 arg1, TArg2 arg2, TArg3 arg3, out string result)
Definition Interop.cs:1850
ImpersonationLevel
Definition Interop.cs:1710
static OperatingSystem OSVersion
static string EnsureExtendedPrefix(string path)
static string EnsureExtendedPrefixIfNeeded(string path)
static Exception GetExceptionForLastWin32Error(string path="")
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
DayOfWeek
Definition DayOfWeek.cs:4
unsafe fixed byte LeadByte[12]
Definition Interop.cs:277
unsafe fixed byte DefaultChar[2]
Definition Interop.cs:275
DateTimeOffset ToDateTimeOffset()
Definition Interop.cs:244
unsafe fixed char szCSDVersion[128]
Definition Interop.cs:354
REG_TZI_FORMAT(in TIME_ZONE_INFORMATION tzi)
Definition Interop.cs:552
bool Equals(in SYSTEMTIME other)
Definition Interop.cs:455
unsafe fixed char StandardName[32]
Definition Interop.cs:500
unsafe fixed char DaylightName[32]
Definition Interop.cs:506
unsafe TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi)
Definition Interop.cs:512
void PopulateFrom(ref WIN32_FIND_DATA findData)
Definition Interop.cs:576
unsafe fixed char _cAlternateFileName[14]
Definition Interop.cs:99
unsafe ReadOnlySpan< char > cFileName
Definition Interop.cs:611
unsafe fixed char _cFileName[260]
Definition Interop.cs:97
DateTimeOffset ToDateTimeOffset()
Definition Interop.cs:1844
unsafe ReadOnlySpan< char > FileName
Definition Interop.cs:1523
static unsafe FILE_FULL_DIR_INFORMATION * GetNextInfo(FILE_FULL_DIR_INFORMATION *info)
Definition Interop.cs:1533
unsafe fixed char szCSDVersion[128]
Definition Interop.cs:1633
unsafe void * SecurityDescriptor
Definition Interop.cs:1733
unsafe SECURITY_QUALITY_OF_SERVICE * SecurityQualityOfService
Definition Interop.cs:1735
unsafe OBJECT_ATTRIBUTES(UNICODE_STRING *objectName, ObjectAttributes attributes, IntPtr rootDirectory, SECURITY_QUALITY_OF_SERVICE *securityQualityOfService=null)
Definition Interop.cs:1737
unsafe UNICODE_STRING * ObjectName
Definition Interop.cs:1729
ObjectAttributes Attributes
Definition Interop.cs:1731
ImpersonationLevel ImpersonationLevel
Definition Interop.cs:1702
ContextTrackingMode ContextTrackingMode
Definition Interop.cs:1704
static DateTimeOffset FromFileTime(long fileTime)
static DateTime FromFileTimeUtc(long fileTime)
Definition DateTime.cs:718
static readonly Guid Empty
Definition Guid.cs:86
static readonly IntPtr Zero
Definition IntPtr.cs:18
override string ToString()
Span< T > Slice(int start)
Definition Span.cs:271
int Length
Definition Span.cs:70