private static List <EntryTemplate> parse_entry(ProtectedStringDictionary Strings)
        {
            List <EntryTemplate> ret = new List <EntryTemplate>();

            string[] names = get_protected_dictionary_names(Strings);
            foreach (string name in names)
            {
                if (name.StartsWith("_etm_title_"))
                {
                    String          fieldName = name.Substring("_etm_title_".Length);
                    ProtectedString str       = Strings.Get("_etm_title_" + fieldName);
                    String          title     = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_type_" + fieldName);
                    String type = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_position_" + fieldName);
                    String position = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_options_" + fieldName);
                    String options = str == null ? "" : str.ReadString();
                    ret.Add(new EntryTemplate(title, fieldName, type, position, options));
                }
            }
            ret.Sort((t1, t2) => t1.position.CompareTo(t2.position));

            return(ret);
        }
Esempio n. 2
0
        private void buttonFieldEdit_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection lvsicSel = listView2.SelectedItems;
            List <string> all = new List <string>();

            for (int i = 0; i < listView2.Items.Count; ++i)
            {
                all.Add(listView2.Items[i].Text);
            }

            List <string> others = all.GetRange(0, all.Count);

            others.Remove(lvsicSel[0].Text);

            FormFieldType fft           = Utilities.FormFieldTypeFromDisplay(lvsicSel[0].SubItems[3].Text);
            string        existingValue = "";

            if (lvsicSel[0].SubItems[1].Text == "KeePass password" || lvsicSel[0].SubItems[1].Text == "KeePass username")
            {
                existingValue = lvsicSel[0].SubItems[1].Text;
            }
            else
            {
                existingValue = _strings.Get("KPRPC Form field " + lvsicSel[0].SubItems[0].Text + " value").ReadString();
            }

            KeeFoxFieldForm kfff = new KeeFoxFieldForm(lvsicSel[0].SubItems[0].Text, existingValue, lvsicSel[0].SubItems[2].Text, fft, int.Parse(lvsicSel[0].SubItems[4].Text), others);

            if (kfff.ShowDialog() == DialogResult.OK)
            {
                // remove the old field data
                fields.Remove(lvsicSel[0].Text);
                RemoveFieldListItem(lvsicSel[0]);

                string displayName = kfff.Name;
                if (kfff.Value == "KeePass password" || kfff.Value == "KeePass username")
                {
                    displayName = kfff.Value;
                }

                string type = Utilities.FormFieldTypeToDisplay(kfff.Type, false);
                int    page = kfff.Page;

                ListViewItem lvi = new ListViewItem(new string[] { kfff.Name, kfff.Type == FormFieldType.FFTpassword ? "********" : kfff.Value, kfff.Id, type, page.ToString() });
                AddFieldListItem(lvi);
                fields.Add(kfff.Name, new FormField(kfff.Name, displayName, kfff.Value, kfff.Type, kfff.Id, page));


                UpdateFieldStrings();
            }
        }
        public static bool ModIfNeeded(this PwEntry entry,
                                       string key, ProtectedString value)
        {
            ProtectedStringDictionary strings = entry.Strings;

            if (value == null)
            {
                return(strings.Remove(key));
            }
            else if (!strings.Exists(key) ||
                     !strings.Get(key).OrdinalEquals(value, true))
            {
                strings.Set(key, value);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
		public static void NormalizeNewLines(ProtectedStringDictionary dict,
			bool bWindows)
		{
			if(dict == null) { Debug.Assert(false); return; }

			if(m_vNewLineChars == null)
				m_vNewLineChars = new char[]{ '\r', '\n' };

			List<string> vKeys = dict.GetKeys();
			foreach(string strKey in vKeys)
			{
				ProtectedString ps = dict.Get(strKey);
				if(ps == null) { Debug.Assert(false); continue; }

				string strValue = ps.ReadString();
				if(strValue.IndexOfAny(m_vNewLineChars) < 0) continue;

				dict.Set(strKey, new ProtectedString(ps.IsProtected,
					NormalizeNewLines(strValue, bWindows)));
			}
		}
        internal void ReadProtectedStringEx(XmlNode xmlNode, ProtectedStringDictionary dictStorage)
        {
            ProcessNode(xmlNode);

            string       strKey   = string.Empty;
            XorredBuffer xbValue  = null;
            string       strValue = null;

            foreach (XmlNode xmlChild in xmlNode.ChildNodes)
            {
                if (xmlChild.Name == ElemKey)
                {
                    ProcessNode(xmlChild);
                    strKey = xmlChild.InnerText;
                }
                else if (xmlChild.Name == ElemValue)
                {
                    xbValue = ProcessNode(xmlChild);

                    // If contents aren't protected: read as plain-text string
                    if (xbValue == null)
                    {
                        strValue = xmlChild.InnerText;
                    }
                }
                else
                {
                    ReadUnknown(xmlChild);
                }
            }

            if (xbValue != null)
            {
                Debug.Assert(strValue == null);
                dictStorage.Set(strKey, new ProtectedString(true, xbValue));
            }
            else
            {
                Debug.Assert(strValue != null);
                dictStorage.Set(strKey, new ProtectedString(false, strValue));
            }

#if DEBUG
            if (m_format == Kdb4Format.Default)
            {
                if (strKey == PwDefs.TitleField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectTitle ==
                                 dictStorage.Get(strKey).IsProtected);
                }
                else if (strKey == PwDefs.UserNameField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectUserName ==
                                 dictStorage.Get(strKey).IsProtected);
                }
                else if (strKey == PwDefs.PasswordField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectPassword ==
                                 dictStorage.Get(strKey).IsProtected);
                }
                else if (strKey == PwDefs.UrlField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectUrl ==
                                 dictStorage.Get(strKey).IsProtected);
                }
                else if (strKey == PwDefs.NotesField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectNotes ==
                                 dictStorage.Get(strKey).IsProtected);
                }
            }
