internal static partial class Advapi32
{
[DllImport(Libraries.Advapi32)]
- internal static extern bool AllocateLocallyUniqueId(out LUID Luid);
+ internal static unsafe extern int AllocateLocallyUniqueId(LUID* Luid);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial bool CheckTokenMembership(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
- internal static extern bool CheckTokenMembership(SafeAccessTokenHandle TokenHandle, byte[] SidToCheck, ref bool IsMember);
+ internal static extern bool CheckTokenMembership(
+#endif
+ SafeAccessTokenHandle TokenHandle,
+ byte[] SidToCheck,
+ ref bool IsMember);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial int ConvertStringSidToSid(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int ConvertStringSidToSid(string stringSid, out IntPtr ByteArray);
+ internal static extern int ConvertStringSidToSid(
+#endif
+ string stringSid,
+ out IntPtr ByteArray);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial int CreateWellKnownSid(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int CreateWellKnownSid(int sidType, byte[]? domainSid, byte[] resultSid, ref uint resultSidLength);
+ internal static extern int CreateWellKnownSid(
+#endif
+ int sidType,
+ byte[]? domainSid,
+ byte[] resultSid,
+ ref uint resultSidLength);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial bool DuplicateTokenEx(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool DuplicateTokenEx(
+#endif
SafeAccessTokenHandle hExistingToken,
uint dwDesiredAccess,
IntPtr lpTokenAttributes, // LPSECURITY_ATTRIBUTES
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial bool GetTokenInformation(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool GetTokenInformation(
+#endif
SafeAccessTokenHandle TokenHandle,
uint TokenInformationClass,
SafeLocalAllocHandle TokenInformation,
uint TokenInformationLength,
out uint ReturnLength);
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial bool GetTokenInformation(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool GetTokenInformation(
+#endif
IntPtr TokenHandle,
uint TokenInformationClass,
SafeLocalAllocHandle TokenInformation,
uint TokenInformationLength,
out uint ReturnLength);
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial bool GetTokenInformation(
+#else
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool GetTokenInformation(
+#endif
IntPtr TokenHandle,
uint TokenInformationClass,
IntPtr TokenInformation,
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "GetWindowsAccountDomainSid", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial int GetWindowsAccountDomainSid(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "GetWindowsAccountDomainSid", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int GetWindowsAccountDomainSid(byte[] sid, byte[] resultSid, ref uint resultSidLength);
+ internal static extern int GetWindowsAccountDomainSid(
+#endif
+ byte[] sid,
+ byte[] resultSid,
+ ref uint resultSidLength);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial bool ImpersonateLoggedOnUser(SafeAccessTokenHandle userToken);
+#else
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool ImpersonateLoggedOnUser(SafeAccessTokenHandle userToken);
+#endif
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "EqualDomainSid", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial int IsEqualDomainSid(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "EqualDomainSid", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int IsEqualDomainSid(byte[] sid1, byte[] sid2, out bool result);
+ internal static extern int IsEqualDomainSid(
+#endif
+ byte[] sid1,
+ byte[] sid2,
+ out bool result);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "IsWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial int IsWellKnownSid(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "IsWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int IsWellKnownSid(byte[] sid, int type);
+ internal static extern int IsWellKnownSid(
+#endif
+ byte[] sid,
+ int type);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial int LsaClose(IntPtr handle);
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern int LsaClose(IntPtr handle);
+#endif
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial int LsaFreeMemory(IntPtr handle);
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern int LsaFreeMemory(IntPtr handle);
+#endif
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupSids", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static partial uint LsaLookupSids(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupSids", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern uint LsaLookupSids(
+#endif
SafeLsaPolicyHandle handle,
int count,
IntPtr[] sids,
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", SetLastError = true, CharSet = CharSet.Unicode)]
+ private static partial uint LsaOpenPolicy(
+#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern uint LsaOpenPolicy(
+#endif
ref UNICODE_STRING SystemName,
ref OBJECT_ATTRIBUTES ObjectAttributes,
int AccessMask,
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ internal static partial bool OpenProcessToken(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
- internal static extern bool OpenProcessToken(IntPtr ProcessToken, TokenAccessLevels DesiredAccess, out SafeAccessTokenHandle TokenHandle);
+ internal static extern bool OpenProcessToken(
+#endif
+ IntPtr ProcessToken,
+ TokenAccessLevels DesiredAccess,
+ out SafeAccessTokenHandle TokenHandle);
}
}
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
+ private static partial bool OpenThreadToken(
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
- private static extern bool OpenThreadToken(IntPtr ThreadHandle, TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out SafeAccessTokenHandle phThreadToken);
+ private static extern bool OpenThreadToken(
+#endif
+ IntPtr ThreadHandle,
+ TokenAccessLevels dwDesiredAccess,
+ bool bOpenAsSelf,
+ out SafeAccessTokenHandle phThreadToken);
internal static bool OpenThreadToken(TokenAccessLevels desiredAccess, WinSecurityContext openAs, out SafeAccessTokenHandle tokenHandle)
{
{
internal static partial class Advapi32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ internal static partial bool RevertToSelf();
+#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
internal static extern bool RevertToSelf();
+#endif
}
}
{
internal static partial class Kernel32
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static partial bool DuplicateHandle(
+#else
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool DuplicateHandle(
+#endif
IntPtr hSourceProcessHandle,
IntPtr hSourceHandle,
IntPtr hTargetProcessHandle,
{
internal static partial class SspiCli
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.SspiCli)]
+ internal static partial int LsaConnectUntrusted(out SafeLsaHandle LsaHandle);
+#else
[DllImport(Interop.Libraries.SspiCli)]
internal static extern int LsaConnectUntrusted(out SafeLsaHandle LsaHandle);
+#endif
}
}
{
internal static partial class SspiCli
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.SspiCli, SetLastError = true)]
+ internal static partial int LsaFreeReturnBuffer(IntPtr handle);
+#else
[DllImport(Interop.Libraries.SspiCli, SetLastError = true)]
internal static extern int LsaFreeReturnBuffer(IntPtr handle);
+#endif
}
}
{
internal static partial class SspiCli
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Interop.Libraries.SspiCli, SetLastError = true)]
+ internal static partial int LsaGetLogonSessionData(
+#else
[DllImport(Interop.Libraries.SspiCli, SetLastError = true)]
- internal static extern int LsaGetLogonSessionData(ref LUID LogonId, out SafeLsaReturnBufferHandle ppLogonSessionData);
+ internal static extern int LsaGetLogonSessionData(
+#endif
+ ref LUID LogonId,
+ out SafeLsaReturnBufferHandle ppLogonSessionData);
}
}
{
internal static partial class SspiCli
{
+#if DLLIMPORTGENERATOR_ENABLED
+ [GeneratedDllImport(Libraries.SspiCli)]
+ internal static partial int LsaLookupAuthenticationPackage(
+#else
[DllImport(Libraries.SspiCli)]
internal static extern int LsaLookupAuthenticationPackage(
+#endif
SafeLsaHandle LsaHandle,
- [In] ref Advapi32.LSA_STRING PackageName,
+ ref Advapi32.LSA_STRING PackageName,
out int AuthenticationPackage
);
}
<Reference Include="System.Collections" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.Tools" />
+ <Reference Include="System.Memory" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
byte[] sourceName = { (byte)'C', (byte)'L', (byte)'R', (byte)0 };
TOKEN_SOURCE sourceContext;
- if (!Interop.Advapi32.AllocateLocallyUniqueId(out sourceContext.SourceIdentifier))
- throw new SecurityException(new Win32Exception().Message);
+ unsafe
+ {
+ if (Interop.Advapi32.AllocateLocallyUniqueId(&sourceContext.SourceIdentifier) == 0)
+ throw new SecurityException(new Win32Exception().Message);
+ }
+
sourceContext.SourceName = new byte[TOKEN_SOURCE.TOKEN_SOURCE_LENGTH];
Buffer.BlockCopy(sourceName, 0, sourceContext.SourceName, 0, sourceName.Length);