Example #1
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.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);
        }
Example #2
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);
        }
Example #3
0
        public static void SendKeysWait(string strKeys, bool bObfuscate)
        {
            if (strKeys == null)
            {
                Debug.Assert(false); return;
            }

            List <SiEvent> l = Parse(strKeys);

            if (l.Count == 0)
            {
                return;
            }

            if (bObfuscate)
            {
                SiObf.Obfuscate(l);
            }

            FixEventSeq(l);

            ISiEngine si = null;

            if (SendInputEx.CreateEngine != null)
            {
                SiEventArgs ea = new SiEventArgs();
                SendInputEx.CreateEngine(null, ea);
                si = ea.Engine;
            }
            if (si == null)
            {
                if (NativeLib.IsUnix())
                {
                    si = new SiEngineUnix();
                }
                else
                {
                    si = new SiEngineWin();
                }
            }

            bool bInter = Program.Config.Integration.AutoTypeAllowInterleaved;

            if (!bInter)
            {
                if (!g_csSending.TryEnter())
                {
                    return;
                }
            }

            Interlocked.Increment(ref g_cCurSending);
            try
            {
                si.Init();
                Send(si, l);
            }
            finally
            {
                try { si.Release(); }
                catch (Exception) { Debug.Assert(false); }

                Interlocked.Decrement(ref g_cCurSending);

                if (!bInter)
                {
                    g_csSending.Exit();
                }
            }
        }
Example #4
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 (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);
        }
Example #5
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);
        }