Пример #1
0
        static void Main(string[] args)
        {
            DesignMode = false;             // The designer doesn't call Main()

            CommandLineArgs = new CommandLineArgs(args);

            try
            {
                DpiUtil.ConfigureProcess();
            }
            catch
            {
            }

            MonoSpaceFont = new FontEx
            {
                Font   = new Font("Courier New", DpiUtil.ScaleIntX(13), GraphicsUnit.Pixel),
                Width  = DpiUtil.ScaleIntX(8),
                Height = DpiUtil.ScaleIntY(16)
            };

            NativeMethods.EnableDebugPrivileges();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            Settings = SettingsSerializer.Load();
            Logger   = new GuiLogger();

#if !DEBUG
            try
            {
#endif
            using (var coreFunctions = new CoreFunctionsManager())
            {
                RemoteProcess = new RemoteProcess(coreFunctions);

                MainForm = new MainForm();

                Application.Run(MainForm);

                RemoteProcess.Dispose();
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ShowException(ex);
        }
#endif

            SettingsSerializer.Save(Settings);
        }
        public static KeyValuePair <string, string> GetEntry(string entry, string databasefile, string keyfile)
        {
            /*
             * Assembly assembly = Assembly.LoadFrom(assemblyPath);
             * Type T = assembly.GetType("Company.Project.Classname");
             * Company.Project.Classname instance = (Company.Project.Classname)Activator.CreateInstance(T);
             */

            //Read string databasefile,string keyfile from config
            KeyValuePair <string, string> keyval = new KeyValuePair <string, string>("Username", null);

            DpiUtil.ConfigureProcess();        //needed?

            if (!KeePass.Program.CommonInit()) //check if in same dir as KeePass??
            {
                KeePass.Program.CommonTerminate();
                return(keyval);
            }

            IOConnectionInfo ioc = new IOConnectionInfo();

            ioc.Path         = databasefile;
            ioc.CredSaveMode = IOCredSaveMode.NoSave;

            CompositeKey cmpKey = new CompositeKey();

            cmpKey.AddUserKey(new KcpKeyFile(keyfile));

            if ((cmpKey == null) || (cmpKey.UserKeyCount == 0))
            {
                return(keyval);
            }

            PwDatabase pwDb = new PwDatabase();

            pwDb.Open(ioc, cmpKey, null);

            string password;

            //bool bNeedsSave;
            if (ReportingMod.GetEntryString(pwDb, entry, out password))
            {
                keyval = new KeyValuePair <string, string>("Username", password);
            }
            // if (bNeedsSave) pwDb.Save(null);


            pwDb.Close();


            return(keyval);
        }
Пример #3
0
        static void Main()
        {
            DesignMode = false;             // The designer doesn't call Main()

            try
            {
                DpiUtil.ConfigureProcess();
            }
            catch
            {
            }

            NativeMethods.EnableDebugPrivileges();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            Settings = Settings.Load(Constants.SettingsFile);
            Logger   = new GuiLogger();
#if DEBUG
            using (var coreFunctions = new CoreFunctionsManager())
            {
                MainForm = new MainForm(coreFunctions);

                Application.Run(MainForm);
            }
#else
            try
            {
                using (var nativeHelper = new CoreFunctionsManager())
                {
                    MainForm = new MainForm(nativeHelper);

                    Application.Run(MainForm);
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
#endif

            Settings.Save(Settings, Constants.SettingsFile);
        }
Пример #4
0
        static void Main()
        {
            designMode = false;             // The designer doesn't call Main()

            DpiUtil.ConfigureProcess();

            EnableDebugPrivileges();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            settings = Settings.Load(Constants.SettingsFile);
            logger   = new GuiLogger();
#if RELEASE
            try
            {
                using (var nativeHelper = new NativeHelper())
                {
                    mainForm = new MainForm(nativeHelper);

                    Application.Run(mainForm);
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
#else
            using (var nativeHelper = new NativeHelper())
            {
                mainForm = new MainForm(nativeHelper);

                Application.Run(mainForm);
            }
#endif

            Settings.Save(settings, Constants.SettingsFile);
        }
        public static void GetAllEntries(string databasefile, string keyfile, out ConcurrentDictionary <string, KeyValuePair <string, string> > dictionary)
        {
            // public static void ListEntries(PwDatabase pwDb)
            dictionary = null;

            DpiUtil.ConfigureProcess();        //needed?

            if (!KeePass.Program.CommonInit()) //check if in same dir as KeePass??
            {
                KeePass.Program.CommonTerminate();
                return;
            }

            IOConnectionInfo ioc = new IOConnectionInfo();

            ioc.Path         = databasefile;
            ioc.CredSaveMode = IOCredSaveMode.NoSave;

            CompositeKey cmpKey = new CompositeKey();

            cmpKey.AddUserKey(new KcpKeyFile(keyfile));

            if ((cmpKey == null) || (cmpKey.UserKeyCount == 0))
            {
                return;
            }

            PwDatabase pwDb = new PwDatabase();

            pwDb.Open(ioc, cmpKey, null);


            EntryMod.GetAllEntries(pwDb, out dictionary);


            pwDb.Close();
        }
Пример #6
0
        public static void Main(string[] args)
        {
#if DEBUG
            // Program.DesignMode should not be queried before executing
            // Main (e.g. by a static Control) when running the program
            // normally
            Debug.Assert(!m_bDesignModeQueried);
#endif
            m_bDesignMode = false;             // Designer doesn't call Main method

            m_cmdLineArgs = new CommandLineArgs(args);

            // Before loading the configuration
            string strWaDisable = m_cmdLineArgs[
                AppDefs.CommandLineOptions.WorkaroundDisable];
            if (!string.IsNullOrEmpty(strWaDisable))
            {
                MonoWorkarounds.SetEnabled(strWaDisable, false);
            }

            DpiUtil.ConfigureProcess();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents();             // Required

#if DEBUG
            string strInitialWorkDir = WinUtil.GetWorkingDirectory();
#endif

            if (!CommonInit())
            {
                CommonTerminate(); return;
            }

            if (m_appConfig.Application.Start.PluginCacheClearOnce)
            {
                PlgxCache.Clear();
                m_appConfig.Application.Start.PluginCacheClearOnce = false;
                AppConfigSerializer.Save(Program.Config);
            }

            if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null)
            {
                ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId,
                                            KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null)
            {
                ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null)
            {
                // All important .NET assemblies are in memory now already
                try { SelfTest.Perform(); }
                catch (Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }

            /* if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null)
             * {
             *      string strPreLoadPath = WinUtil.GetExecutable().Trim();
             *      if(strPreLoadPath.StartsWith("\"") == false)
             *              strPreLoadPath = "\"" + strPreLoadPath + "\"";
             *      ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath,
             *              @"--" + AppDefs.CommandLineOptions.PreLoad, true);
             *      MainCleanUp();
             *      return;
             * }
             * if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null)
             * {
             *      ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty,
             *              string.Empty, false);
             *      MainCleanUp();
             *      return;
             * } */
            if ((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) ||
                (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null))
            {
                AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetUrlOverride];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = string.Empty;
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null)
            {
                try
                {
                    string strFileOut = UrlUtil.EnsureTerminatingSeparator(
                        UrlUtil.GetTempPath(), false) + "KeePass_UrlOverride.tmp";
                    string strContent = ("[KeePass]\r\nKeeURLOverride=" +
                                         Program.Config.Integration.UrlOverride + "\r\n");
                    File.WriteAllText(strFileOut, strContent);
                }
                catch (Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null)
            {
                Program.Config.Application.LanguageFile = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetLanguageFile];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null)
            {
                PlgxPlugin.CreateFromCommandLine();
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null)
            {
                PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ShowAssemblyInfo] != null)
            {
                MessageService.ShowInfo(Assembly.GetExecutingAssembly().ToString());
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXmlSerializerEx] != null)
            {
                XmlSerializerEx.GenerateSerializers(m_cmdLineArgs);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXspFile] != null)
            {
                XspArchive.CreateFile(m_cmdLineArgs.FileName, m_cmdLineArgs["d"]);
                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.Version] != null)
            {
                Console.WriteLine(PwDefs.ShortProductName + " " + PwDefs.VersionString);
                Console.WriteLine(PwDefs.Copyright);
                MainCleanUp();
                return;
            }
#if DEBUG
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.TestGfx] != null)
            {
                List <Image> lImg = new List <Image>();
                lImg.Add(Properties.Resources.B16x16_Browser);
                lImg.Add(Properties.Resources.B48x48_Keyboard_Layout);
                ImageArchive aHighRes = new ImageArchive();
                aHighRes.Load(Properties.Resources.Images_Client_HighRes);
                lImg.Add(aHighRes.GetForObject("C12_IRKickFlash"));
                if (File.Exists("Test.png"))
                {
                    lImg.Add(Image.FromFile("Test.png"));
                }
                Image img = GfxUtil.ScaleTest(lImg.ToArray());
                img.Save("GfxScaleTest.png", ImageFormat.Png);
                return;
            }
