private bool ValidateStringNameEx(string str) { if (str == null) { Debug.Assert(false); return(false); } if (PwDefs.IsStandardField(str)) { return(false); } if (str.Length <= 0) { return(false); } char[] vInvalidChars = new char[] { '{', '}' }; if (str.IndexOfAny(vInvalidChars) >= 0) { return(false); } string strStart = (m_strStringName != null) ? m_strStringName : string.Empty; if (!strStart.Equals(str) && m_vStringDict.Exists(str)) { return(false); } // See ValidateStringName return(true); }
private static void ReadCustomField(XmlNode xmlNode, PwEntry pe) { string strName = string.Empty, strValue = string.Empty; foreach (XmlNode xmlChild in xmlNode) { if (xmlChild.Name == ElemCustomFieldName) { strName = XmlUtil.SafeInnerText(xmlChild); } else if (xmlChild.Name == ElemCustomFieldValue) { strValue = XmlUtil.SafeInnerText(xmlChild); } // else { } // Field 'VISIBLE' } if ((strName.Length == 0) || PwDefs.IsStandardField(strName)) { pe.Strings.Set(Guid.NewGuid().ToString(), new ProtectedString(false, strValue)); } else { pe.Strings.Set(strName, new ProtectedString(false, strValue)); } }
private static void MsAppend(PwEntry pe, string strFieldName, string[] vLine, int iIndex, PwDatabase pdContext) { if (iIndex >= vLine.Length) { Debug.Assert(false); return; } string strValue = vLine[iIndex]; if (string.IsNullOrEmpty(strValue)) { return; } strValue = strValue.Replace("\\r\\n", "\\n"); strValue = strValue.Replace("\\r", "\\n"); if (PwDefs.IsStandardField(strFieldName) && (strFieldName != PwDefs.NotesField)) { while (strValue.EndsWith("\\n")) { strValue = strValue.Substring(0, strValue.Length - 2); } strValue = strValue.Replace("\\n", ", "); } else { strValue = strValue.Replace("\\n", MessageService.NewLine); } ImportUtil.AppendToField(pe, strFieldName, strValue, pdContext); }
protected virtual void OnEntryChanged(EventArgs e) { if (Entry == null) { ClearObjects(); } else { var rows = new List <RowObject>(); // First, the standard fields, where present, in the standard order AddFieldIfNotEmpty(rows, PwDefs.TitleField); AddFieldIfNotEmpty(rows, PwDefs.UserNameField); AddFieldIfNotEmpty(rows, PwDefs.PasswordField); AddFieldIfNotEmpty(rows, PwDefs.UrlField); // Then, all custom strings rows.AddRange(from kvp in Entry.Strings where !PwDefs.IsStandardField(kvp.Key) && !IsExcludedField(kvp.Key) select new RowObject(kvp)); // Finally, an empty "add new" row rows.Add(RowObject.CreateInsertionRow()); SetRows(rows); } AllowCreateHistoryNow = true; // Whenever the entry is replaced, it counts as not having been edited yet (so the first edit is always given a history backup) }
protected override void DeleteFieldCommand(RowObject rowObject) { CreateHistoryEntry(); if (PwDefs.IsStandardField(rowObject.FieldName)) { var blankValue = new ProtectedString(rowObject.Value.IsProtected, new byte[0]); Entry.Strings.Set(rowObject.FieldName, blankValue); if (mOptions.HideEmptyFields) { RemoveObject(rowObject); } else { rowObject.Value = blankValue; RefreshObject(rowObject); } } else { Entry.Strings.Remove(rowObject.FieldName); RemoveObject(rowObject); } OnModified(EventArgs.Empty); }
protected override void ValidateFieldName(CellEditEventArgs e, string newValue) { base.ValidateFieldName(e, newValue); if (PwDefs.IsStandardField(newValue)) { ReportValidationFailure(e.Control, KPRes.FieldNameInvalid); e.Cancel = true; return; } var rowObject = (RowObject)e.RowObject; IEnumerable <PwEntry> entriesWithField; if (rowObject.IsInsertionRow) { entriesWithField = Entries; } else { entriesWithField = Entries.Where(entry => entry.Strings.Exists(rowObject.FieldName)); } // Disallow the field name if it already exists on any of the entries which have that field foreach (var entry in entriesWithField) { if (entry.Strings.Exists(newValue)) { ReportValidationFailure(e.Control, KPRes.FieldNameExistsAlready); e.Cancel = true; return; } } }
private void MultiApplyStrings() { ProtectedString psCue = MultipleValuesEx.CueProtectedString; EnsureStandardStrings(); for (int i = 0; i < m_v.Length; ++i) { PwEntry pe = m_v[i]; foreach (KeyValuePair <string, ProtectedString> kvpM in m_peM.Strings) { ProtectedString ps = pe.Strings.Get(kvpM.Key); bool bProt = kvpM.Value.IsProtected; bool bMultiProt; this.MultiStringProt.TryGetValue(kvpM.Key, out bMultiProt); if (bMultiProt && (ps != null)) { bProt = ps.IsProtected; } if (kvpM.Value.Equals(psCue, false)) { if ((ps != null) && (ps.IsProtected != bProt)) { PrepareMod(i); pe.Strings.Set(kvpM.Key, ps.WithProtection(bProt)); } } else if (kvpM.Value.IsEmpty && (ps == null) && PwDefs.IsStandardField(kvpM.Key)) { // Do not create the string } else { if ((ps == null) || !ps.Equals(kvpM.Value, false) || (ps.IsProtected != bProt)) { PrepareMod(i); pe.Strings.Set(kvpM.Key, kvpM.Value.WithProtection(bProt)); } } } List <string> lKeys = pe.Strings.GetKeys(); foreach (string strKey in lKeys) { if (!m_peM.Strings.Exists(strKey)) { PrepareMod(i); pe.Strings.Remove(strKey); } } } }
bool MakeAccessibleForKeyboard(PwEntryOutput entry, string searchUrl) { #if EXCLUDE_KEYBOARD return(false); #else bool hasData = false; Keepass2android.Kbbridge.KeyboardDataBuilder kbdataBuilder = new Keepass2android.Kbbridge.KeyboardDataBuilder(); String[] keys = { PwDefs.UserNameField, PwDefs.PasswordField, PwDefs.UrlField, PwDefs.NotesField, PwDefs.TitleField }; int[] resIds = { Resource.String.entry_user_name, Resource.String.entry_password, Resource.String.entry_url, Resource.String.entry_comment, Resource.String.entry_title }; //add standard fields: int i = 0; foreach (string key in keys) { String value = entry.OutputStrings.ReadSafe(key); if (value.Length > 0) { kbdataBuilder.AddString(key, GetString(resIds[i]), value); hasData = true; } i++; } //add additional fields: foreach (var pair in entry.OutputStrings) { var key = pair.Key; var value = pair.Value.ReadString(); if (!PwDefs.IsStandardField(key)) { kbdataBuilder.AddString(pair.Key, pair.Key, value); hasData = true; } } kbdataBuilder.Commit(); Keepass2android.Kbbridge.KeyboardData.EntryName = entry.OutputStrings.ReadSafe(PwDefs.TitleField); Keepass2android.Kbbridge.KeyboardData.EntryId = entry.Uuid.ToHexString(); if (hasData) { Keepass2android.Autofill.AutoFillService.NotifyNewData(searchUrl); } return(hasData); #endif }
public ProtectedCustomFieldDictionaryBuffer(List <KeyValuePair <String, ProtectedString> > entryStrings) : base(entryStrings.Count) { foreach (var kvp in entryStrings) { System.Diagnostics.Debug.Assert(!PwDefs.IsStandardField(kvp.Key)); AddStringField(kvp.Key, kvp.Value, null); } }
private void PopulateExtraStrings() { ViewGroup extraGroup = (ViewGroup)FindViewById(Resource.Id.extra_strings); foreach (var pair in Entry.Strings.Where(pair => !PwDefs.IsStandardField(pair.Key)).OrderBy(pair => pair.Key)) { var stringView = CreateExtraSection(pair.Key, pair.Value.ReadString(), pair.Value.IsProtected); extraGroup.AddView(stringView.View); } }
public static void AppendToField(PwEntry pe, string strName, string strValue, PwDatabase pdContext, string strSeparator, bool bOnlyIfNotDup) { if (pe == null) { Debug.Assert(false); return; } if (string.IsNullOrEmpty(strName)) { Debug.Assert(false); return; } if (strValue == null) { Debug.Assert(false); strValue = string.Empty; } if (strSeparator == null) { if (PwDefs.IsStandardField(strName) && (strName != PwDefs.NotesField)) { strSeparator = ", "; } else { strSeparator = MessageService.NewLine; } } ProtectedString psPrev = pe.Strings.Get(strName); if ((psPrev == null) || psPrev.IsEmpty) { MemoryProtectionConfig mpc = ((pdContext != null) ? pdContext.MemoryProtection : new MemoryProtectionConfig()); bool bProtect = mpc.GetProtection(strName); pe.Strings.Set(strName, new ProtectedString(bProtect, strValue)); } else if (strValue.Length != 0) { bool bAppend = true; if (bOnlyIfNotDup) { ProtectedString psValue = new ProtectedString(false, strValue); bAppend = !psPrev.Equals(psValue, false); } if (bAppend) { pe.Strings.Set(strName, psPrev + (strSeparator + strValue)); } } }
private bool ValidateStringName() { string str = m_cmbStringName.Text; string strStart = (m_strStringName != null) ? m_strStringName : string.Empty; char[] vInvalidChars = new char[] { '{', '}' }; if (PwDefs.IsStandardField(str)) { m_lblValidationInfo.Text = KPRes.FieldNameInvalid; m_cmbStringName.BackColor = AppDefs.ColorEditError; m_btnOK.Enabled = false; return(false); } else if (str.Length <= 0) { m_lblValidationInfo.Text = KPRes.FieldNamePrompt; m_cmbStringName.ResetBackColor(); m_btnOK.Enabled = false; return(false); } else if (str.IndexOfAny(vInvalidChars) >= 0) { m_lblValidationInfo.Text = KPRes.FieldNameInvalid; m_cmbStringName.BackColor = AppDefs.ColorEditError; m_btnOK.Enabled = false; return(false); } else if (!strStart.Equals(str) && m_vStringDict.Exists(str)) { m_lblValidationInfo.Text = KPRes.FieldNameExistsAlready; m_cmbStringName.BackColor = AppDefs.ColorEditError; m_btnOK.Enabled = false; return(false); } else { m_lblValidationInfo.Text = string.Empty; m_cmbStringName.ResetBackColor(); m_btnOK.Enabled = true; } // See ValidateStringNameEx return(true); }
private static string FillEntryStrings(string str, SprContext ctx, uint uRecursionLevel) { List <string> vKeys = ctx.Entry.Strings.GetKeys(); // Ensure that all standard field names are in the list // (this is required in order to replace the standard placeholders // even if the corresponding standard field isn't present in // the entry) List <string> vStdNames = PwDefs.GetStandardFields(); foreach (string strStdField in vStdNames) { if (!vKeys.Contains(strStdField)) { vKeys.Add(strStdField); } } // Do not directly enumerate the strings in ctx.Entry.Strings, // because strings might change during the Spr compilation foreach (string strField in vKeys) { string strKey = (PwDefs.IsStandardField(strField) ? (@"{" + strField + @"}") : (@"{" + PwDefs.AutoTypeStringPrefix + strField + @"}")); if (!ctx.ForcePlainTextPasswords && strKey.Equals(@"{" + PwDefs.PasswordField + @"}", StrUtil.CaseIgnoreCmp) && Program.Config.MainWindow.IsColumnHidden(AceColumnType.Password)) { str = SprEngine.FillIfExists(str, strKey, new ProtectedString( false, PwDefs.HiddenPassword), ctx, uRecursionLevel); continue; } // Use GetSafe because the field doesn't necessarily exist // (might be a standard field that has been added above) str = SprEngine.FillIfExists(str, strKey, ctx.Entry.Strings.GetSafe( strField), ctx, uRecursionLevel); } return(str); }
public override bool IsVisible(string fieldKey) { if (fieldKey == EtmTemplateUuid) { return(false); } if (fieldKey == PwDefs.TitleField) { return(true); } if ((fieldKey.StartsWith("@") || (PwDefs.IsStandardField(fieldKey)))) { return(!String.IsNullOrEmpty(GetFieldValue(fieldKey)) || _templateEntry.Strings.Exists(EtmTitle + fieldKey)); } return(true); }
protected override void OnCellEditStarting(CellEditEventArgs e) { base.OnCellEditStarting(e); var rowObject = (RowObject)e.RowObject; // Disallow editing of standard field names if (e.Column == mFieldNames) { if (rowObject.FieldName != null && PwDefs.IsStandardField(rowObject.FieldName)) { e.Cancel = true; } } // Disallow editing of the insertion row value if (e.Column == mFieldValues && rowObject.IsInsertionRow) { e.Cancel = true; } }
protected override void DeleteFieldCommand(RowObject rowObject) { var isStandardField = PwDefs.IsStandardField(rowObject.FieldName); var entriesWithField = Entries.Where(entry => entry.Strings.Exists(rowObject.FieldName)).ToArray(); if (ConfirmOperationOnAllEntries(String.Format(Properties.Resources.MultipleEntryFieldDeleteQuestion, rowObject.DisplayName), KPRes.Delete, entriesWithField)) { var blankValue = new ProtectedString(rowObject.Value.IsProtected, new byte[0]); // ProtectedStrings are immutable, so OK to assign the same one to all entries var createBackups = AllowCreateHistoryNow; foreach (var entry in entriesWithField) { if (createBackups) { entry.CreateBackup(Database); } if (isStandardField) { entry.Strings.Set(rowObject.FieldName, blankValue); } else { entry.Strings.Remove(rowObject.FieldName); } } if (isStandardField) { rowObject.Value = blankValue; RefreshObject(rowObject); } else { RemoveObject(rowObject); } } OnModified(EventArgs.Empty); }
// Get all user defined strings internal static List <string> GetListEntriesUserStrings(PwGroup pwg) { List <string> strl = new List <string>(); // Add all known pwentry strings foreach (PwEntry pe in pwg.GetEntries(true)) { foreach (KeyValuePair <string, ProtectedString> pstr in pe.Strings) { if (!strl.Contains(pstr.Key)) { if (!PwDefs.IsStandardField(pstr.Key)) { strl.Add(pstr.Key); } } } } strl.Sort(); return(strl); }
/// <summary> /// Gets an ordered list of fields to search for the term /// </summary> /// <param name="entry"></param> /// <returns></returns> private IEnumerable <string> GetFieldsToSearch(PwEntry entry) { var fieldsToSearch = new List <String>((int)entry.Strings.UCount); if (mSearchTitle) { fieldsToSearch.Add(PwDefs.TitleField); } if (mSearchUserName) { fieldsToSearch.Add(PwDefs.UserNameField); } if (mSearchUrl) { fieldsToSearch.Add(PwDefs.UrlField); } if (mSearchNotes) { fieldsToSearch.Add(PwDefs.NotesField); } if (mSearchCustomFields) { foreach (var stringEntry in entry.Strings) { if (!stringEntry.Value.IsProtected && !PwDefs.IsStandardField(stringEntry.Key)) { fieldsToSearch.Add(stringEntry.Key); } } } if (mSearchTags) { fieldsToSearch.Add(AutoTypeSearchExt.TagsVirtualFieldName); } return(fieldsToSearch); }
private static StandardField?GetField(string fieldName) { switch (fieldName) { case PwDefs.TitleField: return(StandardField.Title); case PwDefs.UserNameField: return(StandardField.UserName); case PwDefs.PasswordField: return(StandardField.Password); case PwDefs.UrlField: return(StandardField.Url); case PwDefs.NotesField: return(StandardField.Notes); default: System.Diagnostics.Debug.Assert(!PwDefs.IsStandardField(fieldName)); return(null); } }
protected override void ValidateFieldName(CellEditEventArgs e, string newValue) { base.ValidateFieldName(e, newValue); if (PwDefs.IsStandardField(newValue)) { // Allow if the standard field on the entry is currently blank and hidden if (mOptions.HideEmptyFields && Entry.Strings.GetSafe(newValue).IsEmpty) { return; } ReportValidationFailure(e.Control, KPRes.FieldNameInvalid); e.Cancel = true; return; } if (Entry.Strings.Exists(newValue)) { ReportValidationFailure(e.Control, KPRes.FieldNameExistsAlready); e.Cancel = true; return; } }
private static void ImportFields(JsonObject[] vFields, PwEntry pe, PwDatabase pd) { foreach (JsonObject jo in vFields) { if (jo == null) { Debug.Assert(false); continue; } string strName = jo.GetValue <string>("name"); string strValue = jo.GetValue <string>("value"); long lType = jo.GetValue <long>("type", 0); if (!string.IsNullOrEmpty(strName)) { ImportUtil.AppendToField(pe, strName, strValue, pd); if ((lType == 1) && !PwDefs.IsStandardField(strName)) { ProtectedString ps = pe.Strings.Get(strName); if (ps == null) { Debug.Assert(false); } else { pe.Strings.Set(strName, ps.WithProtection(true)); } } } else { Debug.Assert(false); } } }
private static void ExportCustomStrings(PwEntry peSource, ref string strNotes) { bool bSep = false; foreach (KeyValuePair <string, ProtectedString> kvp in peSource.Strings) { if (PwDefs.IsStandardField(kvp.Key)) { continue; } if (!bSep) { if (strNotes.Length > 0) { strNotes += MessageService.NewParagraph; } bSep = true; } strNotes += kvp.Key + ": " + kvp.Value.ReadString() + MessageService.NewLine; } }
private void PopulateExtraStrings() { ViewGroup extraGroup = (ViewGroup)FindViewById(Resource.Id.extra_strings); bool hasExtras = false; IEditMode editMode = new DefaultEdit(); if (KpEntryTemplatedEdit.IsTemplated(App.Kp2a.GetDb(), this.Entry)) { editMode = new KpEntryTemplatedEdit(App.Kp2a.GetDb(), this.Entry); } foreach (var key in editMode.SortExtraFieldKeys(Entry.Strings.GetKeys().Where(key => !PwDefs.IsStandardField(key)))) { if (editMode.IsVisible(key)) { hasExtras = true; var value = Entry.Strings.Get(key); var stringView = CreateExtraSection(key, value.ReadString(), value.IsProtected); extraGroup.AddView(stringView.View); } } FindViewById(Resource.Id.extra_strings_container).Visibility = hasExtras ? ViewStates.Visible : ViewStates.Gone; }
private void FillColumnsList(object state) { List <AceColumn> l = new List <AceColumn>(); AddStdAceColumn(l, AceColumnType.Title); AddStdAceColumn(l, AceColumnType.UserName); AddStdAceColumn(l, AceColumnType.Password); AddStdAceColumn(l, AceColumnType.Url); AddStdAceColumn(l, AceColumnType.Notes); AddStdAceColumn(l, AceColumnType.CreationTime); AddStdAceColumn(l, AceColumnType.LastAccessTime); AddStdAceColumn(l, AceColumnType.LastModificationTime); AddStdAceColumn(l, AceColumnType.ExpiryTime); AddStdAceColumn(l, AceColumnType.Uuid); AddStdAceColumn(l, AceColumnType.Attachment); List <string> vCustomNames = new List <string>(); List <AceColumn> lCur = Program.Config.MainWindow.EntryListColumns; foreach (AceColumn cCur in lCur) { if ((cCur.Type == AceColumnType.CustomString) && !vCustomNames.Contains(cCur.CustomName)) { vCustomNames.Add(cCur.CustomName); AddAceColumn(l, new AceColumn(AceColumnType.CustomString, cCur.CustomName, cCur.HideWithAsterisks, cCur.Width)); } } foreach (PwDocument pwDoc in Program.MainForm.DocumentManager.Documents) { if (string.IsNullOrEmpty(pwDoc.LockedIoc.Path) && pwDoc.Database.IsOpen) { EntryHandler eh = delegate(PwEntry pe) { foreach (KeyValuePair <string, ProtectedString> kvp in pe.Strings) { if (PwDefs.IsStandardField(kvp.Key)) { continue; } if (vCustomNames.Contains(kvp.Key)) { continue; } vCustomNames.Add(kvp.Key); AddAceColumn(l, new AceColumn(AceColumnType.CustomString, kvp.Key, kvp.Value.IsProtected, -1)); } return(true); }; pwDoc.Database.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } } string[] vPlgExtNames = Program.ColumnProviderPool.GetColumnNames(); foreach (string strPlgName in vPlgExtNames) { bool bHide = false; int nWidth = -1; foreach (AceColumn cCur in lCur) { if ((cCur.Type == AceColumnType.PluginExt) && (cCur.CustomName == strPlgName)) { bHide = cCur.HideWithAsterisks; nWidth = cCur.Width; break; } } AddAceColumn(l, new AceColumn(AceColumnType.PluginExt, strPlgName, bHide, nWidth)); } AddStdAceColumn(l, AceColumnType.Size); AddStdAceColumn(l, AceColumnType.HistoryCount); AddStdAceColumn(l, AceColumnType.OverrideUrl); AddStdAceColumn(l, AceColumnType.Tags); AddStdAceColumn(l, AceColumnType.ExpiryTimeDateOnly); // m_lvColumns.Invoke(new UpdateUIDelegate(UpdateListEx), false); }
void UpdateEntryFromUi(PwEntry entry) { Database db = App.Kp2a.GetDb(); EntryEditActivity act = this; entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle, Util.GetEditText(act, Resource.Id.entry_title))); entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName, Util.GetEditText(act, Resource.Id.entry_user_name))); String pass = Util.GetEditText(act, Resource.Id.entry_password); byte[] password = StrUtil.Utf8.GetBytes(pass); entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword, password)); MemUtil.ZeroByteArray(password); entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl, Util.GetEditText(act, Resource.Id.entry_url))); entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes, Util.GetEditText(act, Resource.Id.entry_comment))); // Validate expiry date DateTime newExpiry = new DateTime(); if ((State.Entry.Expires) && (!DateTime.TryParse(Util.GetEditText(this, Resource.Id.entry_expires), out newExpiry))) { //ignore here } else { State.Entry.ExpiryTime = newExpiry; } // Delete all non standard strings var keys = entry.Strings.GetKeys(); foreach (String key in keys) { if (PwDefs.IsStandardField(key) == false) { entry.Strings.Remove(key); } } LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container); for (int index = 0; index < container.ChildCount; index++) { View view = container.GetChildAt(index); TextView keyView = (TextView)view.FindViewById(Resource.Id.title); String key = keyView.Text; if (String.IsNullOrEmpty(key)) { continue; } TextView valueView = (TextView)view.FindViewById(Resource.Id.value); String value = valueView.Text; bool protect = ((CheckBox)view.FindViewById(Resource.Id.protection)).Checked; entry.Strings.Set(key, new ProtectedString(protect, value)); } entry.OverrideUrl = Util.GetEditText(this, Resource.Id.entry_override_url); List <string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this, Resource.Id.entry_tags)); entry.Tags.Clear(); foreach (string strTag in vNewTags) { entry.AddTag(strTag); } /*KPDesktop * * * m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked; * m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ? * AutoTypeObfuscationOptions.UseClipboard : * AutoTypeObfuscationOptions.None); * * SaveDefaultSeq(); * * newEntry.AutoType = m_atConfig; */ }
private void FillColumnsList(object state) { List <AceColumn> l = new List <AceColumn>(); AddStdAceColumn(l, AceColumnType.Title); AddStdAceColumn(l, AceColumnType.UserName); AddStdAceColumn(l, AceColumnType.Password); AddStdAceColumn(l, AceColumnType.Url); AddStdAceColumn(l, AceColumnType.Notes); AddStdAceColumn(l, AceColumnType.CreationTime); if ((Program.Config.UI.UIFlags & (ulong)AceUIFlags.ShowLastAccessTime) != 0) { AddStdAceColumn(l, AceColumnType.LastAccessTime); } AddStdAceColumn(l, AceColumnType.LastModificationTime); AddStdAceColumn(l, AceColumnType.ExpiryTime); AddStdAceColumn(l, AceColumnType.Uuid); AddStdAceColumn(l, AceColumnType.Attachment); SortedDictionary <string, AceColumn> d = new SortedDictionary <string, AceColumn>(StrUtil.CaseIgnoreComparer); List <AceColumn> lCur = Program.Config.MainWindow.EntryListColumns; foreach (AceColumn cCur in lCur) { if ((cCur.Type == AceColumnType.CustomString) && !d.ContainsKey(cCur.CustomName)) { d[cCur.CustomName] = new AceColumn(AceColumnType.CustomString, cCur.CustomName, cCur.HideWithAsterisks, cCur.Width); } } foreach (PwDocument pwDoc in Program.MainForm.DocumentManager.Documents) { if (string.IsNullOrEmpty(pwDoc.LockedIoc.Path) && pwDoc.Database.IsOpen) { EntryHandler eh = delegate(PwEntry pe) { foreach (KeyValuePair <string, ProtectedString> kvp in pe.Strings) { if (PwDefs.IsStandardField(kvp.Key)) { continue; } if (d.ContainsKey(kvp.Key)) { continue; } d[kvp.Key] = new AceColumn(AceColumnType.CustomString, kvp.Key, kvp.Value.IsProtected, -1); } return(true); }; pwDoc.Database.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } } foreach (KeyValuePair <string, AceColumn> kvpCustom in d) { AddAceColumn(l, kvpCustom.Value); } AddStdAceColumn(l, AceColumnType.Size); AddStdAceColumn(l, AceColumnType.AttachmentCount); AddStdAceColumn(l, AceColumnType.HistoryCount); AddStdAceColumn(l, AceColumnType.OverrideUrl); AddStdAceColumn(l, AceColumnType.Tags); AddStdAceColumn(l, AceColumnType.ExpiryTimeDateOnly); AddStdAceColumn(l, AceColumnType.LastPasswordModTime); d.Clear(); // Add active plugin columns (including those of uninstalled plugins) foreach (AceColumn cCur in lCur) { if (cCur.Type != AceColumnType.PluginExt) { continue; } if (d.ContainsKey(cCur.CustomName)) { Debug.Assert(false); continue; } d[cCur.CustomName] = new AceColumn(AceColumnType.PluginExt, cCur.CustomName, cCur.HideWithAsterisks, cCur.Width); } // Add unused plugin columns string[] vPlgExtNames = Program.ColumnProviderPool.GetColumnNames(); foreach (string strPlgName in vPlgExtNames) { if (d.ContainsKey(strPlgName)) { continue; // Do not overwrite } d[strPlgName] = new AceColumn(AceColumnType.PluginExt, strPlgName, false, -1); } foreach (KeyValuePair <string, AceColumn> kvpExt in d) { AddAceColumn(l, kvpExt.Value); } // m_lvColumns.Invoke(new UpdateUIDelegate(UpdateListEx), false); }
private void InitPlaceholdersBox() { const string VkcBreak = @"<break />"; string[] vSpecialKeyCodes = new string[] { "TAB", "ENTER", "UP", "DOWN", "LEFT", "RIGHT", "HOME", "END", "PGUP", "PGDN", "INSERT", "DELETE", "SPACE", VkcBreak, "BACKSPACE", "BREAK", "CAPSLOCK", "ESC", "WIN", "LWIN", "RWIN", "APPS", "HELP", "NUMLOCK", "PRTSC", "SCROLLLOCK", VkcBreak, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", VkcBreak, "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9" }; string[] vSpecialPlaceholders = new string[] { "GROUP", "GROUP_PATH", "GROUP_NOTES", "PASSWORD_ENC", "URL:RMVSCM", "URL:SCM", "URL:HOST", "URL:PORT", "URL:PATH", "URL:QUERY", "URL:USERINFO", "URL:USERNAME", "URL:PASSWORD", // "BASE", "T-REPLACE-RX:/T/S/R/", "T-CONV:/T/C/", "C:Comment", VkcBreak, "DELAY 1000", "DELAY=200", "VKEY 13", "VKEY-NX 13", "VKEY-EX 13", "PICKCHARS", "PICKCHARS:Password:C=3", "NEWPASSWORD", "NEWPASSWORD:/Profile/", "HMACOTP", "CLEARFIELD", "APPACTIVATE " + KPRes.Title, "BEEP 800 200", VkcBreak, "APPDIR", "DB_PATH", "DB_DIR", "DB_NAME", "DB_BASENAME", "DB_EXT", "ENV_DIRSEP", "ENV_PROGRAMFILES_X86", VkcBreak, // "INTERNETEXPLORER", "FIREFOX", "OPERA", "GOOGLECHROME", // "SAFARI", VkcBreak, "DT_SIMPLE", "DT_YEAR", "DT_MONTH", "DT_DAY", "DT_HOUR", "DT_MINUTE", "DT_SECOND", "DT_UTC_SIMPLE", "DT_UTC_YEAR", "DT_UTC_MONTH", "DT_UTC_DAY", "DT_UTC_HOUR", "DT_UTC_MINUTE", "DT_UTC_SECOND" }; RichTextBuilder rb = new RichTextBuilder(); rb.AppendLine(KPRes.StandardFields, FontStyle.Bold, null, null, ":", null); rb.Append("{" + PwDefs.TitleField + "} "); rb.Append("{" + PwDefs.UserNameField + "} "); rb.Append("{" + PwDefs.PasswordField + "} "); rb.Append("{" + PwDefs.UrlField + "} "); rb.Append("{" + PwDefs.NotesField + "}"); bool bCustomInitialized = false, bFirst = true; foreach (KeyValuePair <string, ProtectedString> kvp in m_vStringDict) { if (!PwDefs.IsStandardField(kvp.Key)) { if (bCustomInitialized == false) { rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.CustomFields, FontStyle.Bold, null, null, ":", null); bCustomInitialized = true; } if (!bFirst) { rb.Append(" "); } rb.Append("{" + PwDefs.AutoTypeStringPrefix + kvp.Key + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.KeyboardKeyModifiers, FontStyle.Bold, null, null, ":", null); rb.Append(KPRes.KeyboardKeyShift + @": +, "); rb.Append(KPRes.KeyboardKeyCtrl + @": ^, "); rb.Append(KPRes.KeyboardKeyAlt + @": %"); rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.SpecialKeys, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strNav in vSpecialKeyCodes) { if (strNav == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strNav + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.OtherPlaceholders, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strPH in vSpecialPlaceholders) { if (strPH == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strPH + "}"); bFirst = false; } } if (SprEngine.FilterPlaceholderHints.Count > 0) { rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.PluginProvided, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strP in SprEngine.FilterPlaceholderHints) { if (string.IsNullOrEmpty(strP)) { continue; } if (!bFirst) { rb.Append(" "); } rb.Append(strP); bFirst = false; } } rb.Build(m_rtbPlaceholders); LinkifyRtf(m_rtbPlaceholders); }
public override void Import(PwDatabase pwStorage, Stream sInput, IStatusLogger slLogger) { StreamReader sr = new StreamReader(sInput, Encoding.Unicode); string strData = sr.ReadToEnd(); sr.Close(); string[] vLines = strData.Split(new char[] { '\r', '\n' }); bool bDoImport = false; PwEntry pe = new PwEntry(true, true); bool bInnerSep = false; bool bEmptyEntry = true; string strLastIndexedItem = string.Empty; string strLastLine = string.Empty; foreach (string strLine in vLines) { if (strLine.Length == 0) { continue; } if (strLine == FieldSeparator) { bInnerSep = !bInnerSep; if (bInnerSep && !bEmptyEntry) { pwStorage.RootGroup.AddEntry(pe, true); pe = new PwEntry(true, true); bEmptyEntry = true; } else if (!bInnerSep) { pe.Strings.Set(PwDefs.TitleField, new ProtectedString( pwStorage.MemoryProtection.ProtectTitle, strLastLine)); } bDoImport = true; } else if (bDoImport) { int nIDLen = strLine.IndexOf(": "); if (nIDLen > 0) { string strIndex = strLine.Substring(0, nIDLen); if (PwDefs.IsStandardField(strIndex)) { strIndex = Guid.NewGuid().ToString(); } pe.Strings.Set(strIndex, new ProtectedString( false, strLine.Remove(0, nIDLen + 2))); strLastIndexedItem = strIndex; } else if (!bEmptyEntry) { pe.Strings.Set(strLastIndexedItem, new ProtectedString( false, pe.Strings.ReadSafe(strLastIndexedItem) + MessageService.NewParagraph + strLine)); } bEmptyEntry = false; } strLastLine = strLine; } }
public bool EqualsDictionary(ProtectedStringDictionary dict, PwCompareOptions pwOpt, MemProtCmpMode mpCompare) { if (dict == null) { Debug.Assert(false); return(false); } bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) != PwCompareOptions.None); if (!bNeEqStd) { if (m_vStrings.Count != dict.m_vStrings.Count) { return(false); } } foreach (KeyValuePair <string, ProtectedString> kvp in m_vStrings) { bool bStdField = PwDefs.IsStandardField(kvp.Key); ProtectedString ps = dict.Get(kvp.Key); if (bNeEqStd && (ps == null) && bStdField) { ps = ProtectedString.Empty; } if (ps == null) { return(false); } if (mpCompare == MemProtCmpMode.Full) { if (ps.IsProtected != kvp.Value.IsProtected) { return(false); } } else if (mpCompare == MemProtCmpMode.CustomOnly) { if (!bStdField && (ps.IsProtected != kvp.Value.IsProtected)) { return(false); } } if (!ps.Equals(kvp.Value, false)) { return(false); } } if (bNeEqStd) { foreach (KeyValuePair <string, ProtectedString> kvp in dict.m_vStrings) { ProtectedString ps = Get(kvp.Key); if (ps != null) { continue; // Compared previously } if (!PwDefs.IsStandardField(kvp.Key)) { return(false); } if (!kvp.Value.IsEmpty) { return(false); } } } return(true); }
private void FillData() { _editModeHiddenViews = new List <View>(); ImageButton currIconButton = (ImageButton)FindViewById(Resource.Id.icon_button); App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(currIconButton, this, App.Kp2a.GetDb().KpDatabase, State.Entry.IconId, State.Entry.CustomIconUuid, false); PopulateText(Resource.Id.entry_title, State.Entry.Strings.ReadSafe(PwDefs.TitleField)); PopulateText(Resource.Id.entry_user_name, State.Entry.Strings.ReadSafe(PwDefs.UserNameField)); PopulateText(Resource.Id.entry_url, State.Entry.Strings.ReadSafe(PwDefs.UrlField)); String password = State.Entry.Strings.ReadSafe(PwDefs.PasswordField); PopulateText(Resource.Id.entry_password, password); PopulateText(Resource.Id.entry_confpassword, password); PopulateText(Resource.Id.entry_comment, State.Entry.Strings.ReadSafe(PwDefs.NotesField)); LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container); foreach (var key in State.EditMode.SortExtraFieldKeys(State.Entry.Strings.Select(ps => ps.Key))) { if (!PwDefs.IsStandardField(key)) { RelativeLayout ees = CreateExtraStringView(new KeyValuePair <string, ProtectedString>(key, State.Entry.Strings.Get(key))); var isVisible = State.EditMode.IsVisible(key); ees.Visibility = isVisible ? ViewStates.Visible : ViewStates.Gone; if (!isVisible) { _editModeHiddenViews.Add(ees); } container.AddView(ees); } } PopulateBinaries(); if (App.Kp2a.GetDb().DatabaseFormat.SupportsOverrideUrl) { PopulateText(Resource.Id.entry_override_url, State.Entry.OverrideUrl); } else { FindViewById(Resource.Id.entry_override_url_container).Visibility = ViewStates.Gone; } if (App.Kp2a.GetDb().DatabaseFormat.SupportsTags) { PopulateText(Resource.Id.entry_tags, StrUtil.TagsToString(State.Entry.Tags, true)); } else { var view = FindViewById(Resource.Id.entry_tags_label); if (view != null) { view.Visibility = ViewStates.Gone; } FindViewById(Resource.Id.entry_tags).Visibility = ViewStates.Gone; } UpdateExpires(); List <KeyValuePair <string, int> > keyLayoutIds = new List <KeyValuePair <string, int> >() { new KeyValuePair <string, int>(PwDefs.TitleField, Resource.Id.title_section), new KeyValuePair <string, int>(PwDefs.UserNameField, Resource.Id.user_section), new KeyValuePair <string, int>(PwDefs.PasswordField, Resource.Id.password_section), new KeyValuePair <string, int>(PwDefs.UrlField, Resource.Id.url_section), new KeyValuePair <string, int>(PwDefs.NotesField, Resource.Id.comments_section), new KeyValuePair <string, int>(KeePass.TagsKey, Resource.Id.tags_section), new KeyValuePair <string, int>(KeePass.OverrideUrlKey, Resource.Id.entry_override_url_container), new KeyValuePair <string, int>(KeePass.ExpDateKey, Resource.Id.expires_section), }; foreach (var kvp in keyLayoutIds) { var isVisible = State.EditMode.IsVisible(kvp.Key); var field = FindViewById(kvp.Value); if (!isVisible) { _editModeHiddenViews.Add(field); } field.Visibility = isVisible ? ViewStates.Visible : ViewStates.Gone; } }