Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
6
7internal static class Interop
8{
9 internal static class WinHttp
10 {
12 {
14
16 : base(ownsHandle: true)
17 {
18 }
19
20 public static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle)
21 {
22 if (safeHandle != null)
23 {
24 safeHandle.Dispose();
25 safeHandle = null;
26 }
27 }
28
29 protected override bool ReleaseHandle()
30 {
31 if (_parentHandle != null)
32 {
34 _parentHandle = null;
35 }
37 }
38 }
39
40 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
42 {
43 public uint Flags;
44
45 public uint AutoDetectFlags;
46
47 [MarshalAs(UnmanagedType.LPWStr)]
48 public string AutoConfigUrl;
49
51
52 public uint Reserved2;
53
54 [MarshalAs(UnmanagedType.Bool)]
56 }
57
58 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
60 {
61 [MarshalAs(UnmanagedType.Bool)]
62 public bool AutoDetect;
63
65
66 public IntPtr Proxy;
67
69 }
70
71 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
72 public struct WINHTTP_PROXY_INFO
73 {
74 public uint AccessType;
75
76 public IntPtr Proxy;
77
79 }
80
81 [DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
82 public static extern SafeWinHttpHandle WinHttpOpen(IntPtr userAgent, uint accessType, string proxyName, string proxyBypass, int flags);
83
84 [DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
85 [return: MarshalAs(UnmanagedType.Bool)]
86 public static extern bool WinHttpCloseHandle(IntPtr handle);
87
88 [DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
89 [return: MarshalAs(UnmanagedType.Bool)]
91
92 [DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
93 [return: MarshalAs(UnmanagedType.Bool)]
94 public static extern bool WinHttpGetProxyForUrl(SafeWinHttpHandle sessionHandle, string url, ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out WINHTTP_PROXY_INFO proxyInfo);
95 }
96
97 internal enum SECURITY_STATUS
98 {
99 OK = 0,
100 ContinueNeeded = 590610,
101 CompleteNeeded = 590611,
102 CompAndContinue = 590612,
103 ContextExpired = 590615,
104 CredentialsNeeded = 590624,
105 Renegotiate = 590625,
106 OutOfMemory = -2146893056,
107 InvalidHandle = -2146893055,
108 Unsupported = -2146893054,
109 TargetUnknown = -2146893053,
110 InternalError = -2146893052,
111 PackageNotFound = -2146893051,
112 NotOwner = -2146893050,
113 CannotInstall = -2146893049,
114 InvalidToken = -2146893048,
115 CannotPack = -2146893047,
116 QopNotSupported = -2146893046,
117 NoImpersonation = -2146893045,
118 LogonDenied = -2146893044,
119 UnknownCredentials = -2146893043,
120 NoCredentials = -2146893042,
121 MessageAltered = -2146893041,
122 OutOfSequence = -2146893040,
123 NoAuthenticatingAuthority = -2146893039,
124 IncompleteMessage = -2146893032,
125 IncompleteCredentials = -2146893024,
126 BufferNotEnough = -2146893023,
127 WrongPrincipal = -2146893022,
128 TimeSkew = -2146893020,
129 UntrustedRoot = -2146893019,
130 IllegalMessage = -2146893018,
131 CertUnknown = -2146893017,
132 CertExpired = -2146893016,
133 DecryptFailure = -2146893008,
134 AlgorithmMismatch = -2146893007,
135 SecurityQosFailed = -2146893006,
136 SmartcardLogonRequired = -2146892994,
137 UnsupportedPreauth = -2146892989,
138 BadBinding = -2146892986,
139 DowngradeDetected = -2146892976,
140 ApplicationProtocolMismatch = -2146892953,
141 NoRenegotiation = 590688
142 }
143
144 internal static class SspiCli
145 {
146 [StructLayout(LayoutKind.Sequential, Pack = 1)]
147 internal struct CredHandle
148 {
150
152
153 public bool IsZero
154 {
155 [MethodImpl(MethodImplOptions.AggressiveInlining)]
156 get
157 {
158 if (dwLower == IntPtr.Zero)
159 {
160 return dwUpper == IntPtr.Zero;
161 }
162 return false;
163 }
164 }
165
166 internal void SetToInvalid()
167 {
170 }
171
172 public override string ToString()
173 {
174 return dwLower.ToString("x") + ":" + dwUpper.ToString("x");
175 }
176 }
177
178 [Flags]
179 internal enum ContextFlags
180 {
181 Zero = 0,
182 Delegate = 1,
183 MutualAuth = 2,
184 ReplayDetect = 4,
185 SequenceDetect = 8,
186 Confidentiality = 0x10,
187 UseSessionKey = 0x20,
188 AllocateMemory = 0x100,
189 Connection = 0x800,
190 InitExtendedError = 0x4000,
191 AcceptExtendedError = 0x8000,
192 InitStream = 0x8000,
193 AcceptStream = 0x10000,
194 InitIntegrity = 0x10000,
195 AcceptIntegrity = 0x20000,
196 InitManualCredValidation = 0x80000,
198 InitIdentify = 0x20000,
199 AcceptIdentify = 0x80000,
200 ProxyBindings = 0x4000000,
201 AllowMissingBindings = 0x10000000,
202 UnverifiedTargetName = 0x20000000
203 }
204
205 internal enum Endianness
206 {
209 }
210
211 internal enum CredentialUse
212 {
216 }
217
218 internal struct SecBuffer
219 {
220 public int cbBuffer;
221
223
225
226 public unsafe static readonly int Size = sizeof(SecBuffer);
227 }
228
229 internal struct SecBufferDesc
230 {
231 public readonly int ulVersion;
232
233 public readonly int cBuffers;
234
235 public unsafe void* pBuffers;
236
237 public unsafe SecBufferDesc(int count)
238 {
239 ulVersion = 0;
240 cBuffers = count;
241 pBuffers = null;
242 }
243 }
244
245 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
246 internal static extern int FreeContextBuffer([In] IntPtr contextBuffer);
247
248 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
249 internal static extern int FreeCredentialsHandle(ref CredHandle handlePtr);
250
251 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
252 internal static extern int DeleteSecurityContext(ref CredHandle handlePtr);
253
254 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
255 internal unsafe static extern int AcceptSecurityContext(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] SecBufferDesc* inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
256
257 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
259
260 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
261 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] IntPtr zero, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
262
263 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
264 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] System.Net.Security.SafeSspiAuthDataHandle authdata, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
265
266 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
267 internal unsafe static extern int InitializeSecurityContextW(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] byte* targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecBufferDesc* inputBuffer, [In] int reservedII, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
268
269 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
270 internal unsafe static extern int CompleteAuthToken([In] void* inContextPtr, [In][Out] ref SecBufferDesc inputBuffers);
271
272 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
273 internal static extern SECURITY_STATUS SspiFreeAuthIdentity([In] IntPtr authData);
274
275 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
276 internal static extern SECURITY_STATUS SspiEncodeStringsAsAuthIdentity([In] string userName, [In] string domainName, [In] string password, out System.Net.Security.SafeSspiAuthDataHandle authData);
277 }
278}
static SECURITY_STATUS SspiEncodeStringsAsAuthIdentity([In] string userName, [In] string domainName, [In] string password, out System.Net.Security.SafeSspiAuthDataHandle authData)
static unsafe int AcceptSecurityContext(ref CredHandle credentialHandle, [In] void *inContextPtr, [In] SecBufferDesc *inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] System.Net.Security.SafeSspiAuthDataHandle authdata, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static int FreeContextBuffer([In] IntPtr contextBuffer)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] IntPtr zero, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static SECURITY_STATUS SspiFreeAuthIdentity([In] IntPtr authData)
static unsafe int CompleteAuthToken([In] void *inContextPtr, [In][Out] ref SecBufferDesc inputBuffers)
static int EnumerateSecurityPackagesW(out int pkgnum, out System.Net.Security.SafeFreeContextBuffer_SECURITY handle)
static int DeleteSecurityContext(ref CredHandle handlePtr)
static unsafe int InitializeSecurityContextW(ref CredHandle credentialHandle, [In] void *inContextPtr, [In] byte *targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecBufferDesc *inputBuffer, [In] int reservedII, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp)
static int FreeCredentialsHandle(ref CredHandle handlePtr)
override bool ReleaseHandle()
Definition Interop.cs:29
SafeWinHttpHandle _parentHandle
Definition Interop.cs:13
static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle)
Definition Interop.cs:20
static SafeWinHttpHandle WinHttpOpen(IntPtr userAgent, uint accessType, string proxyName, string proxyBypass, int flags)
static bool WinHttpCloseHandle(IntPtr handle)
static bool WinHttpGetIEProxyConfigForCurrentUser(out WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig)
static bool WinHttpGetProxyForUrl(SafeWinHttpHandle sessionHandle, string url, ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out WINHTTP_PROXY_INFO proxyInfo)
SECURITY_STATUS
Definition Interop.cs:98
override string ToString()
Definition Interop.cs:172
unsafe SecBufferDesc(int count)
Definition Interop.cs:237
static unsafe readonly int Size
Definition Interop.cs:226
System.Net.Security.SecurityBufferType BufferType
Definition Interop.cs:222
unsafe override string ToString()
Definition IntPtr.cs:247
static readonly IntPtr Zero
Definition IntPtr.cs:18