예제 #1
0
        public static bool PerformIntoPreviousWindow(Form fCurrent, PwEntry pe)
        {
            if ((pe != null) && !pe.GetAutoTypeEnabled())
            {
                return(false);
            }

            bool bTopMost = ((fCurrent != null) ? fCurrent.TopMost : false);

            if (bTopMost)
            {
                fCurrent.TopMost = false;
            }

            try
            {
                if (!NativeMethods.LoseFocus(fCurrent))
                {
                    Debug.Assert(false);
                }

                return(PerformIntoCurrentWindow(pe));
            }
            finally
            {
                if (bTopMost)
                {
                    fCurrent.TopMost = true;
                }
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
        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());
        }
예제 #4
0
        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));
        }
예제 #5
0
        private static void MenuAddEntry(PwDocument ds, ToolStripMenuItem tsmiContainer,
                                         PwEntry pe)
        {
            ToolStripMenuItem tsmiEntry = new ToolStripMenuItem();
            string            strTitle  = pe.Strings.ReadSafe(PwDefs.TitleField);
            string            strUser   = pe.Strings.ReadSafe(PwDefs.UserNameField);
            string            strText   = string.Empty;

            if ((strTitle.Length > 0) && (strUser.Length > 0))
            {
                strText = strTitle + ": " + strUser;
            }
            else if (strTitle.Length > 0)
            {
                strText = strTitle;
            }
            else if (strUser.Length > 0)
            {
                strText = strUser;
            }
            tsmiEntry.Text       = strText;
            tsmiEntry.ImageIndex = MenuGetImageIndex(ds, pe.IconId, pe.CustomIconUuid);
            tsmiContainer.DropDownItems.Add(tsmiEntry);

            ToolStripMenuItem tsmi;

            tsmi            = new ToolStripMenuItem(KPRes.AutoType);
            tsmi.ImageIndex = (int)PwIcon.Run;
            tsmi.Tag        = pe;
            tsmi.Click     += OnAutoType;
            tsmi.Enabled    = pe.GetAutoTypeEnabled();
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmiEntry.DropDownItems.Add(new ToolStripSeparator());

            tsmi            = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.UserName);
            tsmi.ImageIndex = (int)PwIcon.UserKey;
            tsmi.Tag        = pe;
            tsmi.Click     += OnCopyUserName;
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmi            = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.Password);
            tsmi.ImageIndex = (int)PwIcon.Key;
            tsmi.Tag        = pe;
            tsmi.Click     += OnCopyPassword;
            tsmiEntry.DropDownItems.Add(tsmi);
        }
예제 #6
0
        public static bool PerformIntoPreviousWindow(Form fCurrent, 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);
            }

            bool bTopMost = ((fCurrent != null) ? fCurrent.TopMost : false);

            if (bTopMost)
            {
                fCurrent.TopMost = false;
            }

            try
            {
                if (!NativeMethods.LoseFocus(fCurrent, true))
                {
                    Debug.Assert(false);
                }

                return(PerformIntoCurrentWindow(pe, pdContext, strSeq));
            }
            finally
            {
                if (bTopMost)
                {
                    fCurrent.TopMost = true;
                }
            }
        }
