protected override string GetDisplayValue(ProtectedString value, bool revealValues) { return(SprEngine.Compile(value.ReadString(), new SprContext(null, Database, SprCompileFlags.All) { ForcePlainTextPasswords = revealValues })); }
/// <summary> /// Helper method to get keepass entry property as string, following references /// </summary> /// <param name="entry">The keepass entry</param> /// <param name="field">The field</param> /// <returns>The dereferenced value for this field.</returns> private string GetKeepassEntryPropertyDereferenced(PwEntry entry, string field) { var value = this.GetKeepassEntryProperty(entry, field); this.ExecuteInGuiThread(new Action(() => { value = SprEngine.Compile(value, new SprContext(entry, this.host.Database, SprCompileFlags.All)); })); return(value); }
public static ProtectedString GetFieldWRef(PwEntry entry, PwDatabase sourceDb, string fieldName) { ProtectedString orgValue = entry.Strings.GetSafe(fieldName); byte[] orgValueByteArray = orgValue.ReadUtf8(); // Check if the protected string begins with the ref marker bool isRef = orgValueByteArray.Take(5).SequenceEqual(RefStringByteArray); MemUtil.ZeroByteArray(orgValueByteArray); if (!isRef) { // The protected string is not a ref -> return the protected string directly return(orgValue); } SprContext ctx = new SprContext(entry, sourceDb, SprCompileFlags.All, false, false); // the protected string is a reference -> decode it and look it up return(new ProtectedString(true, SprEngine.Compile( orgValue.ReadString(), ctx))); }
public static string GetCacheRoot() { if (Program.Config.Application.PluginCachePath.Length > 0) { string strRoot = SprEngine.Compile(Program.Config.Application.PluginCachePath, null); if (!string.IsNullOrEmpty(strRoot)) { if (strRoot.EndsWith(new string(Path.DirectorySeparatorChar, 1))) { strRoot = strRoot.Substring(0, strRoot.Length - 1); } return(strRoot); } } string strDataDir = AppConfigSerializer.LocalAppDataDirectory; // try // { // DirectoryInfo diAppData = new DirectoryInfo(strDataDir); // DirectoryInfo diRoot = diAppData.Root; // DriveInfo di = new DriveInfo(diRoot.FullName); // if(di.DriveType == DriveType.Network) // { // strDataDir = UrlUtil.EnsureTerminatingSeparator( // UrlUtil.GetTempPath(), false); // strDataDir = strDataDir.Substring(0, strDataDir.Length - 1); // } // } // catch(Exception) { Debug.Assert(false); } return(strDataDir + Path.DirectorySeparatorChar + CacheDirName); }
internal static string SprCompileFn(string strText, PwListItem li) { string strCmp = null; while (strCmp == null) { try { strCmp = SprEngine.Compile(strText, MainForm.GetEntryListSprContext( li.Entry, Program.MainForm.DocumentManager.SafeFindContainerOf( li.Entry))); } catch (InvalidOperationException) { } // Probably collection changed catch (NullReferenceException) { } // Objects disposed already catch (Exception) { Debug.Assert(false); } } if (strCmp == strText) { return(strText); } return(Program.Config.MainWindow.EntryListShowDerefDataAndRefs ? (strCmp + " - " + strText) : strCmp); }
public override string GetCellData(string strColumnName, PwEntry pe) { if (strColumnName == null) { Debug.Assert(false); return(string.Empty); } if (strColumnName != Globals.COLUMN_NAME) { return(string.Empty); } if (pe == null) { Debug.Assert(false); return(string.Empty); } string strPw = pe.Strings.ReadSafe(PwDefs.PasswordField); if (strPw.IndexOf('{') >= 0) { IPluginHost host = ColoredQualityColumnExt.Host; if (host == null) { Debug.Assert(false); return(string.Empty); } PwDatabase pd = null; try { pd = host.MainWindow.DocumentManager.SafeFindContainerOf(pe); } catch (Exception) { Debug.Assert(false); } SprContext ctx = new SprContext(pe, pd, (SprCompileFlags.Deref | SprCompileFlags.TextTransforms), false, false); strPw = SprEngine.Compile(strPw, ctx); } uint uEst; lock (m_oCacheSync) { if (!m_dCache.TryGetValue(strPw, out uEst)) { uEst = uint.MaxValue; } } if (uEst == uint.MaxValue) { uEst = QualityEstimation.EstimatePasswordBits(strPw.ToCharArray()); lock (m_oCacheSync) { // Store quality estimation in cache. m_dCache[strPw] = uEst; } } return(uEst.ToString() + " bits"); }
internal static string SprCompileFn(string strText, PwListItem li) { if (string.IsNullOrEmpty(strText)) { return(string.Empty); } string str = null; while (str == null) { try { SprContext ctx = MainForm.GetEntryListSprContext(li.Entry, Program.MainForm.DocumentManager.SafeFindContainerOf( li.Entry)); str = SprEngine.Compile(strText, ctx); } catch (InvalidOperationException) { } // Probably collection changed catch (NullReferenceException) { } // Objects disposed already catch (Exception) { Debug.Assert(false); } } if (Program.Config.MainWindow.EntryListShowDerefDataAndRefs && (str != strText)) { str += " - " + strText; } return(StrUtil.MultiToSingleLine(str)); }
internal string[] GetUserPass(PwEntryDatabase entryDatabase) { // follow references SprContext ctx = new SprContext(entryDatabase.entry, entryDatabase.database, SprCompileFlags.All, false, false); string user = SprEngine.Compile( entryDatabase.entry.Strings.ReadSafe(PwDefs.UserNameField), ctx); string pass = SprEngine.Compile( entryDatabase.entry.Strings.ReadSafe(PwDefs.PasswordField), ctx); var f = (MethodInvoker) delegate { // apparently, SprEngine.Compile might modify the database host.MainWindow.UpdateUI(false, null, false, null, false, null, false); }; if (host.MainWindow.InvokeRequired) { host.MainWindow.Invoke(f); } else { f.Invoke(); } return(new string[] { user, pass }); }
public static bool Copy(string strToCopy, bool bIsEntryInfo, PwEntry peEntryInfo, PwDatabase pwReferenceSource) { Debug.Assert(strToCopy != null); if (strToCopy == null) { throw new ArgumentNullException("strToCopy"); } if (bIsEntryInfo && !AppPolicy.Try(AppPolicyId.CopyToClipboard)) { return(false); } string strData = SprEngine.Compile(strToCopy, false, peEntryInfo, pwReferenceSource, false, false); try { Clipboard.Clear(); DataObject doData = CreateProtectedDataObject(strData); Clipboard.SetDataObject(doData); m_pbDataHash32 = HashClipboard(); m_strFormat = null; } catch (Exception) { Debug.Assert(false); return(false); } return(true); }
private static string ReplacePickPlaceholder(string str, string strPlaceholder, PwEntry pe, PwDatabase pd, SprContentFlags cf, uint uCharCount) { if (str.IndexOf(strPlaceholder, StrUtil.CaseIgnoreCmp) < 0) { return(str); } ProtectedString ps = pe.Strings.Get(PwDefs.PasswordField); if (ps != null) { string strPassword = ps.ReadString(); string strPick = SprEngine.Compile(strPassword, false, pe, pd, false, false); // Do not transform content yet if (!string.IsNullOrEmpty(strPick)) { ProtectedString psPick = new ProtectedString(false, strPick); CharPickerForm dlg = new CharPickerForm(); dlg.InitEx(psPick, true, true, uCharCount); if (dlg.ShowDialog() == DialogResult.OK) { str = StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, SprEngine.TransformContent(dlg.SelectedCharacters.ReadString(), cf)); } } } return(StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, string.Empty)); }
private static void RunBuildCommand(string strCmd, string strTmpDir, string strCacheDir) { if (string.IsNullOrEmpty(strCmd)) { return; // No assert } string str = strCmd; if (strTmpDir != null) { str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_TEMP_DIR}", SprEncoding.EncodeForCommandLine(strTmpDir)); } if (strCacheDir != null) { str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_CACHE_DIR}", SprEncoding.EncodeForCommandLine(strCacheDir)); } // str = UrlUtil.ConvertSeparators(str); // Would convert args str = SprEngine.Compile(str, new SprContext(null, null, SprCompileFlags.NonActive, false, true)); string strApp, strArgs; StrUtil.SplitCommandLine(str, out strApp, out strArgs, true); Process p = null; try { if (!string.IsNullOrEmpty(strArgs)) { p = Process.Start(strApp, strArgs); } else { p = Process.Start(strApp); } } catch (Exception ex) { if (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null) { throw new PlgxException(ex.Message); } throw; } finally { try { if (p != null) { p.Dispose(); } } catch (Exception) { Debug.Assert(false); } } }
protected override string GetDisplayValue(ProtectedString value, bool revealValues) { System.Windows.Forms.MessageBox.Show("GetDisplayValue: " + System.Environment.StackTrace); return(SprEngine.Compile(value.ReadString(), new SprContext(Entry, Database, SprCompileFlags.All) { ForcePlainTextPasswords = revealValues })); }
private static string GetSequenceForWindow(PwEntry pwe, string strWindow, bool bRequireDefinedWindow) { Debug.Assert(strWindow != null); if (strWindow == null) { return(null); } Debug.Assert(pwe != null); if (pwe == null) { return(null); } if (!pwe.GetAutoTypeEnabled()) { return(null); } string strSeq = null; foreach (KeyValuePair <string, string> kvp in pwe.AutoType.WindowSequencePairs) { string strWndSpec = kvp.Key; if (!string.IsNullOrEmpty(strWndSpec)) { strWndSpec = SprEngine.Compile(strWndSpec, false, pwe, null, false, false); } if (MatchWindows(strWndSpec, strWindow)) { strSeq = kvp.Value; break; } } if (Program.Config.Integration.AutoTypeMatchByTitle) { string strTitle = pwe.Strings.ReadSafe(PwDefs.TitleField); if (string.IsNullOrEmpty(strSeq) && (strTitle.Length > 0) && (strWindow.IndexOf(strTitle, StrUtil.CaseIgnoreCmp) >= 0)) { strSeq = pwe.AutoType.DefaultSequence; Debug.Assert(strSeq != null); } } if ((strSeq == null) && bRequireDefinedWindow) { return(null); } if (!string.IsNullOrEmpty(strSeq)) { return(strSeq); } return(pwe.GetAutoTypeSequence()); }
public static ISshKey GetSshKey(this EntrySettings settings, ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries, SprContext sprContext) { if (!settings.AllowUseOfSshKey) { return(null); } KeyFormatter.GetPassphraseCallback getPassphraseCallback = delegate(string comment) { var securePassphrase = new SecureString(); var passphrase = SprEngine.Compile(strings.ReadSafe( PwDefs.PasswordField), sprContext); foreach (var c in passphrase) { securePassphrase.AppendChar(c); } return(securePassphrase); }; Func <Stream> getPrivateKeyStream; Func <Stream> getPublicKeyStream = null; switch (settings.Location.SelectedType) { case EntrySettings.LocationType.Attachment: if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) { throw new NoAttachmentException(); } var privateKeyData = binaries.Get(settings.Location.AttachmentName); var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub"); getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData()); if (publicKeyData != null) { getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData()); } return(GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback)); case EntrySettings.LocationType.File: var filename = settings.Location.FileName.ExpandEnvironmentVariables(); getPrivateKeyStream = () => File.OpenRead(filename); var publicKeyFile = filename + ".pub"; if (File.Exists(publicKeyFile)) { getPublicKeyStream = () => File.OpenRead(publicKeyFile); } return(GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback)); default: return(null); } }
internal static ProtectedString GenerateAcceptable(PwProfile prf, byte[] pbUserEntropy, PwEntry peOptCtx, PwDatabase pdOptCtx, ref bool bAcceptAlways) { ProtectedString ps = ProtectedString.Empty; SprContext ctx = new SprContext(peOptCtx, pdOptCtx, SprCompileFlags.NonActive, false, false); bool bAcceptable = false; while (!bAcceptable) { bAcceptable = true; PwGenerator.Generate(out ps, prf, pbUserEntropy, Program.PwGeneratorPool); if (ps == null) { Debug.Assert(false); ps = ProtectedString.Empty; } if (bAcceptAlways) { } else { string str = ps.ReadString(); string strCmp = SprEngine.Compile(str, ctx); if (str != strCmp) { if (prf.GeneratorType == PasswordGeneratorType.CharSet) { bAcceptable = false; // Silently try again } else { string strText = str + StrUtil.NewParagraph + KPRes.GenPwSprVariant + StrUtil.NewParagraph + KPRes.GenPwAccept; if (!MessageService.AskYesNo(strText, null, false)) { bAcceptable = false; } else { bAcceptAlways = true; } } } } } return(ps); }
private void Lv_DrawItem(object sender, DrawListViewItemEventArgs e) { if (_highlightsOn) { ListViewItem lvi = e.Item; PwListItem li = (lvi.Tag as PwListItem); if (li == null) { Debug.Assert(false); return; } PwEntry pe = li.Entry; if (pe == null) { Debug.Assert(false); return; } ProtectedString pStr = pe.Strings.Get(PwDefs.PasswordField); if (pStr == null) { Debug.Assert(false); return; } string pw = pStr.ReadString(); if (pw.IndexOf('{') >= 0) { //It is a reference to another entry. PwDatabase pd = null; try { pd = _host.MainWindow.DocumentManager.SafeFindContainerOf(pe); } catch (Exception) { Debug.Assert(false); } SprContext context = new SprContext(pe, pd, (SprCompileFlags.Deref | SprCompileFlags.TextTransforms), false, false); pw = SprEngine.Compile(pw, context); } uint bits = QualityEstimation.EstimatePasswordBits(pw.ToCharArray()); foreach (KeyValuePair <uint, Color> kvp in QualityDelimiter) { if (bits <= kvp.Key) { lvi.BackColor = kvp.Value; break; } } } e.DrawDefault = true; }
private static IEnumerable <KeyValuePair <string, string> > GetFields(ConfigOpt configOpt, PwEntryDatabase entryDatabase) { SprContext ctx = new SprContext(entryDatabase.entry, entryDatabase.database, SprCompileFlags.All, false, false); List <KeyValuePair <string, string> > fields = null; if (configOpt.ReturnStringFields) { fields = new List <KeyValuePair <string, string> >(); foreach (var sf in entryDatabase.entry.Strings) { var sfValue = entryDatabase.entry.Strings.ReadSafe(sf.Key); // follow references sfValue = SprEngine.Compile(sfValue, ctx); // KeeOtp support through keepassxc-browser // KeeOtp stores the TOTP config in a string field "otp" and provides a placeholder "{TOTP}" // KeeTrayTOTP uses by default a "TOTP Seed" string field, and the {TOTP} placeholder. // keepassxc-browser needs the value in a string field named "KPH: {TOTP}" if (sf.Key == "otp" || sf.Key.Equals("TOTP Seed", StringComparison.InvariantCultureIgnoreCase)) { fields.Add(new KeyValuePair <string, string>("KPH: {TOTP}", SprEngine.Compile("{TOTP}", ctx))); } else if (configOpt.ReturnStringFieldsWithKphOnly) { if (sf.Key.StartsWith("KPH: ")) { fields.Add(new KeyValuePair <string, string>(sf.Key.Substring(5), sfValue)); } } else { fields.Add(new KeyValuePair <string, string>(sf.Key, sfValue)); } } if (fields.Count > 0) { var sorted = from e2 in fields orderby e2.Key ascending select e2; fields = sorted.ToList(); } else { fields = null; } } return(fields); }
private ResponseEntry PrepareElementForResponseEntries(ConfigOpt configOpt, PwEntryDatabase entryDatabase) { SprContext ctx = new SprContext(entryDatabase.entry, entryDatabase.database, SprCompileFlags.All, false, false); var name = entryDatabase.entry.Strings.ReadSafe(PwDefs.TitleField); var loginpass = GetUserPass(entryDatabase, ctx); var login = loginpass[0]; var passwd = loginpass[1]; var uuid = entryDatabase.entry.Uuid.ToHexString(); var group = new ResponseGroupField(entryDatabase.entry.ParentGroup.GetFullPath("/", true), entryDatabase.entry.ParentGroup.Uuid.ToHexString()); List <ResponseStringField> fields = null; if (configOpt.ReturnStringFields) { fields = new List <ResponseStringField>(); foreach (var sf in entryDatabase.entry.Strings) { var sfValue = entryDatabase.entry.Strings.ReadSafe(sf.Key); // follow references sfValue = SprEngine.Compile(sfValue, ctx); if (configOpt.ReturnStringFieldsWithKphOnly) { if (sf.Key.StartsWith("KPH: ")) { fields.Add(new ResponseStringField(sf.Key.Substring(5), sfValue)); } } else { fields.Add(new ResponseStringField(sf.Key, sfValue)); } } if (fields.Count > 0) { var fields2 = from e2 in fields orderby e2.Key ascending select e2; fields = fields2.ToList <ResponseStringField>(); } else { fields = null; } } return(new ResponseEntry(name, login, passwd, uuid, group, fields, IsEntryRecycled(entryDatabase.entry))); }
private static bool Execute(string strSeq, PwEntry pweData) { Debug.Assert(strSeq != null); if (strSeq == null) { return(false); } Debug.Assert(pweData != null); if (pweData == null) { return(false); } if (!pweData.AutoType.Enabled) { return(false); } if (!AppPolicy.Try(AppPolicyId.AutoType)) { return(false); } PwDatabase pwDatabase = null; try { pwDatabase = Program.MainForm.PluginHost.Database; } catch (Exception) { pwDatabase = null; } string strSend = SprEngine.Compile(strSeq, true, pweData, pwDatabase, true, false); string strError = ValidateAutoTypeSequence(strSend); if (strError != null) { MessageService.ShowWarning(strError); return(false); } bool bObfuscate = (pweData.AutoType.ObfuscationOptions != AutoTypeObfuscationOptions.None); Application.DoEvents(); try { SendInputEx.SendKeysWait(strSend, bObfuscate); } catch (Exception excpAT) { MessageService.ShowWarning(excpAT); } return(true); }
internal static string CompileUrl(string strUrlToOpen, PwEntry pe, bool bAllowOverride, string strBaseRaw, bool?obForceEncCmd) { MainForm mf = Program.MainForm; PwDatabase pd = null; try { if (mf != null) { pd = mf.DocumentManager.SafeFindContainerOf(pe); } } catch (Exception) { Debug.Assert(false); } string strUrlFlt = strUrlToOpen; strUrlFlt = strUrlFlt.TrimStart(new char[] { ' ', '\t', '\r', '\n' }); bool bEncCmd = (obForceEncCmd.HasValue ? obForceEncCmd.Value : WinUtil.IsCommandLineUrl(strUrlFlt)); SprContext ctx = new SprContext(pe, pd, SprCompileFlags.All, false, bEncCmd); ctx.Base = strBaseRaw; ctx.BaseIsEncoded = false; string strUrl = SprEngine.Compile(strUrlFlt, ctx); string strOvr = Program.Config.Integration.UrlSchemeOverrides.GetOverrideForUrl( strUrl); if (!bAllowOverride) { strOvr = null; } if (strOvr != null) { bool bEncCmdOvr = WinUtil.IsCommandLineUrl(strOvr); SprContext ctxOvr = new SprContext(pe, pd, SprCompileFlags.All, false, bEncCmdOvr); ctxOvr.Base = strUrl; ctxOvr.BaseIsEncoded = bEncCmd; strUrl = SprEngine.Compile(strOvr, ctxOvr); } return(strUrl); }
/** * Replaces all placeholders with keepass compiling engine and replace os environment variables */ protected String fillPlaceholders(String applicationOptions) { String resolvedPathOrOptions = String.Empty; //Resolv keepass variables Boolean encodeAsAutoType = false; Boolean encodeQuotesForCommandline = true; SprCompileFlags compileFlags = SprCompileFlags.All; // Which placeholders should be replaced SprContext replaceContext = new SprContext(this.keepassEntry, this.keepassDatabase, compileFlags, encodeAsAutoType, encodeQuotesForCommandline); resolvedPathOrOptions = SprEngine.Compile(applicationOptions, replaceContext); //Resolv OS variables resolvedPathOrOptions = Environment.ExpandEnvironmentVariables(resolvedPathOrOptions); return(resolvedPathOrOptions); }
public static string GetFieldWRefUnprotected(PwEntry entry, PwDatabase sourceDb, string fieldName) { string orgValue = entry.Strings.ReadSafe(fieldName); // Check if the string begins with the ref marker or contains a % if (!orgValue.StartsWith("{REF") && !orgValue.Contains("%")) { // The string is not a ref -> return the string directly return(orgValue); } SprContext ctx = new SprContext(entry, sourceDb, SprCompileFlags.All, false, false); // the string is a reference -> decode it and look it up return(SprEngine.Compile(orgValue, ctx)); }
private static void RunBuildCommand(string strCmd, string strTmpDir, string strCacheDir) { if (string.IsNullOrEmpty(strCmd)) { return; // No assert } string str = strCmd; if (strTmpDir != null) { str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_TEMP_DIR}", strTmpDir); } if (strCacheDir != null) { str = StrUtil.ReplaceCaseInsensitive(str, @"{PLGX_CACHE_DIR}", strCacheDir); } // str = UrlUtil.ConvertSeparators(str); str = SprEngine.Compile(str, null); string strApp, strArgs; StrUtil.SplitCommandLine(str, out strApp, out strArgs); try { if ((strArgs != null) && (strArgs.Length > 0)) { Process.Start(strApp, strArgs); } else { Process.Start(strApp); } } catch (Exception exRun) { if (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null) { throw new PlgxException(exRun.Message); } throw; } }
private string GetPasswordSHA() { using (var sha1 = new SHA1CryptoServiceProvider()) { var context = new SprContext(PasswordEntry, Host.Database, SprCompileFlags.All); var password = SprEngine.Compile(PasswordEntry.Strings.GetSafe(PwDefs.PasswordField).ReadString(), context); var pwdShaBytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(password)); var sb = new StringBuilder(2 * pwdShaBytes.Length); foreach (var b in pwdShaBytes) { sb.AppendFormat("{0:X2}", b); } return(sb.ToString()); } }
private static object GetStringEntry(string key, PwDatabase db, PwEntry entry, bool asUnprotectedStrings, bool resolveReferencedFields) { var keyEntry = entry.Strings.Get(key); if (keyEntry.IsProtected && !asUnprotectedStrings) { return(keyEntry.ToSecureString()); } var stringValue = keyEntry.ReadString(); if (resolveReferencedFields && stringValue.Contains("{REF:")) { return(SprEngine.Compile(stringValue, new SprContext(entry, db, SprCompileFlags.All))); } return(stringValue); }
public static string GetCacheRoot() { if (Program.Config.Application.PluginCachePath.Length > 0) { string strRoot = SprEngine.Compile(Program.Config.Application.PluginCachePath, false, null, null, false, false); if (!string.IsNullOrEmpty(strRoot)) { if (strRoot.EndsWith(new string(Path.DirectorySeparatorChar, 1))) { strRoot = strRoot.Substring(0, strRoot.Length - 1); } return(strRoot); } } return(AppConfigSerializer.AppDataDirectory + Path.DirectorySeparatorChar + CacheDirName); }
public static string GetParamString(List <string> vParams, int iIndex, bool bSprCompile, bool bSprForCommandLine) { string str = GetParamString(vParams, iIndex, string.Empty); if (bSprCompile && !string.IsNullOrEmpty(str)) { PwEntry pe = null; try { pe = Program.MainForm.GetSelectedEntry(false); } catch (Exception) { Debug.Assert(false); } PwDatabase pd = Program.MainForm.DocumentManager.SafeFindContainerOf(pe); str = SprEngine.Compile(str, new SprContext(pe, pd, SprCompileFlags.All, false, bSprForCommandLine)); } return(str); }
private IEnumerable <KeyValuePair <string, string> > GetFields(ConfigOpt configOpt, PwEntryDatabase entryDatabase) { SprContext ctx = new SprContext(entryDatabase.entry, entryDatabase.database, SprCompileFlags.All, false, false); List <KeyValuePair <string, string> > fields = null; if (configOpt.ReturnStringFields) { fields = new List <KeyValuePair <string, string> >(); foreach (var sf in entryDatabase.entry.Strings) { var sfValue = entryDatabase.entry.Strings.ReadSafe(sf.Key); // follow references sfValue = SprEngine.Compile(sfValue, ctx); if (configOpt.ReturnStringFieldsWithKphOnly) { if (sf.Key.StartsWith("KPH: ")) { fields.Add(new KeyValuePair <string, string>(sf.Key.Substring(5), sfValue)); } } else { fields.Add(new KeyValuePair <string, string>(sf.Key, sfValue)); } } if (fields.Count > 0) { var sorted = from e2 in fields orderby e2.Key ascending select e2; fields = sorted.ToList(); } else { fields = null; } } return(fields); }
public static string GetParamString(List <string> vParams, int iIndex, bool bSprCompile) { string str = GetParamString(vParams, iIndex, string.Empty); if (bSprCompile && !string.IsNullOrEmpty(str)) { PwDatabase pd = null; try { pd = Program.MainForm.ActiveDatabase; } catch (Exception) { Debug.Assert(false); } PwEntry pe = null; try { pe = Program.MainForm.GetSelectedEntry(false); } catch (Exception) { Debug.Assert(false); } str = SprEngine.Compile(str, false, pe, pd, false, false); } return(str); }
protected ToolStripMenuItem CreateMenuItemFromPwEntry(PwEntry entry, PwDatabase pwDatabase) { var context = new SprContext(entry, pwDatabase, SprCompileFlags.All, false, false); var entryTitle = entry.Strings.ReadSafe(PwDefs.TitleField); var entryUsername = SprEngine.Compile(entry.Strings.ReadSafe(PwDefs.UserNameField), context); string trayTitle = TrimMenuItemTitleIfNecessary(entryTitle, entryUsername); var validEntry = Plugin.TOTPEntryValidator.SettingsValidate(entry); var menuItem = new ToolStripMenuItem(trayTitle) { Tag = entry, Image = validEntry ? GetEntryImage(entry, pwDatabase) : Resources.TOTP_Error, Enabled = validEntry, }; menuItem.Click += OnNotifyMenuTOTPClick; return(menuItem); }