Exemplo n.º 1
0
 public static IntPtr GetProcAddressWrapper(SafeLibraryHandle implDll, string procName)
 {
     IntPtr procaddr = NativeMethods.GetProcAddress(implDll, procName);
     if (IntPtr.Zero == procaddr)
     {
         //
         // We'll get the last error's message using Win32Exception
         // Adding the procName gives more context.
         //
         ThrowWin32ExceptionWithContext(new Win32Exception(), procName);
     }
     return procaddr;
 }
        public static IntPtr GetProcAddressWrapper(SafeLibraryHandle implDll, string procName)
        {
            IntPtr procaddr = NativeMethods.GetProcAddress(implDll, procName);

            if (IntPtr.Zero == procaddr)
            {
                //
                // We'll get the last error's message using Win32Exception
                // Adding the procName gives more context.
                //
                ThrowWin32ExceptionWithContext(new Win32Exception(), procName);
            }
            return(procaddr);
        }
Exemplo n.º 3
0
        //
        // GetBrowserToken not required because that is accomplished via Pheonix bit etc. (not exposed thru
        // managed interface).
        //

        //
        // Summary:
        // Performs initialization of the CardSpaceShim if necessary.
        // The v1 service will only allow one request from the user,
        // however locking anyway in case we change our behavior in v2.
        //
        public void InitializeIfNecessary()
        {
            if (!m_isInitialized)
            {
                lock (m_syncRoot)
                {
                    if (!m_isInitialized)
                    {
                        string implDllPath = GetCardSpaceImplementationDll();

                        m_implementationDll = SafeLibraryHandle.LoadLibraryW(implDllPath);
                        if (m_implementationDll.IsInvalid)
                        {
                            throw NativeMethods.ThrowWin32ExceptionWithContext(new Win32Exception(), implDllPath);
                        }

                        try
                        {
                            //
                            // Functions are listed in alphabetical order
                            //

                            IntPtr procaddr1 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "CloseCryptoHandle");
                            m_csShimCloseCryptoHandle =
                                (CsV2CloseCryptoHandle)Marshal.GetDelegateForFunctionPointer(
                                    procaddr1, typeof(CsV2CloseCryptoHandle));

                            IntPtr procaddr2 = NativeMethods.GetProcAddressWrapper(
                                m_implementationDll, "Decrypt");
                            m_csShimDecrypt =
                                (CsV2Decrypt)Marshal.GetDelegateForFunctionPointer(
                                    procaddr2, typeof(CsV2Decrypt));

                            IntPtr procaddr3 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "Encrypt");
                            m_csShimEncrypt =
                                (CsV2Encrypt)Marshal.GetDelegateForFunctionPointer(
                                    procaddr3, typeof(CsV2Encrypt));

                            IntPtr procaddr4 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "FreeToken");
                            m_csShimFreeToken =
                                (CsV2FreeToken)Marshal.GetDelegateForFunctionPointer(
                                    procaddr4, typeof(CsV2FreeToken));

                            IntPtr procaddr5 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GenerateDerivedKey");
                            m_csShimGenerateDerivedKey =
                                (CsV2GenerateDerivedKey)Marshal.GetDelegateForFunctionPointer(
                                    procaddr5, typeof(CsV2GenerateDerivedKey));

                            IntPtr procaddr6 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetCryptoTransform");
                            m_csShimGetCryptoTransform =
                                (CsV2GetCryptoTransform)Marshal.GetDelegateForFunctionPointer(
                                    procaddr6, typeof(CsV2GetCryptoTransform));

                            IntPtr procaddr7 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetKeyedHash");
                            m_csShimGetKeyedHash =
                                (CsV2GetKeyedHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr7, typeof(CsV2GetKeyedHash));

                            IntPtr procaddr8 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetToken");
                            m_csShimGetToken =
                                (CsV2GetToken)Marshal.GetDelegateForFunctionPointer(
                                    procaddr8, typeof(CsV2GetToken));

                            IntPtr procaddr9 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashCore");
                            m_csShimHashCore =
                                (CsV2HashCore)Marshal.GetDelegateForFunctionPointer(
                                    procaddr9, typeof(CsV2HashCore));

                            IntPtr procaddr10 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashFinal");
                            m_csShimHashFinal =
                                (CsV2HashFinal)Marshal.GetDelegateForFunctionPointer(
                                    procaddr10, typeof(CsV2HashFinal));

                            IntPtr procaddr11 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ImportInformationCard");
                            m_csShimImportInformationCard =
                                (CsV2ImportInformationCard)Marshal.GetDelegateForFunctionPointer(
                                    procaddr11, typeof(CsV2ImportInformationCard));

                            IntPtr procaddr12 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ManageCardSpace");
                            m_csShimManageCardSpace =
                                (CsV2ManageCardSpace)Marshal.GetDelegateForFunctionPointer(
                                    procaddr12, typeof(CsV2ManageCardSpace));

                            IntPtr procaddr13 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "SignHash");
                            m_csShimSignHash =
                                (CsV2SignHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr13, typeof(CsV2SignHash));

                            IntPtr procaddr14 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformBlock");
                            m_csShimTransformBlock =
                                (CsV2TransformBlock)Marshal.GetDelegateForFunctionPointer(
                                    procaddr14, typeof(CsV2TransformBlock));

                            IntPtr procaddr15 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformFinalBlock");
                            m_csShimTransformFinalBlock =
                                (CsV2TransformFinalBlock)Marshal.GetDelegateForFunctionPointer(
                                    procaddr15, typeof(CsV2TransformFinalBlock));


                            IntPtr procaddr16 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "VerifyHash");
                            m_csShimVerifyHash =
                                (CsV2VerifyHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr16, typeof(CsV2VerifyHash));
                        }
                        catch (Win32Exception)
                        {
                            //
                            // NB: IDT.ThrowHelperError would have logged for the Win32Exception
                            //
                            IDT.Assert(!m_isInitialized, "If an exception occurred, we expect this to be false");
                            throw;
                        }

                        m_isInitialized = true;
                    }
                }
            }
        }
 private static extern IntPtr GetProcAddress(
     SafeLibraryHandle hModule,
     [MarshalAs(UnmanagedType.LPStr)]
     string procname);
Exemplo n.º 5
0
 private static extern IntPtr GetProcAddress(
     SafeLibraryHandle hModule,
     [MarshalAs(UnmanagedType.LPStr)]
     string procname);