예제 #7
0
        private static void MenuAddEntry(PwDocument ds, ToolStripMenuItem tsmiContainer,
            PwEntry pe)
        {
            ToolStripMenuItem tsmiEntry = new ToolStripMenuItem();
            string strTitle = pe.Strings.ReadSafe(PwDefs.TitleField);
            string strUser = pe.Strings.ReadSafe(PwDefs.UserNameField);
            string strText = string.Empty;
            if((strTitle.Length > 0) && (strUser.Length > 0))
                strText = strTitle + ": " + strUser;
            else if(strTitle.Length > 0) strText = strTitle;
            else if(strUser.Length > 0) strText = strUser;
            tsmiEntry.Text = strText;
            tsmiEntry.ImageIndex = MenuGetImageIndex(ds, pe.IconId, pe.CustomIconUuid);
            tsmiContainer.DropDownItems.Add(tsmiEntry);

            ToolStripMenuItem tsmi;

            tsmi = new ToolStripMenuItem(KPRes.AutoType);
            tsmi.ImageIndex = (int)PwIcon.Run;
            tsmi.Tag = pe;
            tsmi.Click += OnAutoType;
            tsmi.Enabled = pe.GetAutoTypeEnabled();
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmiEntry.DropDownItems.Add(new ToolStripSeparator());

            tsmi = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.UserName);
            tsmi.ImageIndex = (int)PwIcon.UserKey;
            tsmi.Tag = pe;
            tsmi.Click += OnCopyUserName;
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmi = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.Password);
            tsmi.ImageIndex = (int)PwIcon.Key;
            tsmi.Tag = pe;
            tsmi.Click += OnCopyPassword;
            tsmiEntry.DropDownItems.Add(tsmi);
        }
예제 #8
0
		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);
		}
예제 #9
0
		public static bool PerformIntoPreviousWindow(Form fCurrent, 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;

			bool bTopMost = ((fCurrent != null) ? fCurrent.TopMost : false);
			if(bTopMost) fCurrent.TopMost = false;

			try
			{
				if(!NativeMethods.LoseFocus(fCurrent)) { Debug.Assert(false); }

				return PerformIntoCurrentWindow(pe, pdContext, strSeq);
			}
			finally
			{
				if(bTopMost) fCurrent.TopMost = true;
			}
		}
예제 #10
0
		// 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;
		}
예제 #11
0
        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;
        }
예제 #12
0
        // 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);
        }
예제 #13
0
        public QuickAccessForm(IPluginHost host, PwEntry entry, Options options, bool tan)
        {
            this.host = host;
            this.entry = entry;
            this.tan = tan;
            this.options = options;

            host.MainWindow.FileClosingPre += MainWindow_FileClosingPre;

            InitializeComponent();

            if (options.location != (int)Options.Locations.Center)
            {
                this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
                Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
                if (options.location == (int)Options.Locations.LowerRight)
                {
                    this.Left = workingArea.Right - this.Width;
                    this.Top = workingArea.Bottom - this.Height;
                }
                else if (options.location == (int)Options.Locations.UpperRight)
                {
                    this.Left = workingArea.Right - this.Width;
                    this.Top = workingArea.Top;
                }
                else if (options.location == (int)Options.Locations.LowerLeft)
                {
                    this.Left = workingArea.Left;
                    this.Top = workingArea.Bottom - this.Height;
                }
                else if (options.location == (int)Options.Locations.UpperLeft)
                {
                    this.Left = workingArea.Left;
                    this.Top = workingArea.Top;
                }
            }

            host.MainWindow.FileClosingPre += MainWindow_FileClosingPre;
            string title = entry.Strings.ReadSafe(PwDefs.TitleField);
            if (title != null) this.Text = title;

            imgList = new ImageList();
            imgList.Images.Add((System.Drawing.Bitmap)host.Resources.GetObject("B16x16_KTouch"));
            imgList.Images.Add((System.Drawing.Bitmap)host.Resources.GetObject("B16x16_Browser"));
            imgList.Images.Add((System.Drawing.Bitmap)host.Resources.GetObject("B16x16_Personal"));
            imgList.Images.Add((System.Drawing.Bitmap)host.Resources.GetObject("B16x16_KGPG_Info"));
            imgList.Images.Add(host.MainWindow.ClientIcons.Images[(int)PwIcon.Notepad]);
            imgList.Images.Add(host.MainWindow.ClientIcons.Images[(int)PwIcon.List]);
            imgList.Images.Add((System.Drawing.Bitmap)host.Resources.GetObject("B16x16_KeePass"));

            this.Icon = host.MainWindow.Icon;
            buttonAutoType.Image = imgList.Images[0];
            buttonUrl.Image = imgList.Images[1];
            buttonCopyUser.Image = tan ? imgList.Images[3] : imgList.Images[2];
            buttonCopyPw.Image = imgList.Images[3];
            buttonCopyNotes.Image = imgList.Images[4];
            buttonCopyFields.Image = imgList.Images[5];
            buttonMainWindow.Image = imgList.Images[6];

            buttonAutoType.Enabled = entry.GetAutoTypeEnabled();
            buttonUrl.Enabled = !entry.Strings.GetSafe(PwDefs.UrlField).IsEmpty;
            buttonCopyUser.Enabled = (!entry.Strings.GetSafe(PwDefs.UserNameField).IsEmpty && !tan) || (!entry.Strings.GetSafe(PwDefs.PasswordField).IsEmpty && tan);
            buttonCopyPw.Enabled = !entry.Strings.GetSafe(PwDefs.PasswordField).IsEmpty && !tan;
            buttonCopyNotes.Enabled = !entry.Strings.GetSafe(PwDefs.NotesField).IsEmpty;
            buttonCopyFields.Enabled = Util.hasFields(entry);

            if (tan) buttonCopyUser.Text = "Copy TAN";
            buttonCopyPw.Visible = !tan;

            this.panel.Select();

            userCopied = !buttonCopyUser.Enabled;
            pwCopied = !buttonCopyPw.Enabled;

            this.Activated += QuickAccessForm_Activated;
            this.Deactivate += QuickAccessForm_Deactivate;
            this.FormClosing += QuickAccessForm_FormClosing;
        }
