예제 #1
0
        private void User_CreateReg(object sender, RoutedEventArgs e)
        {
            Dictionary <string, List <PolicyItem> > registryKeyItems = new Dictionary <string, List <PolicyItem> >();

            try
            {
                foreach (object item in UserPolicyItems.SelectedItems)
                {
                    if (item is PolicyItem)
                    {
                        PolicyItem policyItem = (PolicyItem)item;

                        if (!registryKeyItems.ContainsKey(policyItem.Key))
                        {
                            registryKeyItems.Add(policyItem.Key, new List <PolicyItem>());
                        }

                        registryKeyItems[policyItem.Key].Add(policyItem);
                    }
                }

                string tester = "Windows Registry Editor Version 5.00\r\n";

                foreach (string key in registryKeyItems.Keys)
                {
                    if (registryKeyItems[key].Count == 1 && registryKeyItems[key][0].IsKeyDeletion)
                    {
                        tester += "\r\n[-HKEY_CURRENT_USER\\" + key + "]\r\n";
                    }
                    else
                    {
                        tester += "\r\n[HKEY_CURRENT_USER\\" + key + "]\r\n";

                        foreach (PolicyItem values in registryKeyItems[key])
                        {
                            tester += values.RegFileString() + "\r\n";
                        }
                    }
                }

                Clipboard.SetData(DataFormats.Text, tester);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void Machine_Write(object sender, RoutedEventArgs e)
        {
            try{
                foreach (object item in MachinePolicyItems.SelectedItems)
                {
                    if (item is PolicyItem)
                    {
                        PolicyItem policyItem = (PolicyItem)item;

                        policyItem.Write(true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        void CopyCmdExecuted(object target, ExecutedRoutedEventArgs e)
        {
            ListView lv = e.OriginalSource as ListView;

            string copyContent = String.Empty;

            int count = 0;

            foreach (object item in lv.SelectedItems)
            {
                if (count > 0)
                {
                    copyContent += Environment.NewLine;
                }

                if (item is String)
                {
                    copyContent += (String)item;
                }
                else if (item is PolicyItem)
                {
                    PolicyItem policyItem = (PolicyItem)item;
                    copyContent += policyItem.LocalCompare.ActualPolicy.ExistsText() + "\t" +
                                   policyItem.LocalCompare.ActualPolicy.LocalValue + "\t" +
                                   policyItem.LocalCompare.DiffContextPolicy.ExistsText() + "\t" +
                                   policyItem.LocalCompare.DiffContextPolicy.LocalValue + "\t" +
                                   policyItem.LocalCompare.NonPolicy.ExistsText() + "\t" +
                                   policyItem.LocalCompare.NonPolicy.LocalValue + "\t" +
                                   policyItem.LocalCompare.DiffContextNonPolicy.ExistsText() + "\t" +
                                   policyItem.LocalCompare.DiffContextNonPolicy.LocalValue + "\t" +
                                   policyItem.Key + "\t" + policyItem.Value + "\t" + policyItem.StringType + "\t" + policyItem.Data;
                }
                count++;
            }

            try
            {
                Clipboard.SetData(DataFormats.Text, copyContent);
            }
            catch
            {
            }
        }
예제 #4
0
        public void AddPolicy(string FileName)
        {
            BinaryReader binaryStream = new BinaryReader(File.OpenRead(FileName), Encoding.Unicode);

            PolicyItem PolItem = new PolicyItem();

            int length     = (int)binaryStream.BaseStream.Length;
            int pos        = 0;
            int CurrentPos = POSITION_REG_END;

            if (length >= sizeof(int) * 2)
            {
                Signature   = binaryStream.ReadInt32();
                FileVersion = binaryStream.ReadInt32();
                pos        += sizeof(int) * 2;
            }

            while (pos < length)
            {
                if (CurrentPos == POSITION_REG_END || CurrentPos == POSITION_REG_KEY ||
                    CurrentPos == POSITION_REG_VALUE)
                {
                    char NextChar = binaryStream.ReadChar();
                    pos += sizeof(char);

                    if (NextChar == '[' && CurrentPos == POSITION_REG_END)
                    {
                        PolItem    = new PolicyItem();
                        CurrentPos = POSITION_REG_KEY;
                    }
                    else if (NextChar == ']' && CurrentPos == POSITION_REG_END)
                    {
                        PolicyItems.Add(PolItem);
                    }
                    else if (NextChar != ';' && CurrentPos == POSITION_REG_KEY)
                    {
                        if (NextChar != '\0')
                        {
                            PolItem.Key += NextChar;
                        }
                    }
                    else if (NextChar == ';' && CurrentPos == POSITION_REG_KEY)
                    {
                        CurrentPos = POSITION_REG_VALUE;
                    }
                    else if (NextChar != ';' && CurrentPos == POSITION_REG_VALUE)
                    {
                        if (NextChar != '\0')
                        {
                            PolItem.Value += NextChar;
                        }
                    }
                    else if (NextChar == ';' && CurrentPos == POSITION_REG_VALUE)
                    {
                        CurrentPos = POSITION_REG_TYPE;
                    }
                }
                else if (CurrentPos == POSITION_REG_TYPE)
                {
                    PolItem.Type = binaryStream.ReadInt32();
                    pos         += sizeof(int);
                    CurrentPos   = POSITION_REG_SIZE;

                    if (pos < length)
                    {
                        binaryStream.ReadChar();
                        pos += sizeof(char);
                    }
                }
                else if (CurrentPos == POSITION_REG_SIZE)
                {
                    PolItem.Size = binaryStream.ReadInt32();
                    pos         += sizeof(int);
                    CurrentPos   = POSITION_REG_DATA;

                    if (pos < length)
                    {
                        binaryStream.ReadChar();
                        pos += sizeof(char);
                    }

                    if ((pos + PolItem.Size) < length)
                    {
                        PolItem.SetData(binaryStream.ReadBytes(PolItem.Size), PolItem.Size);
                        CurrentPos = POSITION_REG_END;
                        pos       += PolItem.Size;
                    }
                }
            }


            binaryStream.Close();
        }
예제 #5
0
        private PolicyItemCheckItem TestItem(RegistryKey passedRoot, string passedKey, string passedValue, PolicyItem item)
        {
            PolicyItemCheckItem returnValue = new PolicyItemCheckItem();

            try
            {
                RegistryKey rk = passedRoot.OpenSubKey(passedKey);

                object Value = rk.GetValue(passedValue);

                if (Value != null)
                {
                    RegistryValueKind rvk = rk.GetValueKind(item.Value);

                    if (ConvertRegKindToString(rvk).ToString().Equals(item.StringType))
                    {
                        if (rvk.Equals(RegistryValueKind.Binary))
                        {
                            byte[] bytes = (byte[])Value;
                            string vs    = "";

                            for (int i = 0; i < bytes.Length; i++)
                            {
                                vs += String.Format("{0:X2}", bytes[i]);
                            }

                            returnValue.LocalValue = vs;

                            if (vs.Equals(item.Data))
                            {
                                returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                                returnValue.ExistsInfo = "Values Match";
                            }
                            else
                            {
                                returnValue.Exists     = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS;
                                returnValue.ExistsInfo = "Local value " + vs;
                            }
                        }
                        else if (rvk.Equals(RegistryValueKind.ExpandString))
                        {
                            returnValue.LocalValue = Value.ToString();

                            if (Value.ToString().Equals(item.Data))
                            {
                                returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                                returnValue.ExistsInfo = "Values Match";
                            }
                            else
                            {
                                if (Environment.ExpandEnvironmentVariables(item.Data).Equals(Value.ToString()))
                                {
                                    returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                                    returnValue.ExistsInfo = "Values Match";
                                }
                                else
                                {
                                    returnValue.Exists     = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS;
                                    returnValue.ExistsInfo = "Local value " + Value;
                                }
                            }
                        }
                        else if (rvk.Equals(RegistryValueKind.MultiString))
                        {
                            string[] regItems = item.Data.Split('\0').Where(t => t.Length > 0).ToArray();

                            if (Value is string[] && regItems.SequenceEqual((string[])(Value)))
                            {
                                returnValue.LocalValue = Value.ToString();
                                returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                                returnValue.ExistsInfo = "Values Match";
                            }
                            else
                            {
                                returnValue.Exists     = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS;
                                returnValue.ExistsInfo = "Local value " + Value;
                                returnValue.LocalValue = Value.ToString();
                            }
                        }
                        else if (Value.ToString().Equals(item.Data))
                        {
                            returnValue.LocalValue = Value.ToString();
                            returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                            returnValue.ExistsInfo = "Values Match";
                        }
                        else
                        {
                            returnValue.Exists     = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS;
                            returnValue.ExistsInfo = "Local value " + Value;
                            returnValue.LocalValue = Value.ToString();
                        }
                    }
                    else
                    {
                        returnValue.Exists     = PolicyItem.ITEM_EXISTS_TYPE_DIFFERS;
                        returnValue.ExistsInfo = "Local type " + ConvertRegKindToString(rvk).ToString();
                        returnValue.LocalValue = item.Data.ToString();
                    }
                }
                else if (item.Value.StartsWith("**del.") || item.StringType.Equals("REG_NONE"))
                {
                    returnValue.Exists     = PolicyItem.ITEM_EXISTS_SAME;
                    returnValue.ExistsInfo = "Deleted locally too";
                    returnValue.LocalValue = "";
                }
                else
                {
                    returnValue.Exists     = PolicyItem.ITEM_MISSING;
                    returnValue.ExistsInfo = "Not set locally";
                    returnValue.LocalValue = "";
                }
            }
            catch
            {
                returnValue.Exists     = PolicyItem.ITEM_MISSING;
                returnValue.ExistsInfo = "Not set locally";
                returnValue.LocalValue = "";
            }

            return(returnValue);
        }