Interop.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // **********************************************************************************
  2. // CassiniDev - http://cassinidev.codeplex.com
  3. //
  4. // Copyright (c) 2010 Sky Sanders. All rights reserved.
  5. //
  6. // This source code is subject to terms and conditions of the Microsoft Public
  7. // License (Ms-PL). A copy of the license can be found in the license.txt file
  8. // included in this distribution.
  9. //
  10. // You must not remove this notice, or any other, from this software.
  11. //
  12. // **********************************************************************************
  13. #region
  14. using System;
  15. using System.Runtime.InteropServices;
  16. #endregion
  17. namespace CassiniDev
  18. {
  19. internal static class Interop
  20. {
  21. #region Structs
  22. [DllImport("SECUR32.DLL", CharSet = CharSet.Unicode)]
  23. public static extern int AcceptSecurityContext(ref SecHandle phCredential, IntPtr phContext,
  24. ref SecBufferDesc pInput, uint fContextReq, uint TargetDataRep,
  25. ref SecHandle phNewContext, ref SecBufferDesc pOutput,
  26. ref uint pfContextAttr, ref long ptsTimeStamp);
  27. [DllImport("SECUR32.DLL", CharSet = CharSet.Unicode)]
  28. public static extern int AcquireCredentialsHandle(string pszPrincipal, string pszPackage, uint fCredentialUse,
  29. IntPtr pvLogonID, IntPtr pAuthData, IntPtr pGetKeyFn,
  30. IntPtr pvGetKeyArgument, ref SecHandle phCredential,
  31. ref long ptsExpiry);
  32. [DllImport("KERNEL32.DLL", CharSet = CharSet.Unicode)]
  33. public static extern int CloseHandle(IntPtr phToken);
  34. [DllImport("SECUR32.DLL", CharSet = CharSet.Unicode)]
  35. public static extern int DeleteSecurityContext(ref SecHandle phContext);
  36. /// <summary>
  37. /// FIX: #12506
  38. /// </summary>
  39. [DllImport("urlmon.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
  40. public static extern int FindMimeFromData(IntPtr pBC, [MarshalAs(UnmanagedType.LPWStr)] string pwzUrl,
  41. [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1,
  42. SizeParamIndex = 3)] byte[] pBuffer, int cbSize,
  43. [MarshalAs(UnmanagedType.LPWStr)] string pwzMimeProposed,
  44. int dwMimeFlags, out IntPtr ppwzMimeOut, int dwReserved);
  45. [DllImport("SECUR32.DLL", CharSet = CharSet.Unicode)]
  46. public static extern int FreeCredentialsHandle(ref SecHandle phCredential);
  47. [DllImport("kernel32.dll", EntryPoint = "GetConsoleScreenBufferInfo", SetLastError = true,
  48. CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  49. public static extern int GetConsoleScreenBufferInfo(int hConsoleOutput,
  50. ref CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
  51. [DllImport("KERNEL32.DLL", SetLastError = true)]
  52. public static extern IntPtr GetCurrentThread();
  53. [DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Auto,
  54. CallingConvention = CallingConvention.StdCall)]
  55. public static extern int GetStdHandle(int nStdHandle);
  56. [DllImport("ADVAPI32.DLL", SetLastError = true)]
  57. public static extern bool ImpersonateSelf(int level);
  58. [DllImport("ADVAPI32.DLL", SetLastError = true)]
  59. public static extern int OpenThreadToken(IntPtr thread, int access, bool openAsSelf, ref IntPtr hToken);
  60. [DllImport("SECUR32.DLL", CharSet = CharSet.Unicode)]
  61. public static extern int QuerySecurityContextToken(ref SecHandle phContext, ref IntPtr phToken);
  62. [DllImport("ADVAPI32.DLL", SetLastError = true)]
  63. public static extern int RevertToSelf();
  64. #region Nested type: CONSOLE_SCREEN_BUFFER_INFO
  65. public struct CONSOLE_SCREEN_BUFFER_INFO
  66. {
  67. internal COORD dwCursorPosition;
  68. internal COORD dwMaximumWindowSize;
  69. internal COORD dwSize;
  70. internal SMALL_RECT srWindow;
  71. internal Int16 wAttributes;
  72. }
  73. #endregion
  74. #region Nested type: COORD
  75. public struct COORD
  76. {
  77. internal Int16 x;
  78. internal Int16 y;
  79. }
  80. #endregion
  81. #region Nested type: SecBuffer
  82. [StructLayout(LayoutKind.Sequential)]
  83. public struct SecBuffer
  84. {
  85. // ReSharper disable InconsistentNaming
  86. public uint cbBuffer;
  87. public uint BufferType;
  88. public IntPtr pvBuffer;
  89. // ReSharper restore InconsistentNaming
  90. }
  91. #endregion
  92. #region Nested type: SecBufferDesc
  93. [StructLayout(LayoutKind.Sequential)]
  94. public struct SecBufferDesc
  95. {
  96. // ReSharper disable InconsistentNaming
  97. public uint ulVersion;
  98. public uint cBuffers;
  99. public IntPtr pBuffers;
  100. // ReSharper restore InconsistentNaming
  101. }
  102. #endregion
  103. #region Nested type: SecHandle
  104. [StructLayout(LayoutKind.Sequential)]
  105. public struct SecHandle
  106. {
  107. // ReSharper disable InconsistentNaming
  108. public IntPtr dwLower;
  109. public IntPtr dwUpper;
  110. // ReSharper restore InconsistentNaming
  111. }
  112. #endregion
  113. #region Nested type: SMALL_RECT
  114. public struct SMALL_RECT
  115. {
  116. internal Int16 Bottom;
  117. internal Int16 Left;
  118. internal Int16 Right;
  119. internal Int16 Top;
  120. }
  121. #endregion
  122. #endregion
  123. }
  124. }