Ejemplo n.º 1
0
        private bool TryGetSubKey(KeyDisposition disposition, string lpSubKey,
                                  KeySecurity samDesired, Win32Api.RegWow64Options wowOptions, out KeyImplHolder subKeyHolder)
        {
            KeyIdentity subKeyIdentity = new KeyIdentity(identity_, wowOptions, lpSubKey);
            IKeyImpl    keyImpl        = cachedKeyImpls_.TryGet(subKeyIdentity, disposition, samDesired);

            if (keyImpl != null)
            {
                subKeyHolder = new NotOwningKeyImplHolder(keyImpl);
                return(true);
            }
            KeyImplHolder newOne;

            if (!opener_.TryOpenHolder(identity_, disposition, subKeyIdentity, samDesired, out newOne))
            {
                subKeyHolder = null;
                return(false);
            }
            subKeyHolder = cachedKeyImpls_.Add(subKeyIdentity, disposition, newOne);
            return(true);
        }
Ejemplo n.º 2
0
        private DoesntExistOrMarkedAsDeletedState DoesntExistOrMarkedAsDeleted(KeyIdentity existingBase, KeyIdentity identity,
                                                                               IntPtr allocatedpData, IntPtr allocatedpcbData)
        {
            string[] subkeys = identity.SplitPath();
            int      existingLevels, nonRemovableLevels;

            CalcNonRemovableLevels(existingBase, identity, out existingLevels, out nonRemovableLevels);
            if (subkeys.Length <= nonRemovableLevels)
            {
                return(DoesntExistOrMarkedAsDeletedState.Exists);
            }

            for (int level = existingLevels; level < subkeys.Length; level++)
            {
                KeyIdentity   curLevelIdentity = KeyIdentity.Build(identity.BaseKey, subkeys, level);
                KeyImplHolder holder;
                lock (this)
                {
                    IKeyImpl keyImpl = null;

                    if (level <= nonRemovableLevels)
                    {
                        keyImpl = cacheForDeletedMarks_.TryGet(curLevelIdentity, KeyDisposition.DIFF_HIVE, cacheSecurity_);
                    }
                    if (keyImpl != null)
                    {
                        holder = new NotOwningKeyImplHolder(keyImpl);
                    }
                    else
                    {
                        OffregLib.OffregKey   key;
                        OffregLib.Win32Result result;
                        if (!hive_.Root.TryOpenSubKey(OffRegKey.GetMainOffRegPath(curLevelIdentity), out key, out result))
                        {
                            return(DoesntExistOrMarkedAsDeletedState.DoesntExist);
                        }
                        holder = new KeyImplHolder(new OffRegKey(this, key, curLevelIdentity));
                        if (level <= nonRemovableLevels)
                        {
                            // Adding to cache only the lowest, non removable level
                            holder = cacheForDeletedMarks_.Add(
                                curLevelIdentity, KeyDisposition.DIFF_HIVE,
                                holder);
                        }
                    }
                }
                using (holder)
                {
                    Marshal.WriteInt32(allocatedpcbData, Marshal.SizeOf(typeof(int)));
                    if (holder.GetKeyImpl().TryQueryValue(
                            DELETED_PREFIX + subkeys[level],
                            IntPtr.Zero, IntPtr.Zero, allocatedpData, allocatedpcbData))
                    {
                        if (Marshal.ReadInt32(allocatedpcbData) == Marshal.SizeOf(typeof(int)) &&
                            Marshal.ReadInt32(allocatedpData) != 0)
                        {
                            // There is a special value marking key as deleted
                            return(DoesntExistOrMarkedAsDeletedState.MarkedAsDeleted);
                        }
                    }
                }
            }
            return(DoesntExistOrMarkedAsDeletedState.Exists);
        }