tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
NativeMethods.cs
Go to the documentation of this file.
1using System;
2using System.Runtime.InteropServices;
3using System.Text;
4
6{
10#pragma warning disable SA1602
11#pragma warning disable SA1611
12#pragma warning disable SA1615
13 static class NativeMethods
14 {
18 [Flags]
19 public enum CreateSymbolicLinkFlags : int
20 {
21 None = 0x0,
22 Directory = 0x1,
24 }
25
29 public enum ThreadAccess : int
30 {
31 SuspendResume = 0x0002,
32 }
33
37 [Flags]
38 public enum MiniDumpType : uint
39 {
40 WithDataSegs = 0x00000001,
41 WithFullMemory = 0x00000002,
42 WithHandleData = 0x00000004,
43 WithUnloadedModules = 0x00000020,
44 WithThreadInfo = 0x00001000,
45 }
46
50 [DllImport("user32.dll")]
51 public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
52
56 [DllImport("user32.dll", CharSet = CharSet.Unicode)]
57 public static extern IntPtr FindWindow(string? lpClassName, string lpWindowName);
58
62 [DllImport("user32.dll")]
63 public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
64
68 public delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);
69
73 [DllImport("user32.dll")]
74 public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
75
79 [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
80 public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
81
85 [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
86 public static extern bool LogonUser(string lpszUsername, string? lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
87
91 [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
92 public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, CreateSymbolicLinkFlags dwFlags);
93
97 [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
98 public static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
99
103 [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
104 public static extern bool CloseHandle(IntPtr hObject);
105
109 [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
110 public static extern uint SuspendThread(IntPtr hThread);
111
115 [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
116 public static extern uint ResumeThread(IntPtr hThread);
117
121 [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
122 public static extern bool MiniDumpWriteDump(
123 IntPtr hProcess,
124 uint processId,
125 SafeHandle hFile,
126 MiniDumpType dumpType,
127 IntPtr expParam,
128 IntPtr userStreamParam,
129 IntPtr callbackParam);
130
134#pragma warning disable IDE0079
135#pragma warning disable CA2101 // https://github.com/dotnet/roslyn-analyzers/issues/5479#issuecomment-1603665900
136 [DllImport("libsystemd.so.0", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
137 public static extern int sd_notify(int unset_environment, [MarshalAs(UnmanagedType.LPUTF8Str)] string state);
138#pragma warning restore CA2101
139#pragma warning restore IDE0079
140 }
141}
Native methods used by the code.
MiniDumpType
See https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ne-minidumpapiset-minidump_type...
static int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowthreadprocessid.
static IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms684335(v=vs.85).aspx.
static uint ResumeThread(IntPtr hThread)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms685086(v=vs.85).aspx.
static uint SuspendThread(IntPtr hThread)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686345(v=vs.85).aspx.
static bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumchildwindows.
static int sd_notify(int unset_environment, [MarshalAs(UnmanagedType.LPUTF8Str)] string state)
See https://www.freedesktop.org/software/systemd/man/sd_notify.html.
static IntPtr FindWindow(string? lpClassName, string lpWindowName)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-findwindoww.
static bool MiniDumpWriteDump(IntPtr hProcess, uint processId, SafeHandle hFile, MiniDumpType dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam)
See https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/nf-minidumpapiset-minidumpwrite...
static bool LogonUser(string lpszUsername, string? lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken)
See https://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx.
delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam)
See https://msdn.microsoft.com/en-us/library/ms633493(v=VS.85).aspx.
CreateSymbolicLinkFlags
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinka#param...
static bool CloseHandle(IntPtr hObject)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx.
static int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendmessage.
ThreadAccess
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx.
static bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, CreateSymbolicLinkFlags dwFlags)
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinkw.
static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowtextw.