Example #1
0
        private void FreeSubKeys(KeyNodeCell subkeyCell)
        {
            if (subkeyCell.SubKeysIndex == -1)
            {
                throw new InvalidOperationException("No subkey list");
            }

            Cell list = _hive.GetCell<Cell>(subkeyCell.SubKeysIndex);

            SubKeyIndirectListCell indirectList = list as SubKeyIndirectListCell;
            if (indirectList != null)
            {
                ////foreach (int listIndex in indirectList.CellIndexes)
                for (int i = 0; i < indirectList.CellIndexes.Count; ++i)
                {
                    int listIndex = indirectList.CellIndexes[i];
                    _hive.FreeCell(listIndex);
                }
            }

            _hive.FreeCell(list.Index);
        }
Example #2
0
        /// <summary>
        /// Creates or opens a subkey.
        /// </summary>
        /// <param name="subkey">The relative path the the subkey</param>
        /// <returns>The subkey</returns>
        public RegistryKey CreateSubKey(string subkey)
        {
            if (string.IsNullOrEmpty(subkey))
            {
                return this;
            }

            string[] split = subkey.Split(new char[] { '\\' }, 2);
            int cellIndex = FindSubKeyCell(split[0]);

            if (cellIndex < 0)
            {
                KeyNodeCell newKeyCell = new KeyNodeCell(split[0], _cell.Index);
                newKeyCell.SecurityIndex = _cell.SecurityIndex;
                ReferenceSecurityCell(newKeyCell.SecurityIndex);
                _hive.UpdateCell(newKeyCell, true);

                LinkSubKey(split[0], newKeyCell.Index);

                if (split.Length == 1)
                {
                    return new RegistryKey(_hive, newKeyCell);
                }
                else
                {
                    return new RegistryKey(_hive, newKeyCell).CreateSubKey(split[1]);
                }
            }
            else
            {
                KeyNodeCell cell = _hive.GetCell<KeyNodeCell>(cellIndex);
                if (split.Length == 1)
                {
                    return new RegistryKey(_hive, cell);
                }
                else
                {
                    return new RegistryKey(_hive, cell).CreateSubKey(split[1]);
                }
            }
        }
Example #3
0
        private void FreeValues(KeyNodeCell cell)
        {
            if (cell.NumValues != 0 && cell.ValueListIndex != -1)
            {
                byte[] valueList = _hive.RawCellData(cell.ValueListIndex, cell.NumValues * 4);

                for (int i = 0; i < cell.NumValues; ++i)
                {
                    int valueIndex = Utilities.ToInt32LittleEndian(valueList, i * 4);
                    _hive.FreeCell(valueIndex);
                }

                _hive.FreeCell(cell.ValueListIndex);
                cell.ValueListIndex = -1;
                cell.NumValues = 0;
                cell.MaxValDataBytes = 0;
                cell.MaxValNameBytes = 0;
            }
        }
Example #4
0
 internal RegistryKey(RegistryHive hive, KeyNodeCell cell)
 {
     _hive = hive;
     _cell = cell;
 }