当前位置: 首页>>代码示例>>C#>>正文


C# SafeHandle.DangerousGetHandle方法代码示例

本文整理汇总了C#中System.Runtime.InteropServices.SafeHandle.DangerousGetHandle方法的典型用法代码示例。如果您正苦于以下问题:C# SafeHandle.DangerousGetHandle方法的具体用法?C# SafeHandle.DangerousGetHandle怎么用?C# SafeHandle.DangerousGetHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.InteropServices.SafeHandle的用法示例。


在下文中一共展示了SafeHandle.DangerousGetHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SecurityPackageInfoClass

        /*
            This is to support SSL with no client cert.
            Important: safeHandle should not be Disposed during construction of this object.
           
            _SecPkgInfoW in sspi.h
         */
        internal SecurityPackageInfoClass(SafeHandle safeHandle, int index)
        {
            if (safeHandle.IsInvalid)
            {
                GlobalLog.Print("SecurityPackageInfoClass::.ctor() the pointer is invalid: " + (safeHandle.DangerousGetHandle()).ToString("x"));
                return;
            }

            IntPtr unmanagedAddress = IntPtrHelper.Add(safeHandle.DangerousGetHandle(), SecurityPackageInfo.Size * index);
            GlobalLog.Print("SecurityPackageInfoClass::.ctor() unmanagedPointer: " + ((long)unmanagedAddress).ToString("x"));

            // TODO (Issue #3114): replace with Marshal.PtrToStructure.
            Capabilities = Marshal.ReadInt32(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Capabilities"));
            Version = Marshal.ReadInt16(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Version"));
            RPCID = Marshal.ReadInt16(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("RPCID"));
            MaxToken = Marshal.ReadInt32(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("MaxToken"));

            IntPtr unmanagedString;

            unmanagedString = Marshal.ReadIntPtr(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Name"));
            if (unmanagedString != IntPtr.Zero)
            {
                Name = Marshal.PtrToStringUni(unmanagedString);
                GlobalLog.Print("Name: " + Name);
            }

            unmanagedString = Marshal.ReadIntPtr(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Comment"));
            if (unmanagedString != IntPtr.Zero)
            {
                Comment = Marshal.PtrToStringUni(unmanagedString);
                GlobalLog.Print("Comment: " + Comment);
            }

            GlobalLog.Print("SecurityPackageInfoClass::.ctor(): " + ToString());
        }
开发者ID:jemmy655,项目名称:corefx,代码行数:41,代码来源:SecurityPackageInfoClass.cs

示例2: NegotiationInfoClass

        internal NegotiationInfoClass(SafeHandle safeHandle, int negotiationState)
        {
            if (safeHandle.IsInvalid)
            {
                if (GlobalLog.IsEnabled)
                {
                    GlobalLog.Print("NegotiationInfoClass::.ctor() the handle is invalid:" + (safeHandle.DangerousGetHandle()).ToString("x"));
                }
                return;
            }

            IntPtr packageInfo = safeHandle.DangerousGetHandle();
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("NegotiationInfoClass::.ctor() packageInfo:" + packageInfo.ToString("x8") + " negotiationState:" + negotiationState.ToString("x8"));
            }

            if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE
                || negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC)
            {
                IntPtr unmanagedString = Marshal.ReadIntPtr(packageInfo, SecurityPackageInfo.NameOffest);
                string name = null;
                if (unmanagedString != IntPtr.Zero)
                {
                    name = Marshal.PtrToStringUni(unmanagedString);
                }

                if (GlobalLog.IsEnabled)
                {
                    GlobalLog.Print("NegotiationInfoClass::.ctor() packageInfo:" + packageInfo.ToString("x8") + " negotiationState:" + negotiationState.ToString("x8") + " name:" + LoggingHash.ObjectToString(name));
                }

                // An optimization for future string comparisons.
                if (string.Compare(name, Kerberos, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AuthenticationPackage = Kerberos;
                }
                else if (string.Compare(name, NTLM, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AuthenticationPackage = NTLM;
                }
                else if (string.Compare(name, WDigest, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AuthenticationPackage = WDigest;
                }
                else
                {
                    AuthenticationPackage = name;
                }
            }
        }
开发者ID:GeneralRookie,项目名称:corefx,代码行数:51,代码来源:NegotiationInfoClass.cs

示例3: NegotiationInfoClass

 internal NegotiationInfoClass(SafeHandle safeHandle, int negotiationState)
 {
     if (!safeHandle.IsInvalid)
     {
         IntPtr handle = safeHandle.DangerousGetHandle();
         if ((negotiationState == 0) || (negotiationState == 1))
         {
             IntPtr ptr = Marshal.ReadIntPtr(handle, SecurityPackageInfo.NameOffest);
             string strA = null;
             if (ptr != IntPtr.Zero)
             {
                 strA = ComNetOS.IsWin9x ? Marshal.PtrToStringAnsi(ptr) : Marshal.PtrToStringUni(ptr);
             }
             if (string.Compare(strA, "Kerberos", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 this.AuthenticationPackage = "Kerberos";
             }
             else if (string.Compare(strA, "NTLM", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 this.AuthenticationPackage = "NTLM";
             }
             else if (string.Compare(strA, "WDigest", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 this.AuthenticationPackage = "WDigest";
             }
             else
             {
                 this.AuthenticationPackage = strA;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:NegotiationInfoClass.cs

示例4: SecurityPackageInfoClass

        /*
            This is to support SSL with no client cert.
            Important: safeHandle should not be Disposed during construction of this object.
           
            _SecPkgInfoW in sspi.h
         */
        internal SecurityPackageInfoClass(SafeHandle safeHandle, int index)
        {
            if (safeHandle.IsInvalid)
            {
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Invalid handle: {safeHandle}");
                return;
            }

            IntPtr unmanagedAddress = IntPtrHelper.Add(safeHandle.DangerousGetHandle(), SecurityPackageInfo.Size * index);
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"unmanagedAddress: {unmanagedAddress}");

            // TODO (Issue #3114): replace with Marshal.PtrToStructure.
            Capabilities = Marshal.ReadInt32(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Capabilities"));
            Version = Marshal.ReadInt16(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Version"));
            RPCID = Marshal.ReadInt16(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("RPCID"));
            MaxToken = Marshal.ReadInt32(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("MaxToken"));

            IntPtr unmanagedString;

            unmanagedString = Marshal.ReadIntPtr(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Name"));
            if (unmanagedString != IntPtr.Zero)
            {
                Name = Marshal.PtrToStringUni(unmanagedString);
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Name: {Name}");
            }

            unmanagedString = Marshal.ReadIntPtr(unmanagedAddress, (int)Marshal.OffsetOf<SecurityPackageInfo>("Comment"));
            if (unmanagedString != IntPtr.Zero)
            {
                Comment = Marshal.PtrToStringUni(unmanagedString);
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Comment: {Comment}");
            }

            if (NetEventSource.IsEnabled) NetEventSource.Info(this, this.ToString());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:41,代码来源:SecurityPackageInfoClass.cs

示例5: SecurityPackageInfoClass

 internal SecurityPackageInfoClass(SafeHandle safeHandle, int index)
 {
     if (!safeHandle.IsInvalid)
     {
         IntPtr ptr = IntPtrHelper.Add(safeHandle.DangerousGetHandle(), SecurityPackageInfo.Size * index);
         this.Capabilities = Marshal.ReadInt32(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "Capabilities"));
         this.Version = Marshal.ReadInt16(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "Version"));
         this.RPCID = Marshal.ReadInt16(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "RPCID"));
         this.MaxToken = Marshal.ReadInt32(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "MaxToken"));
         IntPtr ptr2 = Marshal.ReadIntPtr(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "Name"));
         if (ptr2 != IntPtr.Zero)
         {
             if (ComNetOS.IsWin9x)
             {
                 this.Name = Marshal.PtrToStringAnsi(ptr2);
             }
             else
             {
                 this.Name = Marshal.PtrToStringUni(ptr2);
             }
         }
         ptr2 = Marshal.ReadIntPtr(ptr, (int) Marshal.OffsetOf(typeof(SecurityPackageInfo), "Comment"));
         if (ptr2 != IntPtr.Zero)
         {
             if (ComNetOS.IsWin9x)
             {
                 this.Comment = Marshal.PtrToStringAnsi(ptr2);
             }
             else
             {
                 this.Comment = Marshal.PtrToStringUni(ptr2);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:SecurityPackageInfoClass.cs

示例6: EntryPage

		protected EntryPage(SafeHandle handle, uint capacity)
		{
			Contract.Requires(handle != null && !handle.IsInvalid && !handle.IsClosed);

			m_handle = handle;
			m_capacity = capacity;
			m_start = (byte*) handle.DangerousGetHandle();
			m_end = m_start + capacity;
			m_current = m_start;
			CheckInvariants();
		}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:11,代码来源:EntryPage.cs

示例7: FromSafeHandle

      public static ArbitraryWaitHandle FromSafeHandle(SafeHandle safeHandle) {
         Contract.Requires(safeHandle != null);
         Boolean success = false;
         try {
            safeHandle.DangerousAddRef(ref success);
            if (!success) throw new InvalidOperationException("Couldn't AddRef");

            return new ArbitraryWaitHandle(safeHandle.DangerousGetHandle());
         }
         finally {
            safeHandle.DangerousRelease();
         }
      }
开发者ID:blinds52,项目名称:PowerThreading,代码行数:13,代码来源:ArbitraryWaitHandle.cs

示例8: SafePipeHandle

        internal SafePipeHandle(Socket namedPipeSocket) : base(ownsHandle: true)
        {
            Debug.Assert(namedPipeSocket != null);
            _namedPipeSocket = namedPipeSocket;

            // TODO: Issue https://github.com/dotnet/corefx/issues/6807
            // This is unfortunately the only way of getting at the Socket's file descriptor right now, until #6807 is implemented.
            PropertyInfo safeHandleProperty = s_safeHandleProperty ?? (s_safeHandleProperty = typeof(Socket).GetTypeInfo().GetDeclaredProperty("SafeHandle"));
            Debug.Assert(safeHandleProperty != null, "Socket.SafeHandle could not be found.");
            _namedPipeSocketHandle = (SafeHandle)safeHandleProperty?.GetValue(namedPipeSocket, null);

            bool ignored = false;
            _namedPipeSocketHandle.DangerousAddRef(ref ignored);
            SetHandle(_namedPipeSocketHandle.DangerousGetHandle());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:SafePipeHandle.Unix.cs

示例9: DuplicateTokenAsPrimaryToken

        public static SafeHandle DuplicateTokenAsPrimaryToken(SafeHandle originalToken)
        {
            IntPtr duplicatedToken = Constants.INVALID_HANDLE_VALUE;

            if (!AdvApi32PInvoke.DuplicateTokenEx(originalToken.DangerousGetHandle(),
                AdvApi32PInvoke.TOKEN_QUERY
                | AdvApi32PInvoke.TOKEN_DUPLICATE
                | AdvApi32PInvoke.TOKEN_ASSIGN_PRIMARY
                | AdvApi32PInvoke.TOKEN_ADJUST_DEFAULT
                | AdvApi32PInvoke.TOKEN_ADJUST_SESSIONID,
                Constants.NULL,
                AdvApi32PInvoke.SECURITY_IMPERSONATION_LEVEL.SecurityDelegation,
                AdvApi32PInvoke.TOKEN_TYPE.TokenPrimary,
                out duplicatedToken))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return new SafeFileHandle(duplicatedToken, true);
        }
开发者ID:fschwiet,项目名称:PShochu,代码行数:20,代码来源:AccessToken.cs

示例10: DuplicateHandle

		public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
			out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
		{
			bool release = false;
			try {
				hSourceHandle.DangerousAddRef (ref release);

				MonoIOError error;
				IntPtr nakedTargetHandle;
				bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
					out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

				if (error != MonoIOError.ERROR_SUCCESS)
					throw MonoIO.GetException (error);

				targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
				return ret;
			} finally {
				if (release)
					hSourceHandle.DangerousRelease ();
			}
		}
开发者ID:BogdanovKirill,项目名称:mono,代码行数:22,代码来源:NativeMethods.cs

示例11: CheckPrivilege

        private bool CheckPrivilege(string exectedPrivilege, SafeHandle currentUserToken)
        {
            AdvApi32PInvoke.LUID luid = default(AdvApi32PInvoke.LUID);

            expect(() => get_privilege_identifier(exectedPrivilege, out luid));

            AdvApi32PInvoke.PRIVILEGE_SET privilegeSet = new AdvApi32PInvoke.PRIVILEGE_SET();
            privilegeSet.PrivilegeCount = 1;
            privilegeSet.Control = AdvApi32PInvoke.PRIVILEGE_SET.PRIVILEGE_SET_ALL_NECESSARY;
            privilegeSet.Privilege = new AdvApi32PInvoke.LUID_AND_ATTRIBUTES[1];
            privilegeSet.Privilege[0].Luid = luid;
            privilegeSet.Privilege[0].Attributes = AdvApi32PInvoke.LUID_AND_ATTRIBUTES.SE_PRIVILEGE_REMOVED;

            bool privilegeCheckResult;

            bool executionResult = AdvApi32PInvoke.PrivilegeCheck(currentUserToken.DangerousGetHandle(),
                ref privilegeSet, out privilegeCheckResult);

            expect(() => executionResult);

            return privilegeCheckResult;
        }
开发者ID:fschwiet,项目名称:PShochu,代码行数:22,代码来源:verify_privileges.cs

示例12: ToRecipientInfosForThisIndex

        private static IEnumerable<RecipientInfo> ToRecipientInfosForThisIndex(SafeHandle pCmsgCmsRecipientInfoMemory, int index)
        {
            bool mustRelease = false;
            pCmsgCmsRecipientInfoMemory.DangerousAddRef(ref mustRelease);
            try
            {
                unsafe
                {
                    CMSG_CMS_RECIPIENT_INFO* pCMsgCmsRecipientInfo = (CMSG_CMS_RECIPIENT_INFO*)(pCmsgCmsRecipientInfoMemory.DangerousGetHandle());
                    switch (pCMsgCmsRecipientInfo->dwRecipientChoice)
                    {
                        case CMsgCmsRecipientChoice.CMSG_KEY_TRANS_RECIPIENT:
                            return new KeyTransRecipientInfo[] { new KeyTransRecipientInfo(new KeyTransRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index)) };

                        case CMsgCmsRecipientChoice.CMSG_KEY_AGREE_RECIPIENT:
                            {
                                CMSG_KEY_AGREE_RECIPIENT_INFO* pCmsKeyAgreeRecipientInfo = pCMsgCmsRecipientInfo->KeyAgree;
                                int numKeys = pCmsKeyAgreeRecipientInfo->cRecipientEncryptedKeys;
                                KeyAgreeRecipientInfo[] recipients = new KeyAgreeRecipientInfo[numKeys];
                                for (int subIndex = 0; subIndex < numKeys; subIndex++)
                                {
                                    recipients[subIndex] = new KeyAgreeRecipientInfo(new KeyAgreeRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index, subIndex));
                                }
                                return recipients;
                            }

                        default:
                            throw ErrorCode.E_NOTIMPL.ToCryptographicException();
                    }
                }
            }
            finally
            {
                if (mustRelease)
                {
                    pCmsgCmsRecipientInfoMemory.DangerousRelease();
                }
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:39,代码来源:DecryptorPalWindows.DecodeRecipients.cs

示例13: NegotiationInfoClass

        internal NegotiationInfoClass(SafeHandle safeHandle, int negotiationState)
        {
            if (safeHandle.IsInvalid)
            {
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Invalid handle:{safeHandle}");
                return;
            }

            IntPtr packageInfo = safeHandle.DangerousGetHandle();
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}");

            if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE
                || negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC)
            {
                IntPtr unmanagedString = Marshal.ReadIntPtr(packageInfo, SecurityPackageInfo.NameOffest);
                string name = null;
                if (unmanagedString != IntPtr.Zero)
                {
                    name = Marshal.PtrToStringUni(unmanagedString);
                }

                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}");

                // An optimization for future string comparisons.
                if (string.Compare(name, Kerberos, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AuthenticationPackage = Kerberos;
                }
                else if (string.Compare(name, NTLM, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AuthenticationPackage = NTLM;
                }
                else
                {
                    AuthenticationPackage = name;
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:38,代码来源:NegotiationInfoClass.cs

示例14: BindHandle

 public static bool BindHandle(SafeHandle osHandle)
 {
     if (osHandle == null)
     {
         throw new ArgumentNullException("osHandle");
     }
     bool flag = false;
     bool success = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         osHandle.DangerousAddRef(ref success);
         flag = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
     }
     finally
     {
         if (success)
         {
             osHandle.DangerousRelease();
         }
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:ThreadPool.cs

示例15: Initialise

 /// <summary>
 /// Initialises the device
 /// </summary>
 /// <param name="strPath">Path to the device</param>
 private void Initialise(string strPath)
 {
     // Create the file from the device path
     m_hHandle = Kernel32.CreateFile(strPath, Kernel32.GENERIC_READ | Kernel32.GENERIC_WRITE, 0, IntPtr.Zero, Kernel32.OPEN_EXISTING, Kernel32.FILE_FLAG_OVERLAPPED, 0);
     
     if (!m_hHandle.IsInvalid)	// if the open worked...
     {
         IntPtr lpData;
         if (Hid.HidD_GetPreparsedData(m_hHandle, out lpData))	// get windows to read the device data into an internal buffer
         {
             try
             {
                 HIDP_CAPS oCaps;
                 Hid.HidP_GetCaps(lpData, out oCaps);	// extract the device capabilities from the internal buffer
                 m_nInputReportLength = oCaps.InputReportByteLength;	// get the input...
                 m_nOutputReportLength = oCaps.OutputReportByteLength;	// ... and output report lengths
                 //m_oFile = new FileStream(m_hHandle, FileAccess.Read | FileAccess.Write, true, m_nInputReportLength, true);	// wrap the file handle in a .Net file stream
                 m_oFile = new FileStream(new SafeFileHandle(m_hHandle.DangerousGetHandle(), false), FileAccess.Read | FileAccess.Write, m_nInputReportLength, true);	// wrap the file handle in a .Net file stream
                 BeginAsyncRead();	// kick off the first asynchronous read
             }
             finally
             {
                 Hid.HidD_FreePreparsedData(lpData);	// before we quit the funtion, we must free the internal buffer reserved in GetPreparsedData
             }
         }
         else	// GetPreparsedData failed? Chuck an exception
         {
             throw HIDDeviceException.GenerateWithWinError("GetPreparsedData failed");
         }
     }
     else	// File open failed? Chuck an exception
     {
         m_hHandle.SetHandleAsInvalid();
         throw HIDDeviceException.GenerateWithWinError("Failed to create device file");
     }
 }
开发者ID:Wiladams,项目名称:NewTOAPIA,代码行数:40,代码来源:HIDDevice.cs


注:本文中的System.Runtime.InteropServices.SafeHandle.DangerousGetHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。