#endif
            // #if (DEBUG && !KeePassLibSD)
            // if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null)
            // {
            //	PopularPasswords.MakeList();
            //	MainCleanUp();
            //	return;
            // }
            // #endif

            try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); }
            catch (Exception) { Debug.Assert(NativeLib.IsUnix()); }

            if (m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Exit);
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.AutoType);
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoTypeSelected] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.AutoTypeSelected);
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null)
            {
                string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid];
                if (!string.IsNullOrEmpty(strEntryUuid))
                {
                    IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl,
                                                      strEntryUuid, null, null, null, null);
                    IpcUtilEx.SendGlobalMessage(ipUrl);
                }

                MainCleanUp();
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Lock);
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Unlock);
                return;
            }
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent] != null)
            {
                string strName = m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent];
                if (!string.IsNullOrEmpty(strName))
                {
                    string[] vFlt = KeyUtil.MakeCtxIndependent(args);

                    IpcParamEx ipEvent = new IpcParamEx(IpcUtilEx.CmdIpcEvent, strName,
                                                        CommandLineArgs.SafeSerialize(vFlt), null, null, null);
                    IpcUtilEx.SendGlobalMessage(ipEvent);
                }

                MainCleanUp();
                return;
            }

            // Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
            bool bSingleLock = GlobalMutexPool.CreateMutex(AppDefs.MutexName, true);
            // if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
            if (!bSingleLock && m_appConfig.Integration.LimitToSingleInstance)
            {
                ActivatePreviousInstance(args);
                MainCleanUp();
                return;
            }

            Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

            AutoType.InitStatic();

            CustomMessageFilterEx cmfx = new CustomMessageFilterEx();
            Application.AddMessageFilter(cmfx);

