Exemple #1
0
        private static SystemStoreInformation GetSystemNameAndKey(uint dwFlags, IntPtr pvSystemStore)
        {
            SystemStoreInformation info = new SystemStoreInformation();

            if ((dwFlags & Direct.CERT_SYSTEM_STORE_RELOCATE_FLAG) == Direct.CERT_SYSTEM_STORE_RELOCATE_FLAG)
            {
#if DESKTOP
                var relocate       = Marshal.PtrToStructure <CERT_SYSTEM_STORE_RELOCATE_PARA>(pvSystemStore);
                var registryHandle = new SafeRegistryHandle(relocate.pvBase, ownsHandle: false);

                info.Key = RegistryKey.FromHandle(registryHandle).Name;

                // The name is null terminated
                info.Name = Marshal.PtrToStringUni(relocate.pvSystemStore);
#else
                // Can't do registry access on WinRT
                throw new PlatformNotSupportedException();
#endif
            }
            else
            {
                // The name is null terminated
                info.Name = Marshal.PtrToStringUni(pvSystemStore);
            }

            info.Location = (SystemStoreLocation)(dwFlags & Direct.CERT_SYSTEM_STORE_LOCATION_MASK);
            return(info);
        }
Exemple #2
0
        private static SystemStoreInformation GetSystemNameAndKey(uint dwFlags, IntPtr pvSystemStore)
        {
            SystemStoreInformation info = default;

            if ((dwFlags & CryptoDefines.CERT_SYSTEM_STORE_RELOCATE_FLAG) == CryptoDefines.CERT_SYSTEM_STORE_RELOCATE_FLAG)
            {
                // TODO: Rewrite with WInterop registry code
                // var relocate = Marshal.PtrToStructure<CERT_SYSTEM_STORE_RELOCATE_PARA>(pvSystemStore);
                // var registryHandle = new SafeRegistryHandle(relocate.pvBase, ownsHandle: false);
                // info.Key = RegistryKey.FromHandle(registryHandle).Name;
                // The name is null terminated
                // info.Name = Marshal.PtrToStringUni(relocate.pvSystemStore);
            }
            else
            {
                // The name is null terminated
                info.Name = Marshal.PtrToStringUni(pvSystemStore) ?? string.Empty;
            }

            info.Location = (SystemStoreLocation)(dwFlags & CryptoDefines.CERT_SYSTEM_STORE_LOCATION_MASK);
            return(info);
        }