Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TlsContents()

System.Security.AccessControl.Privilege.TlsContents.TlsContents ( )
inline

Definition at line 32 of file Privilege.cs.

33 {
34 int num = 0;
35 int num2 = 0;
36 bool flag = true;
37 if (processHandle.IsInvalid)
38 {
40 {
41 if (processHandle.IsInvalid)
42 {
43 if (!global::Interop.Advapi32.OpenProcessToken(global::Interop.Kernel32.GetCurrentProcess(), TokenAccessLevels.Duplicate, out var TokenHandle))
44 {
46 flag = false;
47 }
49 }
50 }
51 }
52 try
53 {
55 num = System.Security.Principal.Win32.OpenThreadToken(TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges, System.Security.Principal.WinSecurityContext.Process, out threadHandle);
56 num &= 0x7FF8FFFF;
57 if (num != 0)
58 {
59 if (flag)
60 {
62 if (num != 1008)
63 {
64 flag = false;
65 }
66 if (flag)
67 {
68 num = 0;
69 if (!global::Interop.Advapi32.DuplicateTokenEx(processHandle, TokenAccessLevels.Impersonate | TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges, IntPtr.Zero, global::Interop.Advapi32.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, System.Security.Principal.TokenType.TokenImpersonation, ref threadHandle))
70 {
72 flag = false;
73 }
74 }
75 if (flag)
76 {
78 num &= 0x7FF8FFFF;
79 if (num != 0)
80 {
81 flag = false;
82 }
83 }
84 if (flag)
85 {
86 isImpersonating = true;
87 }
88 }
89 else
90 {
91 num = num2;
92 }
93 }
94 else
95 {
96 flag = true;
97 }
98 }
99 finally
100 {
101 if (!flag)
102 {
103 Dispose();
104 }
105 }
106 switch (num)
107 {
108 case 8:
109 throw new OutOfMemoryException();
110 case 5:
111 case 1347:
112 throw new UnauthorizedAccessException();
113 default:
114 throw new InvalidOperationException();
115 case 0:
116 break;
117 }
118 }
static volatile SafeTokenHandle processHandle
Definition Privilege.cs:22
static int SetThreadToken(SafeTokenHandle hToken)
Definition Win32.cs:39
static int OpenThreadToken(TokenAccessLevels dwDesiredAccess, System.Security.Principal.WinSecurityContext dwOpenAs, out SafeTokenHandle phThreadToken)
Definition Win32.cs:8

References System.Security.AccessControl.Privilege.TlsContents.Dispose(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.Security.AccessControl.Privilege.TlsContents.isImpersonating, System.Security.Principal.Win32.OpenThreadToken(), System.Security.AccessControl.Privilege.TlsContents.processHandle, System.Security.Principal.Win32.SetThreadToken(), System.Security.AccessControl.Privilege.TlsContents.syncRoot, System.Security.AccessControl.Privilege.TlsContents.threadHandle, and System.IntPtr.Zero.