예제 #14
0
파일: AutoType.cs 프로젝트: sinelaw/keepass
        private static bool Execute(AutoTypeCtx ctx)
        {
            if (ctx == null)
            {
                Debug.Assert(false); return(false);
            }

            string  strSeq  = ctx.Sequence;
            PwEntry pweData = ctx.Entry;

            if (pweData == null)
            {
                Debug.Assert(false); return(false);
            }

            if (!pweData.GetAutoTypeEnabled())
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoType))
            {
                return(false);
            }

            if (KeePassLib.Native.NativeLib.IsUnix())
            {
                if (!NativeMethods.TryXDoTool())
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequired,
                                               KPRes.PackageInstallHint);
                    return(false);
                }
            }

            PwDatabase pwDatabase = ctx.Database;

            bool bObfuscate = (pweData.AutoType.ObfuscationOptions !=
                               AutoTypeObfuscationOptions.None);
            AutoTypeEventArgs args = new AutoTypeEventArgs(strSeq, bObfuscate,
                                                           pweData, pwDatabase);

            if (AutoType.FilterCompilePre != null)
            {
                AutoType.FilterCompilePre(null, args);
            }

            args.Sequence = SprEngine.Compile(args.Sequence, new SprContext(
                                                  pweData, pwDatabase, SprCompileFlags.All, true, false));

            // string strError = ValidateAutoTypeSequence(args.Sequence);
            // if(!string.IsNullOrEmpty(strError))
            // {
            //	MessageService.ShowWarning(args.Sequence +
            //		MessageService.NewParagraph + strError);
            //	return false;
            // }

            Application.DoEvents();

            if (AutoType.FilterSendPre != null)
            {
                AutoType.FilterSendPre(null, args);
            }
            if (AutoType.FilterSend != null)
            {
                AutoType.FilterSend(null, args);
            }

            if (args.Sequence.Length > 0)
            {
                try { SendInputEx.SendKeysWait(args.Sequence, args.SendObfuscated); }
                catch (Exception excpAT)
                {
                    MessageService.ShowWarning(args.Sequence +
                                               MessageService.NewParagraph + excpAT.Message);
                }
            }

            pweData.Touch(false);
            if (EntryUtil.ExpireTanEntryIfOption(pweData, pwDatabase))
            {
                Program.MainForm.RefreshEntriesList();
            }

            // SprEngine.Compile might have modified the database;
            // pd.Modified is set by SprEngine
            Program.MainForm.UpdateUI(false, null, false, null, false, null, false);

            return(true);
        }
