Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
7
8internal static class Interop
9{
10 internal static class Kernel32
11 {
12 internal struct PROCESS_INFORMATION
13 {
14 internal IntPtr hProcess;
15
16 internal IntPtr hThread;
17
18 internal int dwProcessId;
19
20 internal int dwThreadId;
21 }
22
23 internal struct STARTUPINFO
24 {
25 internal int cb;
26
28
29 internal IntPtr lpDesktop;
30
31 internal IntPtr lpTitle;
32
33 internal int dwX;
34
35 internal int dwY;
36
37 internal int dwXSize;
38
39 internal int dwYSize;
40
41 internal int dwXCountChars;
42
43 internal int dwYCountChars;
44
45 internal int dwFillAttribute;
46
47 internal int dwFlags;
48
49 internal short wShowWindow;
50
51 internal short cbReserved2;
52
54
55 internal IntPtr hStdInput;
56
58
59 internal IntPtr hStdError;
60 }
61
62 internal struct NtModuleInfo
63 {
64 internal IntPtr BaseOfDll;
65
66 internal int SizeOfImage;
67
69 }
70
71 internal sealed class ProcessWaitHandle : WaitHandle
72 {
73 internal ProcessWaitHandle(SafeProcessHandle processHandle)
74 {
75 IntPtr currentProcess = GetCurrentProcess();
76 if (!DuplicateHandle(currentProcess, (SafeHandle)processHandle, currentProcess, out SafeWaitHandle targetHandle, 0, bInheritHandle: false, 2))
77 {
78 int hRForLastWin32Error = Marshal.GetHRForLastWin32Error();
79 targetHandle.Dispose();
80 Marshal.ThrowExceptionForHR(hRForLastWin32Error);
81 }
82 this.SetSafeWaitHandle(targetHandle);
83 }
84 }
85
86 internal struct SECURITY_ATTRIBUTES
87 {
88 internal uint nLength;
89
91
93 }
94
95 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
96 private struct CPINFOEXW
97 {
98 internal uint MaxCharSize;
99
100 internal unsafe fixed byte DefaultChar[2];
101
102 internal unsafe fixed byte LeadByte[12];
103
104 internal char UnicodeDefaultChar;
105
106 internal uint CodePage;
107
108 internal unsafe fixed char CodePageName[260];
109 }
110
111 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "K32EnumProcessModules", SetLastError = true)]
112 internal static extern bool EnumProcessModules(SafeProcessHandle handle, IntPtr[] modules, int size, out int needed);
113
114 [DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", ExactSpelling = true, SetLastError = true)]
115 private unsafe static extern int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void* lpBuffer, int nSize, IntPtr arguments);
116
117 internal static string GetMessage(int errorCode)
118 {
119 return GetMessage(errorCode, IntPtr.Zero);
120 }
121
122 internal unsafe static string GetMessage(int errorCode, IntPtr moduleHandle)
123 {
124 int num = 12800;
125 if (moduleHandle != IntPtr.Zero)
126 {
127 num |= 0x800;
128 }
129 Span<char> span = stackalloc char[256];
130 fixed (char* lpBuffer = span)
131 {
132 int num2 = FormatMessage(num, moduleHandle, (uint)errorCode, 0, lpBuffer, span.Length, IntPtr.Zero);
133 if (num2 > 0)
134 {
135 return GetAndTrimString(span.Slice(0, num2));
136 }
137 }
138 if (Marshal.GetLastWin32Error() == 122)
139 {
140 IntPtr intPtr = default(IntPtr);
141 try
142 {
143 int num3 = FormatMessage(num | 0x100, moduleHandle, (uint)errorCode, 0, &intPtr, 0, IntPtr.Zero);
144 if (num3 > 0)
145 {
146 return GetAndTrimString(new Span<char>((void*)intPtr, num3));
147 }
148 }
149 finally
150 {
151 Marshal.FreeHGlobal(intPtr);
152 }
153 }
154 return $"Unknown error (0x{errorCode:x})";
155 }
156
157 private static string GetAndTrimString(Span<char> buffer)
158 {
159 int num = buffer.Length;
160 while (num > 0 && buffer[num - 1] <= ' ')
161 {
162 num--;
163 }
164 return buffer.Slice(0, num).ToString();
165 }
166
167 [DllImport("kernel32.dll", SetLastError = true)]
168 internal static extern bool CloseHandle(IntPtr handle);
169
170 [DllImport("kernel32.dll", SetLastError = true)]
171 internal static extern bool IsWow64Process(IntPtr hProcess, out bool Wow64Process);
172
173 [DllImport("kernel32.dll", SetLastError = true)]
174 internal static extern bool IsWow64Process(SafeProcessHandle hProcess, out bool Wow64Process);
175
176 [DllImport("kernel32.dll", SetLastError = true)]
177 internal static extern bool GetExitCodeProcess(SafeProcessHandle processHandle, out int exitCode);
178
179 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
180 internal static extern bool GetProcessTimes(SafeProcessHandle handle, out long creation, out long exit, out long kernel, out long user);
181
182 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
183 internal static extern bool GetThreadTimes(SafeThreadHandle handle, out long creation, out long exit, out long kernel, out long user);
184
185 [DllImport("kernel32.dll")]
186 [SuppressGCTransition]
187 internal static extern IntPtr GetStdHandle(int nStdHandle);
188
189 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateProcessW", SetLastError = true)]
190 internal unsafe static extern bool CreateProcess(string lpApplicationName, char* lpCommandLine, ref SECURITY_ATTRIBUTES procSecAttrs, ref SECURITY_ATTRIBUTES threadSecAttrs, bool bInheritHandles, int dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, ref PROCESS_INFORMATION lpProcessInformation);
191
192 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
193 internal static extern bool TerminateProcess(SafeProcessHandle processHandle, int exitCode);
194
195 [DllImport("kernel32.dll")]
196 internal static extern IntPtr GetCurrentProcess();
197
198 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
199 internal static extern SafeProcessHandle OpenProcess(int access, bool inherit, int processId);
200
201 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "K32EnumProcesses", SetLastError = true)]
202 internal static extern bool EnumProcesses(int[] processIds, int size, out int needed);
203
204 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "K32GetModuleInformation", SetLastError = true)]
205 private static extern bool GetModuleInformation(SafeProcessHandle processHandle, IntPtr moduleHandle, out NtModuleInfo ntModuleInfo, int size);
206
207 internal unsafe static bool GetModuleInformation(SafeProcessHandle processHandle, IntPtr moduleHandle, out NtModuleInfo ntModuleInfo)
208 {
209 return GetModuleInformation(processHandle, moduleHandle, out ntModuleInfo, sizeof(NtModuleInfo));
210 }
211
212 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "K32GetModuleBaseNameW", SetLastError = true)]
213 internal static extern int GetModuleBaseName(SafeProcessHandle processHandle, IntPtr moduleHandle, [Out] char[] baseName, int size);
214
215 [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "K32GetModuleFileNameExW", SetLastError = true)]
216 internal static extern int GetModuleFileNameEx(SafeProcessHandle processHandle, IntPtr moduleHandle, [Out] char[] baseName, int size);
217
218 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
219 internal static extern bool SetProcessWorkingSetSizeEx(SafeProcessHandle handle, IntPtr min, IntPtr max, int flags);
220
221 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
222 internal static extern bool GetProcessWorkingSetSizeEx(SafeProcessHandle handle, out IntPtr min, out IntPtr max, out int flags);
223
224 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
225 internal static extern bool SetProcessAffinityMask(SafeProcessHandle handle, IntPtr mask);
226
227 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
228 internal static extern bool GetProcessAffinityMask(SafeProcessHandle handle, out IntPtr processMask, out IntPtr systemMask);
229
230 [DllImport("kernel32.dll")]
231 public static extern int GetProcessId(SafeProcessHandle nativeHandle);
232
233 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
234 internal static extern bool GetThreadPriorityBoost(SafeThreadHandle handle, out bool disabled);
235
236 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
237 internal static extern bool SetThreadPriorityBoost(SafeThreadHandle handle, bool disabled);
238
239 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
240 internal static extern bool GetProcessPriorityBoost(SafeProcessHandle handle, out bool disabled);
241
242 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
243 internal static extern bool SetProcessPriorityBoost(SafeProcessHandle handle, bool disabled);
244
245 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
246 internal static extern SafeThreadHandle OpenThread(int access, bool inherit, int threadId);
247
248 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
249 internal static extern bool SetThreadPriority(SafeThreadHandle handle, int priority);
250
251 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
252 internal static extern int GetThreadPriority(SafeThreadHandle handle);
253
254 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
256
257 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
258 internal static extern int SetThreadIdealProcessor(SafeThreadHandle handle, int processor);
259
260 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
261 internal static extern int GetPriorityClass(SafeProcessHandle handle);
262
263 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
264 internal static extern bool SetPriorityClass(SafeProcessHandle handle, int priorityClass);
265
266 [DllImport("kernel32.dll", SetLastError = true)]
267 internal static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, SafeHandle hSourceHandle, IntPtr hTargetProcess, out SafeFileHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions);
268
269 [DllImport("kernel32.dll", SetLastError = true)]
270 internal static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, SafeHandle hSourceHandle, IntPtr hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions);
271
272 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetComputerNameW", ExactSpelling = true)]
273 private static extern int GetComputerName(ref char lpBuffer, ref uint nSize);
274
275 internal static string GetComputerName()
276 {
277 Span<char> span = stackalloc char[16];
278 uint nSize = (uint)span.Length;
279 if (GetComputerName(ref MemoryMarshal.GetReference(span), ref nSize) == 0)
280 {
281 return null;
282 }
283 return span.Slice(0, (int)nSize).ToString();
284 }
285
286 [DllImport("kernel32.dll")]
287 internal static extern uint GetConsoleCP();
288
289 [DllImport("kernel32.dll")]
290 internal static extern uint GetConsoleOutputCP();
291
292 [DllImport("kernel32.dll", SetLastError = true)]
293 internal static extern bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, ref SECURITY_ATTRIBUTES lpPipeAttributes, int nSize);
294
295 [DllImport("kernel32.dll")]
296 internal unsafe static extern int MultiByteToWideChar(uint CodePage, uint dwFlags, byte* lpMultiByteStr, int cbMultiByte, char* lpWideCharStr, int cchWideChar);
297
298 [DllImport("kernel32.dll")]
299 internal unsafe static extern int WideCharToMultiByte(uint CodePage, uint dwFlags, char* lpWideCharStr, int cchWideChar, byte* lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar);
300
301 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
302 private unsafe static extern BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW* lpCPInfoEx);
303
304 internal unsafe static int GetLeadByteRanges(int codePage, byte[] leadByteRanges)
305 {
306 int num = 0;
307 Unsafe.SkipInit(out CPINFOEXW cPINFOEXW);
308 if (GetCPInfoExW((uint)codePage, 0u, &cPINFOEXW) != 0)
309 {
310 for (int i = 0; i < 10 && leadByteRanges[i] != 0; i += 2)
311 {
312 leadByteRanges[i] = cPINFOEXW.LeadByte[i];
313 leadByteRanges[i + 1] = cPINFOEXW.LeadByte[i + 1];
314 num++;
315 }
316 }
317 return num;
318 }
319 }
320
321 internal static class NtDll
322 {
324 {
325 public uint ExitStatus;
326
328
330
331 public int BasePriority;
332
334
336 }
337
339 {
340 internal uint NextEntryOffset;
341
342 internal uint NumberOfThreads;
343
344 private unsafe fixed byte Reserved1[48];
345
347
348 internal int BasePriority;
349
351
352 private readonly UIntPtr Reserved2;
353
354 internal uint HandleCount;
355
356 internal uint SessionId;
357
358 private readonly UIntPtr Reserved3;
359
361
363
364 private readonly uint Reserved4;
365
367
369
370 private readonly UIntPtr Reserved5;
371
373
374 private readonly UIntPtr Reserved6;
375
377
379
381
383
384 private unsafe fixed long Reserved7[6];
385 }
386
388 {
389 private unsafe fixed long Reserved1[3];
390
391 private readonly uint Reserved2;
392
394
396
397 internal int Priority;
398
399 internal int BasePriority;
400
401 private readonly uint Reserved3;
402
403 internal uint ThreadState;
404
405 internal uint WaitReason;
406 }
407
408 internal struct CLIENT_ID
409 {
411
413 }
414
415 [DllImport("ntdll.dll", ExactSpelling = true)]
416 internal unsafe static extern uint NtQueryInformationProcess(SafeProcessHandle ProcessHandle, int ProcessInformationClass, void* ProcessInformation, uint ProcessInformationLength, out uint ReturnLength);
417
418 [DllImport("ntdll.dll", ExactSpelling = true)]
419 internal unsafe static extern uint NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, uint SystemInformationLength, uint* ReturnLength);
420 }
421
422 internal static class User32
423 {
424 [DllImport("user32.dll")]
425 public unsafe static extern bool EnumWindows(delegate* unmanaged<IntPtr, IntPtr, BOOL> callback, IntPtr extraData);
426
427 [DllImport("user32.dll")]
428 public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
429
430 [DllImport("user32.dll", EntryPoint = "GetWindowLongW")]
431 public static extern int GetWindowLong(IntPtr hWnd, int uCmd);
432
433 [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
434 public static extern int GetWindowTextLengthW(IntPtr hWnd);
435
436 [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
437 public unsafe static extern int GetWindowTextW(IntPtr hWnd, char* lpString, int nMaxCount);
438
439 [DllImport("user32.dll", ExactSpelling = true)]
440 public unsafe static extern int GetWindowThreadProcessId(IntPtr handle, int* processId);
441
442 [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
443 public static extern int PostMessageW(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
444
445 [DllImport("user32.dll")]
446 public static extern BOOL IsWindowVisible(IntPtr hWnd);
447
448 [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutW")]
449 public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult);
450
451 [DllImport("user32.dll")]
452 public static extern int WaitForInputIdle(SafeProcessHandle handle, int milliseconds);
453 }
454
455 internal static class Advapi32
456 {
457 internal struct PERF_COUNTER_BLOCK
458 {
459 internal int ByteLength;
460 }
461
463 {
464 internal int ByteLength;
465
467
469
471
473
474 internal int DefaultScale;
475
476 internal int DetailLevel;
477
478 internal int CounterType;
479
480 internal int CounterSize;
481
482 internal int CounterOffset;
483 }
484
485 internal struct PERF_DATA_BLOCK
486 {
487 internal int Signature1;
488
489 internal int Signature2;
490
491 internal int LittleEndian;
492
493 internal int Version;
494
495 internal int Revision;
496
497 internal int TotalByteLength;
498
499 internal int HeaderLength;
500
501 internal int NumObjectTypes;
502
503 internal int DefaultObject;
504
506
507 internal int pad1;
508
509 internal long PerfTime;
510
511 internal long PerfFreq;
512
513 internal long PerfTime100nSec;
514
515 internal int SystemNameLength;
516
517 internal int SystemNameOffset;
518 }
519
521 {
522 internal int ByteLength;
523
525
527
528 internal int UniqueID;
529
530 internal int NameOffset;
531
532 internal int NameLength;
533
535 {
536 if (instance.NameLength != 0)
537 {
538 return MemoryMarshal.Cast<byte, char>(data.Slice(instance.NameOffset, instance.NameLength - 2));
539 }
540 return default(ReadOnlySpan<char>);
541 }
542 }
543
544 internal struct PERF_OBJECT_TYPE
545 {
546 internal int TotalByteLength;
547
548 internal int DefinitionLength;
549
550 internal int HeaderLength;
551
553
554 internal int ObjectNameTitlePtr;
555
557
558 internal int ObjectHelpTitlePtr;
559
560 internal int DetailLevel;
561
562 internal int NumCounters;
563
564 internal int DefaultCounter;
565
566 internal int NumInstances;
567
568 internal int CodePage;
569
570 internal long PerfTime;
571
572 internal long PerfFreq;
573 }
574
575 internal struct SYSTEMTIME
576 {
577 internal short wYear;
578
579 internal short wMonth;
580
581 internal short wDayOfWeek;
582
583 internal short wDay;
584
585 internal short wHour;
586
587 internal short wMinute;
588
589 internal short wSecond;
590
591 internal short wMilliseconds;
592
593 public override string ToString()
594 {
595 return "[SYSTEMTIME: " + wDay.ToString(CultureInfo.CurrentCulture) + "/" + wMonth.ToString(CultureInfo.CurrentCulture) + "/" + wYear.ToString(CultureInfo.CurrentCulture) + " " + wHour.ToString(CultureInfo.CurrentCulture) + ":" + wMinute.ToString(CultureInfo.CurrentCulture) + ":" + wSecond.ToString(CultureInfo.CurrentCulture) + "]";
596 }
597 }
598
599 [Flags]
600 internal enum LogonFlags
601 {
604 }
605
606 internal struct LUID
607 {
608 internal int LowPart;
609
610 internal int HighPart;
611 }
612
613 internal struct LUID_AND_ATTRIBUTES
614 {
615 public LUID Luid;
616
617 public uint Attributes;
618 }
619
620 internal struct TOKEN_PRIVILEGE
621 {
622 public uint PrivilegeCount;
623
625 }
626
627 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
628 internal static extern bool OpenProcessToken(IntPtr ProcessHandle, int DesiredAccess, out SafeTokenHandle TokenHandle);
629
630 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "LookupPrivilegeValueW", SetLastError = true)]
631 internal static extern bool LookupPrivilegeValue([MarshalAs(UnmanagedType.LPTStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid);
632
633 [DllImport("advapi32.dll", SetLastError = true)]
634 internal unsafe static extern bool AdjustTokenPrivileges(SafeTokenHandle TokenHandle, bool DisableAllPrivileges, TOKEN_PRIVILEGE* NewState, uint BufferLength, TOKEN_PRIVILEGE* PreviousState, uint* ReturnLength);
635
636 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
637 internal unsafe static extern bool CreateProcessWithLogonW(string userName, string domain, IntPtr password, LogonFlags logonFlags, string appName, char* cmdLine, int creationFlags, IntPtr environmentBlock, string lpCurrentDirectory, ref Kernel32.STARTUPINFO lpStartupInfo, ref Kernel32.PROCESS_INFORMATION lpProcessInformation);
638 }
639
640 internal enum BOOL
641 {
642 FALSE,
643 TRUE
644 }
645
646 internal struct UNICODE_STRING
647 {
648 internal ushort Length;
649
650 internal ushort MaximumLength;
651
652 internal IntPtr Buffer;
653 }
654
655 internal static class Shell32
656 {
657 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
658 internal struct SHELLEXECUTEINFO
659 {
660 public uint cbSize;
661
662 public uint fMask;
663
664 public IntPtr hwnd;
665
666 public unsafe char* lpVerb;
667
668 public unsafe char* lpFile;
669
670 public unsafe char* lpParameters;
671
672 public unsafe char* lpDirectory;
673
674 public int nShow;
675
677
679
681
683
684 public uint dwHotKey;
685
687
689 }
690
691 [DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
692 internal unsafe static extern bool ShellExecuteExW(SHELLEXECUTEINFO* pExecInfo);
693 }
694}
static bool OpenProcessToken(IntPtr ProcessHandle, int DesiredAccess, out SafeTokenHandle TokenHandle)
static unsafe bool CreateProcessWithLogonW(string userName, string domain, IntPtr password, LogonFlags logonFlags, string appName, char *cmdLine, int creationFlags, IntPtr environmentBlock, string lpCurrentDirectory, ref Kernel32.STARTUPINFO lpStartupInfo, ref Kernel32.PROCESS_INFORMATION lpProcessInformation)
static unsafe bool AdjustTokenPrivileges(SafeTokenHandle TokenHandle, bool DisableAllPrivileges, TOKEN_PRIVILEGE *NewState, uint BufferLength, TOKEN_PRIVILEGE *PreviousState, uint *ReturnLength)
static bool LookupPrivilegeValue([MarshalAs(UnmanagedType.LPTStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid)
ProcessWaitHandle(SafeProcessHandle processHandle)
Definition Interop.cs:73
static uint GetConsoleCP()
static bool GetThreadTimes(SafeThreadHandle handle, out long creation, out long exit, out long kernel, out long user)
static uint GetConsoleOutputCP()
static bool DuplicateHandle(IntPtr hSourceProcessHandle, SafeHandle hSourceHandle, IntPtr hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
static IntPtr GetStdHandle(int nStdHandle)
static int GetModuleBaseName(SafeProcessHandle processHandle, IntPtr moduleHandle, [Out] char[] baseName, int size)
static bool IsWow64Process(IntPtr hProcess, out bool Wow64Process)
static unsafe bool GetModuleInformation(SafeProcessHandle processHandle, IntPtr moduleHandle, out NtModuleInfo ntModuleInfo)
Definition Interop.cs:207
static bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, ref SECURITY_ATTRIBUTES lpPipeAttributes, int nSize)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
Definition Interop.cs:122
static bool GetProcessTimes(SafeProcessHandle handle, out long creation, out long exit, out long kernel, out long user)
static void SetLastError(int errorCode)
static bool SetProcessPriorityBoost(SafeProcessHandle handle, bool disabled)
static bool CloseHandle(IntPtr handle)
static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, char *lpWideCharStr, int cchWideChar, byte *lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar)
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 bool IsWow64Process(SafeProcessHandle hProcess, out bool Wow64Process)
static bool SetPriorityClass(SafeProcessHandle handle, int priorityClass)
static bool GetProcessWorkingSetSizeEx(SafeProcessHandle handle, out IntPtr min, out IntPtr max, out int flags)
static bool GetProcessAffinityMask(SafeProcessHandle handle, out IntPtr processMask, out IntPtr systemMask)
static bool GetThreadPriorityBoost(SafeThreadHandle handle, out bool disabled)
static bool TerminateProcess(SafeProcessHandle processHandle, int exitCode)
static string GetMessage(int errorCode)
Definition Interop.cs:117
static bool EnumProcessModules(SafeProcessHandle handle, IntPtr[] modules, int size, out int needed)
static int GetProcessId(SafeProcessHandle nativeHandle)
static int GetModuleFileNameEx(SafeProcessHandle processHandle, IntPtr moduleHandle, [Out] char[] baseName, int size)
static bool SetThreadPriorityBoost(SafeThreadHandle handle, bool disabled)
static IntPtr SetThreadAffinityMask(SafeThreadHandle handle, IntPtr mask)
static IntPtr GetCurrentProcess()
static unsafe int GetLeadByteRanges(int codePage, byte[] leadByteRanges)
Definition Interop.cs:304
static SafeProcessHandle OpenProcess(int access, bool inherit, int processId)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static bool SetProcessAffinityMask(SafeProcessHandle handle, IntPtr mask)
static bool SetThreadPriority(SafeThreadHandle handle, int priority)
static int GetPriorityClass(SafeProcessHandle handle)
static unsafe BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW *lpCPInfoEx)
static SafeThreadHandle OpenThread(int access, bool inherit, int threadId)
static bool DuplicateHandle(IntPtr hSourceProcessHandle, SafeHandle hSourceHandle, IntPtr hTargetProcess, out SafeFileHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
static string GetComputerName()
Definition Interop.cs:275
static bool EnumProcesses(int[] processIds, int size, out int needed)
static bool GetProcessPriorityBoost(SafeProcessHandle handle, out bool disabled)
static int GetThreadPriority(SafeThreadHandle handle)
static int SetThreadIdealProcessor(SafeThreadHandle handle, int processor)
static bool SetProcessWorkingSetSizeEx(SafeProcessHandle handle, IntPtr min, IntPtr max, int flags)
static unsafe bool CreateProcess(string lpApplicationName, char *lpCommandLine, ref SECURITY_ATTRIBUTES procSecAttrs, ref SECURITY_ATTRIBUTES threadSecAttrs, bool bInheritHandles, int dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, ref PROCESS_INFORMATION lpProcessInformation)
static bool GetExitCodeProcess(SafeProcessHandle processHandle, out int exitCode)
static bool GetModuleInformation(SafeProcessHandle processHandle, IntPtr moduleHandle, out NtModuleInfo ntModuleInfo, int size)
static string GetAndTrimString(Span< char > buffer)
Definition Interop.cs:153
static unsafe uint NtQueryInformationProcess(SafeProcessHandle ProcessHandle, int ProcessInformationClass, void *ProcessInformation, uint ProcessInformationLength, out uint ReturnLength)
static unsafe(uint status, IntPtr handle) CreateFile(ReadOnlySpan< char > path
static unsafe uint NtQuerySystemInformation(int SystemInformationClass, void *SystemInformation, uint SystemInformationLength, uint *ReturnLength)
static unsafe bool ShellExecuteExW(SHELLEXECUTEINFO *pExecInfo)
static int GetWindowLong(IntPtr hWnd, int uCmd)
static IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult)
static BOOL IsWindowVisible(IntPtr hWnd)
static int PostMessageW(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam)
static unsafe int GetWindowThreadProcessId(IntPtr handle, int *processId)
static int GetWindowTextLengthW(IntPtr hWnd)
static unsafe bool EnumWindows(delegate *unmanaged< IntPtr, IntPtr, BOOL > callback, IntPtr extraData)
static IntPtr GetWindow(IntPtr hWnd, int uCmd)
static int WaitForInputIdle(SafeProcessHandle handle, int milliseconds)
static unsafe int GetWindowTextW(IntPtr hWnd, char *lpString, int nMaxCount)
static CultureInfo CurrentCulture
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static void ThrowExceptionForHR(int errorCode)
Definition Marshal.cs:1232
static ReadOnlySpan< char > GetName(in PERF_INSTANCE_DEFINITION instance, ReadOnlySpan< byte > data)
Definition Interop.cs:534
override string ToString()
Definition Interop.cs:593
LUID_AND_ATTRIBUTES Privileges
Definition Interop.cs:624
unsafe fixed char CodePageName[260]
Definition Interop.cs:22
unsafe fixed byte LeadByte[12]
Definition Interop.cs:16
unsafe fixed byte DefaultChar[2]
Definition Interop.cs:14
static readonly IntPtr Zero
Definition IntPtr.cs:18
ReadOnlySpan< T > Slice(int start)
Span< T > Slice(int start)
Definition Span.cs:271
int Length
Definition Span.cs:70