Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
5
6internal static class Interop
7{
8 internal static class Advapi32
9 {
10 internal struct LUID
11 {
12 internal int LowPart;
13
14 internal int HighPart;
15 }
16
17 internal struct LUID_AND_ATTRIBUTES
18 {
19 public LUID Luid;
20
21 public uint Attributes;
22 }
23
24 internal struct TOKEN_PRIVILEGE
25 {
26 public uint PrivilegeCount;
27
28 public LUID_AND_ATTRIBUTES Privileges;
29 }
30
38
39 [DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "LookupPrivilegeValueW", SetLastError = true)]
40 internal static extern bool LookupPrivilegeValue([MarshalAs(UnmanagedType.LPTStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid);
41
42 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
43 internal static extern bool RevertToSelf();
44
45 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "ConvertSecurityDescriptorToStringSecurityDescriptorW", ExactSpelling = true, SetLastError = true)]
46 internal static extern bool ConvertSdToStringSd(byte[] securityDescriptor, uint requestedRevision, uint securityInformation, out IntPtr resultString, ref uint resultStringLength);
47
48 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "ConvertStringSecurityDescriptorToSecurityDescriptorW", ExactSpelling = true, SetLastError = true)]
49 internal static extern bool ConvertStringSdToSd(string stringSd, uint stringSdRevision, out IntPtr resultSd, ref uint resultSdLength);
50
51 [DllImport("advapi32.dll", EntryPoint = "GetSecurityInfo", ExactSpelling = true, SetLastError = true)]
52 internal static extern uint GetSecurityInfoByHandle(SafeHandle handle, uint objectType, uint securityInformation, out IntPtr sidOwner, out IntPtr sidGroup, out IntPtr dacl, out IntPtr sacl, out IntPtr securityDescriptor);
53
54 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "SetSecurityInfo", ExactSpelling = true, SetLastError = true)]
55 internal static extern uint SetSecurityInfoByHandle(SafeHandle handle, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl);
56
57 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetNamedSecurityInfoW", ExactSpelling = true, SetLastError = true)]
58 internal static extern uint GetSecurityInfoByName(string name, uint objectType, uint securityInformation, out IntPtr sidOwner, out IntPtr sidGroup, out IntPtr dacl, out IntPtr sacl, out IntPtr securityDescriptor);
59
60 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "SetNamedSecurityInfoW", ExactSpelling = true, SetLastError = true)]
61 internal static extern uint SetSecurityInfoByName(string name, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl);
62
63 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
64 internal static extern uint GetSecurityDescriptorLength(IntPtr byteArray);
65
66 [DllImport("advapi32.dll", SetLastError = true)]
67 internal static extern bool OpenThreadToken(IntPtr ThreadHandle, TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out SafeTokenHandle phThreadToken);
68
69 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
70 internal static extern bool OpenProcessToken(IntPtr ProcessToken, TokenAccessLevels DesiredAccess, out SafeTokenHandle TokenHandle);
71
72 [DllImport("advapi32.dll", SetLastError = true)]
73 internal static extern bool SetThreadToken(IntPtr ThreadHandle, SafeTokenHandle hToken);
74
75 [DllImport("advapi32.dll", SetLastError = true)]
76 internal unsafe static extern bool AdjustTokenPrivileges(SafeTokenHandle TokenHandle, bool DisableAllPrivileges, TOKEN_PRIVILEGE* NewState, uint BufferLength, TOKEN_PRIVILEGE* PreviousState, uint* ReturnLength);
77
78 [DllImport("advapi32.dll", SetLastError = true)]
79 internal static extern bool DuplicateTokenEx(SafeTokenHandle ExistingTokenHandle, TokenAccessLevels DesiredAccess, IntPtr TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, System.Security.Principal.TokenType TokenType, ref SafeTokenHandle DuplicateTokenHandle);
80 }
81
82 internal static class Kernel32
83 {
84 [DllImport("kernel32.dll", SetLastError = true)]
85 internal static extern bool CloseHandle(IntPtr handle);
86
87 [DllImport("kernel32.dll")]
88 internal static extern IntPtr GetCurrentProcess();
89 }
90}
static uint SetSecurityInfoByHandle(SafeHandle handle, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl)
static uint GetSecurityDescriptorLength(IntPtr byteArray)
static uint SetSecurityInfoByName(string name, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl)
static bool SetThreadToken(IntPtr ThreadHandle, SafeTokenHandle hToken)
static bool DuplicateTokenEx(SafeTokenHandle ExistingTokenHandle, TokenAccessLevels DesiredAccess, IntPtr TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, System.Security.Principal.TokenType TokenType, ref SafeTokenHandle DuplicateTokenHandle)
static bool OpenThreadToken(IntPtr ThreadHandle, TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out SafeTokenHandle phThreadToken)
static bool ConvertSdToStringSd(byte[] securityDescriptor, uint requestedRevision, uint securityInformation, out IntPtr resultString, ref uint resultStringLength)
static unsafe bool AdjustTokenPrivileges(SafeTokenHandle TokenHandle, bool DisableAllPrivileges, TOKEN_PRIVILEGE *NewState, uint BufferLength, TOKEN_PRIVILEGE *PreviousState, uint *ReturnLength)
static uint GetSecurityInfoByHandle(SafeHandle handle, uint objectType, uint securityInformation, out IntPtr sidOwner, out IntPtr sidGroup, out IntPtr dacl, out IntPtr sacl, out IntPtr securityDescriptor)
static bool OpenProcessToken(IntPtr ProcessToken, TokenAccessLevels DesiredAccess, out SafeTokenHandle TokenHandle)
static bool RevertToSelf()
static bool ConvertStringSdToSd(string stringSd, uint stringSdRevision, out IntPtr resultSd, ref uint resultSdLength)
SECURITY_IMPERSONATION_LEVEL
Definition Interop.cs:32
static uint GetSecurityInfoByName(string name, uint objectType, uint securityInformation, out IntPtr sidOwner, out IntPtr sidGroup, out IntPtr dacl, out IntPtr sacl, out IntPtr securityDescriptor)
static bool LookupPrivilegeValue([MarshalAs(UnmanagedType.LPTStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid)
static void SetLastError(int errorCode)
static bool CloseHandle(IntPtr handle)
static IntPtr GetCurrentProcess()
ImpersonationLevel
Definition Interop.cs:1710
TokenType
Definition TokenType.cs:4
LUID_AND_ATTRIBUTES Privileges
Definition Interop.cs:624