예제 #15
0
        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.GetAutoTypeEnabled())
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoType))
            {
                return(false);
            }

            if (KeePassLib.Native.NativeLib.IsUnix())
            {
                if (!NativeMethods.TryXDoTool())
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequired,
                                               KPRes.PackageInstallHint);
                    return(false);
                }
            }

            PwDatabase pwDatabase = null;

            try { pwDatabase = Program.MainForm.PluginHost.Database; }
            catch (Exception) { }

            bool bObfuscate = (pweData.AutoType.ObfuscationOptions !=
                               AutoTypeObfuscationOptions.None);
            AutoTypeEventArgs args = new AutoTypeEventArgs(strSeq, bObfuscate, pweData);

            if (AutoType.FilterCompilePre != null)
            {
                AutoType.FilterCompilePre(null, args);
            }

            args.Sequence = SprEngine.Compile(args.Sequence, true, pweData,
                                              pwDatabase, true, false);

            string strError = ValidateAutoTypeSequence(args.Sequence);

            if (strError != null)
            {
                MessageService.ShowWarning(strError);
                return(false);
            }

            Application.DoEvents();

            if (AutoType.FilterSendPre != null)
            {
                AutoType.FilterSendPre(null, args);
            }
            if (AutoType.FilterSend != null)
            {
                AutoType.FilterSend(null, args);
            }

            if (args.Sequence.Length > 0)
            {
                try { SendInputEx.SendKeysWait(args.Sequence, args.SendObfuscated); }
                catch (Exception excpAT)
                {
                    MessageService.ShowWarning(excpAT);
                }
            }

            pweData.Touch(false);

            // SprEngine.Compile might have modified the database
            Program.MainForm.UpdateUI(false, null, false, null, false, null, false);

            return(true);
        }
예제 #16
0
		public static bool PerformIntoPreviousWindow(Form fCurrent, PwEntry pe)
		{
			if((pe != null) && !pe.GetAutoTypeEnabled()) return false;

			bool bTopMost = ((fCurrent != null) ? fCurrent.TopMost : false);
			if(bTopMost) fCurrent.TopMost = false;

			try
			{
				if(!NativeMethods.LoseFocus(fCurrent)) { Debug.Assert(false); }

				return PerformIntoCurrentWindow(pe);
			}
			finally
			{
				if(bTopMost) fCurrent.TopMost = true;
			}
		}
