public static bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext, string strSeq) { if (pe == null) { Debug.Assert(false); return(false); } if (!pe.GetAutoTypeEnabled()) { return(false); } if (!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext)) { return(false); } Thread.Sleep(TargetActivationDelay); IntPtr hWnd; string strWindow; GetForegroundWindowInfo(out hWnd, out strWindow); if (!NativeLib.IsUnix()) { if (strWindow == null) { Debug.Assert(false); return(false); } } else { strWindow = string.Empty; } if (strSeq == null) { SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdContext, evQueries.EventID); GetSequencesForWindowEnd(evQueries); if (lSeq.Count == 0) { strSeq = pe.GetAutoTypeSequence(); } else { strSeq = lSeq[0]; } } AutoTypeCtx ctx = new AutoTypeCtx(strSeq, pe, pdContext); return(AutoType.PerformInternal(ctx, strWindow)); }
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 bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext) { if (pe == null) { Debug.Assert(false); return(false); } if (!pe.GetAutoTypeEnabled()) { return(false); } if (!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext)) { return(false); } IntPtr hWnd; string strWindow; try { NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch (Exception) { hWnd = IntPtr.Zero; strWindow = null; } if (!KeePassLib.Native.NativeLib.IsUnix()) { if (strWindow == null) { Debug.Assert(false); return(false); } } else { strWindow = string.Empty; } Thread.Sleep(100); SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdContext, evQueries.EventID); GetSequencesForWindowEnd(evQueries); if (lSeq.Count == 0) { lSeq.Add(pe.GetAutoTypeSequence()); } AutoTypeCtx ctx = new AutoTypeCtx(lSeq[0], pe, pdContext); return(AutoType.PerformInternal(ctx, strWindow)); }
private static string ConvertAutoTypeSeqExp(string strSeq, PwEntry pe) { string strExp = strSeq; if (string.IsNullOrEmpty(strExp)) { strExp = pe.GetAutoTypeSequence(); } return(ConvertAutoTypeSequence(strExp, false)); }
internal static string GetSequencesText(PwEntry pe) { if (pe == null) { Debug.Assert(false); return(string.Empty); } string strSeq = pe.GetAutoTypeSequence(); Debug.Assert(strSeq.Length != 0); string str = ((strSeq.Length != 0) ? strSeq : ("(" + KPRes.Empty + ")")); int cAssoc = pe.AutoType.AssociationsCount; if (cAssoc != 0) { Dictionary <string, bool> d = new Dictionary <string, bool>(); d[strSeq] = true; foreach (AutoTypeAssociation a in pe.AutoType.Associations) { string strAssocSeq = a.Sequence; if (strAssocSeq.Length != 0) { d[strAssocSeq] = true; } } int c = d.Count; str += ((c >= 2) ? (" " + KPRes.MoreAnd.Replace(@"{PARAM}", (c - 1).ToString())) : string.Empty) + " (" + cAssoc.ToString() + " " + KPRes.AssociationsLower + ")"; } return(str); }
// Multiple calls of this method are wrapped in // GetSequencesForWindowBegin and GetSequencesForWindowEnd private static List <string> GetSequencesForWindow(PwEntry pwe, IntPtr hWnd, string strWindow, PwDatabase pdContext, int iEventID) { List <string> l = new List <string>(); if (pwe == null) { Debug.Assert(false); return(l); } if (strWindow == null) { Debug.Assert(false); return(l); } // May be empty if (!pwe.GetAutoTypeEnabled()) { return(l); } SprContext sprCtx = new SprContext(pwe, pdContext, SprCompileFlags.NonActive); RaiseSequenceQueryEvent(AutoType.SequenceQueryPre, iEventID, hWnd, strWindow, pwe, pdContext, l); // Specifically defined sequences must match before the title, // in order to allow selecting the first item as default one foreach (AutoTypeAssociation a in pwe.AutoType.Associations) { string strWndSpec = a.WindowName; if (strWndSpec == null) { Debug.Assert(false); continue; } strWndSpec = SprEngine.Compile(strWndSpec.Trim(), sprCtx); if (MatchWindows(strWndSpec, strWindow)) { string strSeq = a.Sequence; if (string.IsNullOrEmpty(strSeq)) { strSeq = pwe.GetAutoTypeSequence(); } AddSequence(l, strSeq); } } RaiseSequenceQueryEvent(AutoType.SequenceQuery, iEventID, hWnd, strWindow, pwe, pdContext, l); if (Program.Config.Integration.AutoTypeMatchByTitle) { string strTitle = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.TitleField).Trim(), sprCtx); if ((strTitle.Length > 0) && (strWindow.IndexOf(strTitle, StrUtil.CaseIgnoreCmp) >= 0)) { AddSequence(l, pwe.GetAutoTypeSequence()); } } string strCmpUrl = null; // To cache compiled URL if (Program.Config.Integration.AutoTypeMatchByUrlInTitle) { strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.UrlField).Trim(), sprCtx); if ((strCmpUrl.Length > 0) && (strWindow.IndexOf(strCmpUrl, StrUtil.CaseIgnoreCmp) >= 0)) { AddSequence(l, pwe.GetAutoTypeSequence()); } } if (Program.Config.Integration.AutoTypeMatchByUrlHostInTitle) { if (strCmpUrl == null) { strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.UrlField).Trim(), sprCtx); } string strCleanUrl = StrUtil.RemovePlaceholders(strCmpUrl); string strHost = UrlUtil.GetHost(strCleanUrl); if (strHost.StartsWith("www.", StrUtil.CaseIgnoreCmp) && (strCleanUrl.StartsWith("http:", StrUtil.CaseIgnoreCmp) || strCleanUrl.StartsWith("https:", StrUtil.CaseIgnoreCmp))) { strHost = strHost.Substring(4); } if ((strHost.Length > 0) && (strWindow.IndexOf(strHost, StrUtil.CaseIgnoreCmp) >= 0)) { AddSequence(l, pwe.GetAutoTypeSequence()); } } if (Program.Config.Integration.AutoTypeMatchByTagInTitle) { foreach (string strTag in pwe.Tags) { if (string.IsNullOrEmpty(strTag)) { Debug.Assert(false); continue; } if (strWindow.IndexOf(strTag, StrUtil.CaseIgnoreCmp) >= 0) { AddSequence(l, pwe.GetAutoTypeSequence()); break; } } } RaiseSequenceQueryEvent(AutoType.SequenceQueryPost, iEventID, hWnd, strWindow, pwe, pdContext, l); return(l); }
public static bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext, string strSeq) { if(pe == null) { Debug.Assert(false); return false; } if(!pe.GetAutoTypeEnabled()) return false; if(!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext)) return false; IntPtr hWnd; string strWindow; try { NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch(Exception) { hWnd = IntPtr.Zero; strWindow = null; } if(!KeePassLib.Native.NativeLib.IsUnix()) { if(strWindow == null) { Debug.Assert(false); return false; } } else strWindow = string.Empty; Thread.Sleep(100); if(strSeq == null) { SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List<string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdContext, evQueries.EventID); GetSequencesForWindowEnd(evQueries); if(lSeq.Count == 0) strSeq = pe.GetAutoTypeSequence(); else strSeq = lSeq[0]; } AutoTypeCtx ctx = new AutoTypeCtx(strSeq, pe, pdContext); return AutoType.PerformInternal(ctx, strWindow); }
// Multiple calls of this method are wrapped in // GetSequencesForWindowBegin and GetSequencesForWindowEnd private static List<string> GetSequencesForWindow(PwEntry pwe, IntPtr hWnd, string strWindow, PwDatabase pdContext, int iEventID) { List<string> l = new List<string>(); if(pwe == null) { Debug.Assert(false); return l; } if(strWindow == null) { Debug.Assert(false); return l; } if(!pwe.GetAutoTypeEnabled()) return l; SprContext sprCtx = new SprContext(pwe, pdContext, SprCompileFlags.NonActive); RaiseSequenceQueryEvent(AutoType.SequenceQueryPre, iEventID, hWnd, strWindow, pwe, pdContext, l); // Specifically defined sequences must match before the title, // in order to allow selecting the first item as default one foreach(AutoTypeAssociation a in pwe.AutoType.Associations) { string strWndSpec = a.WindowName; if(strWndSpec == null) { Debug.Assert(false); continue; } strWndSpec = SprEngine.Compile(strWndSpec.Trim(), sprCtx); if(MatchWindows(strWndSpec, strWindow)) { string strSeq = a.Sequence; if(string.IsNullOrEmpty(strSeq)) strSeq = pwe.GetAutoTypeSequence(); AddSequence(l, strSeq); } } RaiseSequenceQueryEvent(AutoType.SequenceQuery, iEventID, hWnd, strWindow, pwe, pdContext, l); if(Program.Config.Integration.AutoTypeMatchByTitle) { string strTitle = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.TitleField).Trim(), sprCtx); if((strTitle.Length > 0) && (strWindow.IndexOf(strTitle, StrUtil.CaseIgnoreCmp) >= 0)) AddSequence(l, pwe.GetAutoTypeSequence()); } string strCmpUrl = null; // To cache compiled URL if(Program.Config.Integration.AutoTypeMatchByUrlInTitle) { strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.UrlField).Trim(), sprCtx); if((strCmpUrl.Length > 0) && (strWindow.IndexOf(strCmpUrl, StrUtil.CaseIgnoreCmp) >= 0)) AddSequence(l, pwe.GetAutoTypeSequence()); } if(Program.Config.Integration.AutoTypeMatchByUrlHostInTitle) { if(strCmpUrl == null) strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe( PwDefs.UrlField).Trim(), sprCtx); string strCleanUrl = StrUtil.RemovePlaceholders(strCmpUrl); string strHost = UrlUtil.GetHost(strCleanUrl); if(strHost.StartsWith("www.", StrUtil.CaseIgnoreCmp) && (strCleanUrl.StartsWith("http:", StrUtil.CaseIgnoreCmp) || strCleanUrl.StartsWith("https:", StrUtil.CaseIgnoreCmp))) strHost = strHost.Substring(4); if((strHost.Length > 0) && (strWindow.IndexOf(strHost, StrUtil.CaseIgnoreCmp) >= 0)) AddSequence(l, pwe.GetAutoTypeSequence()); } if(Program.Config.Integration.AutoTypeMatchByTagInTitle) { foreach(string strTag in pwe.Tags) { if(string.IsNullOrEmpty(strTag)) { Debug.Assert(false); continue; } if(strWindow.IndexOf(strTag, StrUtil.CaseIgnoreCmp) >= 0) { AddSequence(l, pwe.GetAutoTypeSequence()); break; } } } RaiseSequenceQueryEvent(AutoType.SequenceQueryPost, iEventID, hWnd, strWindow, pwe, pdContext, l); return l; }
private static string ConvertAutoTypeSeqExp(string strSeq, PwEntry pe) { string strExp = strSeq; if(string.IsNullOrEmpty(strExp)) strExp = pe.GetAutoTypeSequence(); return ConvertAutoTypeSequence(strExp, false); }
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(strWndSpec == null) { Debug.Assert(false); continue; } strWndSpec = strWndSpec.Trim(); if(strWndSpec.Length > 0) 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); strTitle = strTitle.Trim(); 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(); }
private static List<string> GetSequencesForWindow(PwEntry pwe, string strWindow, PwDatabase pdContext) { List<string> l = new List<string>(); if(pwe == null) { Debug.Assert(false); return l; } if(strWindow == null) { Debug.Assert(false); return l; } if(!pwe.GetAutoTypeEnabled()) return l; // Specifically defined sequences must match before the title, // in order to allow selecting the first item as default one foreach(AutoTypeAssociation a in pwe.AutoType.Associations) { string strWndSpec = a.WindowName; if(strWndSpec == null) { Debug.Assert(false); continue; } strWndSpec = strWndSpec.Trim(); if(strWndSpec.Length > 0) strWndSpec = SprEngine.Compile(strWndSpec, new SprContext( pwe, pdContext, SprCompileFlags.All)); if(MatchWindows(strWndSpec, strWindow)) { string strSeq = a.Sequence; if(string.IsNullOrEmpty(strSeq)) strSeq = pwe.GetAutoTypeSequence(); AddSequence(l, strSeq); } } if(Program.Config.Integration.AutoTypeMatchByTitle) { string strTitle = pwe.Strings.ReadSafe(PwDefs.TitleField); strTitle = strTitle.Trim(); if((strTitle.Length > 0) && (strWindow.IndexOf(strTitle, StrUtil.CaseIgnoreCmp) >= 0)) AddSequence(l, pwe.GetAutoTypeSequence()); } if(Program.Config.Integration.AutoTypeMatchByUrlInTitle) { string strUrl = pwe.Strings.ReadSafe(PwDefs.UrlField); strUrl = strUrl.Trim(); if((strUrl.Length > 0) && (strWindow.IndexOf(strUrl, StrUtil.CaseIgnoreCmp) >= 0)) AddSequence(l, pwe.GetAutoTypeSequence()); } return l; }
public static bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext) { if(pe == null) { Debug.Assert(false); return false; } if(!pe.GetAutoTypeEnabled()) return false; if(!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext)) return false; string strWindow; try { IntPtr hDummy; NativeMethods.GetForegroundWindowInfo(out hDummy, out strWindow, true); } catch(Exception) { strWindow = null; } if(!KeePassLib.Native.NativeLib.IsUnix()) { if(strWindow == null) { Debug.Assert(false); return false; } } else strWindow = string.Empty; Thread.Sleep(100); List<string> lSeq = GetSequencesForWindow(pe, strWindow, pdContext); if(lSeq.Count == 0) lSeq.Add(pe.GetAutoTypeSequence()); AutoTypeCtx ctx = new AutoTypeCtx(lSeq[0], pe, pdContext); return AutoType.PerformInternal(ctx, strWindow); }