예제 #1
0
파일: Win32.cs 프로젝트: sjyanxin/WPFSource
        [System.Security.SecurityCritical]  // auto-generated
        internal static void InitializeReferencedDomainsPointer(SafeLsaMemoryHandle referencedDomains) 
        {
            Contract.Assert(referencedDomains != null, "referencedDomains != null"); 
 
            // We don't know the real size of the referenced domains yet, so we need to set an initial
            // size based on the LSA_REFERENCED_DOMAIN_LIST structure, then resize it to include all of 
            // the domains.
            referencedDomains.Initialize((uint)Marshal.SizeOf(typeof(Win32Native.LSA_REFERENCED_DOMAIN_LIST)));
            Win32Native.LSA_REFERENCED_DOMAIN_LIST domainList = referencedDomains.Read<Win32Native.LSA_REFERENCED_DOMAIN_LIST>(0);
 
            unsafe
            { 
                byte* pRdl = null; 
                RuntimeHelpers.PrepareConstrainedRegions();
                try 
                {
                    referencedDomains.AcquirePointer(ref pRdl);

                    // If there is a trust information list, then the buffer size is the end of that list minus 
                    // the beginning of the domain list. Otherwise, then the buffer is just the size of the
                    // referenced domain list structure, which is what we defaulted to. 
                    if (!domainList.Domains.IsNull()) 
                    {
                        Win32Native.LSA_TRUST_INFORMATION* pTrustInformation = (Win32Native.LSA_TRUST_INFORMATION*)domainList.Domains; 
                        pTrustInformation = pTrustInformation + domainList.Entries;

                        long bufferSize = (byte*)pTrustInformation - pRdl;
                        Contract.Assert(bufferSize > 0, "bufferSize > 0"); 
                        referencedDomains.Initialize((ulong)bufferSize);
                    } 
                } 
                finally
                { 
                    if (pRdl != null)
                        referencedDomains.ReleasePointer();
                }
            } 
        }
 internal static unsafe void InitializeReferencedDomainsPointer(SafeLsaMemoryHandle referencedDomains)
 {
     referencedDomains.Initialize((ulong) Marshal.SizeOf(typeof(Win32Native.LSA_REFERENCED_DOMAIN_LIST)));
     Win32Native.LSA_REFERENCED_DOMAIN_LIST lsa_referenced_domain_list = referencedDomains.Read<Win32Native.LSA_REFERENCED_DOMAIN_LIST>(0L);
     byte* pointer = null;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         referencedDomains.AcquirePointer(ref pointer);
         if (!lsa_referenced_domain_list.Domains.IsNull())
         {
             Win32Native.LSA_TRUST_INFORMATION* domains = (Win32Native.LSA_TRUST_INFORMATION*) lsa_referenced_domain_list.Domains;
             domains += lsa_referenced_domain_list.Entries;
             long num = (long) ((domains - pointer) / 1);
             referencedDomains.Initialize((ulong) num);
         }
     }
     finally
     {
         if (pointer != null)
         {
             referencedDomains.ReleasePointer();
         }
     }
 }