예제 #17
0
        private static bool Execute(AutoTypeCtx ctx)
        {
            if (ctx == null)
            {
                Debug.Assert(false); return(false);
            }

            string  strSeq  = ctx.Sequence;
            PwEntry pweData = ctx.Entry;

            if (pweData == null)
            {
                Debug.Assert(false); return(false);
            }

            if (!pweData.GetAutoTypeEnabled())
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoType))
            {
                return(false);
            }

            if (NativeLib.IsUnix())
            {
                if (!NativeMethods.TryXDoTool() && !NativeLib.IsWayland())
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequired,
                                               KPRes.PackageInstallHint);
                    return(false);
                }
            }

            PwDatabase pwDatabase = ctx.Database;

            bool bObfuscate = (pweData.AutoType.ObfuscationOptions !=
                               AutoTypeObfuscationOptions.None);
            AutoTypeEventArgs args = new AutoTypeEventArgs(strSeq, bObfuscate,
                                                           pweData, pwDatabase);

            if (AutoType.FilterCompilePre != null)
            {
                AutoType.FilterCompilePre(null, args);
            }

            args.Sequence = SprEngine.Compile(args.Sequence, new SprContext(
                                                  pweData, pwDatabase, SprCompileFlags.All, true, false));

            // string strError = ValidateAutoTypeSequence(args.Sequence);
            // if(!string.IsNullOrEmpty(strError))
            // {
            //	MessageService.ShowWarning(args.Sequence +
            //		MessageService.NewParagraph + strError);
            //	return false;
            // }

            Application.DoEvents();

            if (AutoType.FilterSendPre != null)
            {
                AutoType.FilterSendPre(null, args);
            }
            if (AutoType.FilterSend != null)
            {
                AutoType.FilterSend(null, args);
            }

            if (args.Sequence.Length > 0)
            {
                string strError = null;
                try { SendInputEx.SendKeysWait(args.Sequence, args.SendObfuscated); }
                catch (SecurityException exSec) { strError = exSec.Message; }
                catch (Exception ex)
                {
                    strError = args.Sequence + MessageService.NewParagraph +
                               ex.Message;
                }

                if (AutoType.SendPost != null)
                {
                    AutoType.SendPost(null, args);
                }

                if (!string.IsNullOrEmpty(strError))
                {
                    try
                    {
                        MainForm mfP = Program.MainForm;
                        if (mfP != null)
                        {
                            mfP.EnsureVisibleForegroundWindow(false, false);
                        }
                    }
                    catch (Exception) { Debug.Assert(false); }

                    MessageService.ShowWarning(strError);
                }
            }

            pweData.Touch(false);
            EntryUtil.ExpireTanEntryIfOption(pweData, pwDatabase);

            MainForm mf = Program.MainForm;

            if (mf != null)
            {
                // Always refresh entry list (e.g. {NEWPASSWORD} might
                // have changed data)
                mf.RefreshEntriesList();

                // SprEngine.Compile might have modified the database;
                // pd.Modified is set by SprEngine
                mf.UpdateUI(false, null, false, null, false, null, false);

                if (Program.Config.MainWindow.MinimizeAfterAutoType &&
                    mf.IsCommandTypeInvokable(null, MainForm.AppCommandType.Window))
                {
                    UIUtil.SetWindowState(mf, FormWindowState.Minimized);
                }
            }

            return(true);
        }
예제 #18
0
파일: AutoType.cs 프로젝트: elitak/keepass
        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.GetAutoTypeEnabled()) return false;
            if(!AppPolicy.Try(AppPolicyId.AutoType)) return false;

            if(KeePassLib.Native.NativeLib.IsUnix())
            {
                if(!NativeMethods.TryXDoTool())
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequired,
                        KPRes.PackageInstallHint);
                    return false;
                }
            }

            PwDatabase pwDatabase = null;
            try { pwDatabase = Program.MainForm.PluginHost.Database; }
            catch(Exception) { }

            bool bObfuscate = (pweData.AutoType.ObfuscationOptions !=
                AutoTypeObfuscationOptions.None);
            AutoTypeEventArgs args = new AutoTypeEventArgs(strSeq, bObfuscate, pweData);

            if(AutoType.FilterCompilePre != null) AutoType.FilterCompilePre(null, args);

            args.Sequence = SprEngine.Compile(args.Sequence, true, pweData,
                pwDatabase, true, false);

            string strError = ValidateAutoTypeSequence(args.Sequence);
            if(strError != null)
            {
                MessageService.ShowWarning(strError);
                return false;
            }

            Application.DoEvents();

            if(AutoType.FilterSendPre != null) AutoType.FilterSendPre(null, args);
            if(AutoType.FilterSend != null) AutoType.FilterSend(null, args);

            if(args.Sequence.Length > 0)
            {
                try { SendInputEx.SendKeysWait(args.Sequence, args.SendObfuscated); }
                catch(Exception excpAT)
                {
                    MessageService.ShowWarning(excpAT);
                }
            }

            pweData.Touch(false);
            if(EntryUtil.ExpireTanEntryIfOption(pweData))
                Program.MainForm.RefreshEntriesList();

            // SprEngine.Compile might have modified the database;
            // pd.Modified is set by SprEngine
            Program.MainForm.UpdateUI(false, null, false, null, false, null, false);

            return true;
        }
예제 #19
0
파일: AutoType.cs 프로젝트: elitak/keepass
        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();
        }
예제 #20
0
        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);
        }