#if DEBUG
            if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
            {
                throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);
            }

            m_formMain = new MainForm();
            Application.Run(m_formMain);
#else
            try
            {
                if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
                {
                    throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);
                }

                m_formMain = new MainForm();
                Application.Run(m_formMain);
            }
            catch (Exception exPrg)
            {
                // Catch message box exception;
                // https://sourceforge.net/p/keepass/patches/86/
                try { MessageService.ShowFatal(exPrg); }
                catch (Exception) { Console.Error.WriteLine(exPrg.ToString()); }
            }
#endif

            Application.RemoveMessageFilter(cmfx);

            Debug.Assert(GlobalWindowManager.WindowCount == 0);
            Debug.Assert(MessageService.CurrentMessageCount == 0);

            MainCleanUp();

#if DEBUG
            string strEndWorkDir = WinUtil.GetWorkingDirectory();
            Debug.Assert(strEndWorkDir.Equals(strInitialWorkDir, StrUtil.CaseIgnoreCmp));
#endif

            if (mGlobalNotify != null)
            {
                GC.KeepAlive(mGlobalNotify);
            }
            // if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
        }
Пример #7
0
        static void Main(string[] args)
        {
            DesignMode = false;             // The designer doesn't call Main()

            CommandLineArgs = new CommandLineArgs(args);

            try
            {
                DpiUtil.ConfigureProcess();
                DpiUtil.TrySetDpiFromCurrentDesktop();
            }
            catch
            {
                // ignored
            }

            MonoSpaceFont = new FontEx
            {
                Font   = new Font("Courier New", DpiUtil.ScaleIntX(13), GraphicsUnit.Pixel),
                Width  = DpiUtil.ScaleIntX(8),
                Height = DpiUtil.ScaleIntY(16)
            };

            NativeMethods.EnableDebugPrivileges();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            Settings = SettingsSerializer.Load();
            Logger   = new GuiLogger();

            if (!NativeMethods.IsUnix() && Settings.RunAsAdmin && !WinUtil.IsAdministrator)
            {
                WinUtil.RunElevated(Process.GetCurrentProcess().MainModule?.FileName, args.Length > 0 ? string.Join(" ", args) : null);
                return;
            }

#if !DEBUG
            try
            {
#endif
            using (var coreFunctions = new CoreFunctionsManager())
            {
                RemoteProcess = new RemoteProcess(coreFunctions);

                MainForm = new MainForm();

                Application.Run(MainForm);

                RemoteProcess.Dispose();
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ShowException(ex);
        }
#endif

            SettingsSerializer.Save(Settings);
        }