#endif
        }
Esempio n. 6
0
        private void ReadProtectedStringEx(XmlNode xmlNode, ProtectedStringDictionary dictStorage)
        {
            ProcessNode(xmlNode);

            string strKey = string.Empty;
            XorredBuffer xbValue = null;
            string strValue = null;

            foreach(XmlNode xmlChild in xmlNode.ChildNodes)
            {
                if(xmlChild.Name == ElemKey)
                {
                    ProcessNode(xmlChild);
                    strKey = xmlChild.InnerText;
                }
                else if(xmlChild.Name == ElemValue)
                {
                    xbValue = ProcessNode(xmlChild);

                    // If contents aren't protected: read as plain-text string
                    if(xbValue == null) strValue = xmlChild.InnerText;
                }
                else ReadUnknown(xmlChild);
            }

            if(xbValue != null)
            {
                Debug.Assert(strValue == null);
                dictStorage.Set(strKey, new ProtectedString(true, xbValue));
            }
            else
            {
                Debug.Assert(strValue != null);
                dictStorage.Set(strKey, new ProtectedString(false, strValue));
            }

            #if DEBUG
            if(m_format == Kdb4Format.Default)
            {
                if(strKey == PwDefs.TitleField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectTitle ==
                        dictStorage.Get(strKey).IsProtected);
                }
                else if(strKey == PwDefs.UserNameField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectUserName ==
                        dictStorage.Get(strKey).IsProtected);
                }
                else if(strKey == PwDefs.PasswordField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectPassword ==
                        dictStorage.Get(strKey).IsProtected);
                }
                else if(strKey == PwDefs.UrlField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectUrl ==
                        dictStorage.Get(strKey).IsProtected);
                }
                else if(strKey == PwDefs.NotesField)
                {
                    Debug.Assert(m_pwDatabase.MemoryProtection.ProtectNotes ==
                        dictStorage.Get(strKey).IsProtected);
                }
            }
            #endif
        }
Esempio n. 7
0
		public static void NormalizeNewLines(ProtectedStringDictionary dict,
			bool bWindows)
		{
			if(dict == null) { Debug.Assert(false); return; }

			if(m_vNewLineChars == null)
				m_vNewLineChars = new char[]{ '\r', '\n' };

			List<string> vKeys = dict.GetKeys();
			foreach(string strKey in vKeys)
			{
				ProtectedString ps = dict.Get(strKey);
				if(ps == null) { Debug.Assert(false); continue; }

				string strValue = ps.ReadString();
				if(strValue.IndexOfAny(m_vNewLineChars) < 0) continue;

				dict.Set(strKey, new ProtectedString(ps.IsProtected,
					NormalizeNewLines(strValue, bWindows)));
			}
		}
        private static List<EntryTemplate> parse_entry(ProtectedStringDictionary Strings)
        {
            List<EntryTemplate> ret = new List<EntryTemplate>();
            string[] names = get_protected_dictionary_names(Strings);
            foreach (string name in names) {
                if (name.StartsWith("_etm_title_")) {
                    String fieldName = name.Substring("_etm_title_".Length);
                    ProtectedString str = Strings.Get("_etm_title_" + fieldName);
                    String title = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_type_" + fieldName);
                    String type = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_position_" + fieldName);
                    String position = str == null ? "" : str.ReadString();
                    str = Strings.Get("_etm_options_" + fieldName);
                    String options = str == null ? "" : str.ReadString();
                    ret.Add(new EntryTemplate(title, fieldName, type, position, options));
                }
            }
            ret.Sort((t1, t2) => t1.position.CompareTo(t2.position));

            return ret;
        }