private void DetectPasswordsManager()
        {
            var processes           = Process.GetProcesses();
            var passwordManagerList = new Dictionary <string, string>
            {
                // Process name, Application title in the ignored list
                { "PasswordZanager", "PasswordZanager" },
                { "AgileBits.OnePassword.Desktop", "1Password" },
                { "Dashlane", "Dashlane" },
                { "KeePass", "KeePass Password Safe" }
            };

            foreach (var process in processes)
            {
                var passwordManagerDetected = passwordManagerList.FirstOrDefault(item => string.Equals(item.Key, process.ProcessName, StringComparison.OrdinalIgnoreCase));
                if (!passwordManagerDetected.Equals(default(KeyValuePair <string, string>)))
                {
                    var ignoredApp            = new IgnoredApplication();
                    var applicationIdentifier = SystemInfoHelper.GetExecutablePath(process.Id);

                    ignoredApp.DisplayName           = passwordManagerDetected.Value;
                    ignoredApp.ApplicationIdentifier = applicationIdentifier;

                    if (File.Exists(applicationIdentifier))
                    {
                        var tempIcon = Icon.ExtractAssociatedIcon(applicationIdentifier)?.ToBitmap();
                        if (tempIcon != null)
                        {
                            ignoredApp.Icon = DataHelper.BitmapToBitmapImage(new Bitmap(tempIcon, Consts.WindowsIconsSize, Consts.WindowsIconsSize), Consts.WindowsIconsSize);
                        }
                    }

                    var collection = IgnoredApplications;
                    if (collection.Any(app => app.DisplayName == ignoredApp.DisplayName))
                    {
                        continue;
                    }

                    collection.Add(ignoredApp);
                    IgnoredApplications = collection;
                    Logger.Instance.Information($"The application '{ignoredApp.ApplicationIdentifier}' has been added to the ignored app list.");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves some information about a window, like the title, the icon, and return it.
        /// </summary>
        /// <param name="windowHandle">The handle of the window</param>
        /// <returns>A <see cref="Window"/> that represents the information about the window</returns>
        private Window GetWindowInformation(IntPtr windowHandle)
        {
            var stringBuilder = new StringBuilder(256);

            NativeMethods.GetWindowText(windowHandle, stringBuilder, stringBuilder.Capacity);

            // We retrieve the process id
            int processId;

            NativeMethods.GetWindowThreadProcessId(windowHandle, out processId);

            BitmapImage icon                  = null;
            var         process               = Process.GetProcessById(processId);
            var         isWindowsStoreApp     = false;
            var         applicationIdentifier = string.Empty;

            Requires.NotNull(process, nameof(process));

            // If the process corresponds to a Windows Store app (process ApplicationFrameHost
            if (string.Equals(process.ProcessName, Consts.WindowsStoreProcessName, StringComparison.OrdinalIgnoreCase))
            {
                // We retrieve the Win Store App package linked to this window.
                isWindowsStoreApp = true;

                IPropertyStore propStore;
                var            iidIPropertyStore = new Guid("{" + Consts.PropertyStore + "}");
                Requires.VerifySucceeded(NativeMethods.SHGetPropertyStoreForWindow(windowHandle, ref iidIPropertyStore, out propStore));

                using (var prop = new PropVariant())
                {
                    Requires.VerifySucceeded(propStore.GetValue(_appUserModelIdKey, prop));

                    var familyName = prop.Value.Split('!').First();
                    var package    = _windowsStoreApps.FirstOrDefault(app => string.Equals(app.FamilyName, familyName, StringComparison.Ordinal));
                    if (package != null)
                    {
                        applicationIdentifier = package.FamilyName;
                        // Avoid some Thread problem with the hooking. TODO : Investigate for a better solution
                        var thread = new Thread(() =>
                        {
                            // Then we retrieve the application's icon.
                            var iconTask = GetWindowsStoreIconAsync(package);
                            iconTask.Wait();
                            icon = iconTask.Result;
                        });
                        thread.Start();
                        thread.Join();
                    }
                }
            }
            else
            {
                applicationIdentifier = SystemInfoHelper.GetExecutablePath(process.Id);
                icon = GetWin32WindowIcon(windowHandle, applicationIdentifier);
            }

            if (string.IsNullOrEmpty(applicationIdentifier))
            {
                return(null);
            }

            if (icon == null)
            {
                icon = new BitmapImage();
                if (applicationIdentifier.ToLower() == (Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\explorer.exe").ToLower() && stringBuilder.ToString() == "") // Desktop
                {
                    Bitmap bitIcon = Icon.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\explorer.exe").ToBitmap();
                    using (var memory = new MemoryStream())
                    {
                        bitIcon.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                        memory.Position = 0;
                        icon.BeginInit();
                        icon.StreamSource = memory;
                        icon.CacheOption  = BitmapCacheOption.OnLoad;
                        icon.EndInit();
                        icon.Freeze();
                    }
                }
                else // Other app without icon
                {
                    icon.BeginInit();
                    icon.UriSource   = new Uri("pack://application:,,,/ClipboardZanager;component/Assets/NoIcon.png", UriKind.RelativeOrAbsolute);
                    icon.CacheOption = BitmapCacheOption.OnLoad;
                    icon.EndInit();
                    icon.Freeze();
                }
            }

            return(new Window(windowHandle, stringBuilder.ToString(), process, applicationIdentifier, icon, isWindowsStoreApp));
        }