Пример #1
0
        private void CheckForUpdate()
        {
            Task.Delay(200);
            if (!checkUpdate.GetValueOrDefault())
            {
                Task.Delay(2000);
                showMainWindow = true;
                Window_Closing(null, null);
                return;
            }
            cancellationToken.Token.ThrowIfCancellationRequested();
            var result = CheckUpdate.Run(SB.updateUrl);

            showMainWindow = !result.Update;
            if (result.Update)
            {
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate
                {
                    var notesWindow = new NotesWindow()
                    {
                        MainWindow = mainWindow,
                        SBUrl      = result.Url,
                    };
                    notesWindow.titleLabel.Content += " " + result.Version;
                    for (var i = 0; i < result.Notes.Count; i++)
                    {
                        notesWindow.richTextBox.AppendText(result.Notes[i].Note + "\n");
                    }
                    notesWindow.Show();
                    Close();
                });
            }
            else
            {
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate
                {
                    if (notesWindow == null)
                    {
                        Hide();
                        mainWindow = new MainWindow();
                        mainWindow.Show();
                        Close();
                    }
                });
            }
        }
Пример #2
0
        public MainWindow()
        {
            SB.MainWindow = this;

            // Clean or create log file
            File.WriteAllText(SB.logFile, "");

            InitializeComponent();

            var title = $"SilverBullet {SB.Version}";

            Title = title;
            titleLabel.Content = title;
            try
            {
                Task.Run(() =>
                {
                    var update = CheckUpdate.Run <LatestRelease>("https://api.github.com/repos/mohamm4dx/SilverBullet/releases/latest");
                    Dispatcher.Invoke(() => updateButton.Visibility = update.Available ? Visibility.Visible : Visibility.Collapsed);
                });
            }
            catch { }
            // Make sure all folders are there or recreate them
            var folders = new string[] { "Captchas", "ChromeExtensions", "Configs", "DB", "Hits", "Plugins", "Screenshots", "Settings", "Sounds", "Wordlists", "Js", "Compiled" };

            foreach (var folder in folders.Select(f => Path.Combine(Directory.GetCurrentDirectory(), f)))
            {
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
            }

            // Initialize Environment Settings
            try
            {
                SB.Settings.Environment = IOManager.ParseEnvironmentSettings(SB.envFile);
            }
            catch
            {
                SB.Logger.LogError(Components.Main,
                                   "Could not find / parse the Environment Settings file. Please fix the issue and try again.", true);
                Environment.Exit(0);
            }

            if (SB.Settings.Environment.WordlistTypes.Count == 0 || SB.Settings.Environment.CustomKeychains.Count == 0)
            {
                SB.Logger.LogError(Components.Main,
                                   "At least one WordlistType and one CustomKeychain must be defined in the Environment Settings file.", true);
                Environment.Exit(0);
            }

            try
            {
                var vcInstalledVersion = SilverBullet.RedistributableChecker.RedistributablePackage.GetInstalledVersion();

                if (vcInstalledVersion.Length == 0)
                {
                    SB.Logger.LogError(Components.Main, "Visual C++ Redistributable 2015+ Not Installed\nInstall vc_redist.x64 AND vc_redist.x86\nDl Link: microsoft.com/en-us/download/details.aspx?id=48145\nGo to Help tab and then to Requirements tab", true);
                }

                else if (!vcInstalledVersion.Any(v => v.Contains("x86")))
                {
                    SB.Logger.LogError(Components.Main, "Visual C++ Redistributable 2015+ (x86) Not Installed\nDl Link: microsoft.com/en-us/download/details.aspx?id=48145\nGo to Help tab and then to Requirements tab", true);
                }
                else if (!vcInstalledVersion.Any(v => v.Contains("x64")))
                {
                    SB.Logger.LogError(Components.Main, "Visual C++ Redistributable 2015+ (x64) Not Installed\nDl Link: microsoft.com/en-us/download/details.aspx?id=48145\nGo to Help tab and then to Requirements tab", true);
                }
            }
            catch
            {
                SB.Logger.LogError(Components.Main, "Error on check Visual C++ is installed");
            }

            // Initialize Settings
            SB.Settings.RLSettings           = new RLSettingsViewModel();
            SB.Settings.ProxyManagerSettings = new ProxyManagerSettings();
            SB.SBSettings = new SBSettingsViewModel();

            // Create / Load Settings
            if (!File.Exists(SB.rlSettingsFile))
            {
                MessageBox.Show("RuriLib Settings file not found, generating a default one");
                SB.Logger.LogWarning(Components.Main, "RuriLib Settings file not found, generating a default one");
                IOManager.SaveSettings(SB.rlSettingsFile, SB.Settings.RLSettings);
                SB.Logger.LogInfo(Components.Main, $"Created the default RuriLib Settings file {SB.rlSettingsFile}");
            }
            else
            {
                SB.Settings.RLSettings = IOManager.LoadSettings <RLSettingsViewModel>(SB.rlSettingsFile);
                SB.Logger.LogInfo(Components.Main, "Loaded the existing RuriLib Settings file");
            }

            if (!File.Exists(SB.proxyManagerSettingsFile))
            {
                SB.Logger.LogWarning(Components.Main, "Proxy manager Settings file not found, generating a default one");
                SB.Settings.ProxyManagerSettings.ProxySiteUrls.Add(SB.defaultProxySiteUrl);
                SB.Settings.ProxyManagerSettings.ActiveProxySiteUrl = SB.defaultProxySiteUrl;
                SB.Settings.ProxyManagerSettings.ProxyKeys.Add(SB.defaultProxyKey);
                SB.Settings.ProxyManagerSettings.ActiveProxyKey = SB.defaultProxyKey;
                IOManager.SaveSettings(SB.proxyManagerSettingsFile, SB.Settings.ProxyManagerSettings);
                SB.Logger.LogInfo(Components.Main, $"Created the default proxy manager Settings file {SB.proxyManagerSettingsFile}");
            }
            else
            {
                SB.Settings.ProxyManagerSettings = IOManager.LoadSettings <ProxyManagerSettings>(SB.proxyManagerSettingsFile);
                SB.Logger.LogInfo(Components.Main, "Loaded the existing proxy manager Settings file");
            }

            if (!File.Exists(SB.obSettingsFile))
            {
                MessageBox.Show("SilverBullet Settings file not found, generating a default one");
                SB.Logger.LogWarning(Components.Main, "SilverBullet Settings file not found, generating a default one");
                SBIOManager.SaveSettings(SB.obSettingsFile, SB.SBSettings);
                SB.Logger.LogInfo(Components.Main, $"Created the default SilverBullet Settings file {SB.obSettingsFile}");
            }
            else
            {
                SB.SBSettings = SBIOManager.LoadSettings(SB.obSettingsFile);
                SB.Logger.LogInfo(Components.Main, "Loaded the existing SilverBullet Settings file");
            }

            // If there is no DB backup or if it's more than 1 day old, back up the DB
            try
            {
                if (SB.SBSettings.General.BackupDB &&
                    (!File.Exists(SB.dataBaseBackupFile) ||
                     (File.Exists(SB.dataBaseBackupFile) && ((DateTime.Now - File.GetCreationTime(SB.dataBaseBackupFile)).TotalDays > 1))))
                {
                    // Check that the DB is not corrupted by accessing a random collection. If this fails, an exception will be thrown.
                    using (var db = new LiteDB.LiteDatabase(SB.dataBaseFile))
                    {
                        var coll = db.GetCollection <RuriLib.Models.CProxy>("proxies");
                    }

                    // Delete the old file and copy over the new one
                    File.Delete(SB.dataBaseBackupFile);
                    File.Copy(SB.dataBaseFile, SB.dataBaseBackupFile);
                    SB.Logger.LogInfo(Components.Main, "Backed up the DB");
                }
            }
            catch (Exception ex)
            {
                SB.Logger.LogError(Components.Main, $"Could not backup the DB: {ex.Message}");
            }

            Topmost = SB.SBSettings.General.AlwaysOnTop;

            // Load Plugins
            (IEnumerable <PluginControl>, IEnumerable <IBlockPlugin>, IEnumerable <string>)plugins;
            //(plugins, blockPlugins)
            try
            {
                plugins = Loader.LoadPlugins(SB.pluginsFolder);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in load plugins\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
                throw;
            }
            SB.BlockPlugins = plugins.Item2.ToList();
            SB.PluginNames  = plugins.Item3;

            // Set mappings
            SB.BlockMappings = new List <(Type, Type, LinearGradientBrush)>()
            {
                (typeof(BlockBypassCF), typeof(PageBlockBypassCF), Colors.DarkSalmon.GetLinearGradientBrush()),
                (typeof(BlockImageCaptcha), typeof(PageBlockCaptcha), Colors.DarkOrange.GetLinearGradientBrush()),
                (typeof(BlockReportCaptcha), typeof(PageBlockReportCaptcha), Colors.DarkOrange.GetLinearGradientBrush()),
                (typeof(BlockFunction), typeof(PageBlockFunction), Colors.YellowGreen.GetLinearGradientBrush()),
                (typeof(BlockKeycheck), typeof(PageBlockKeycheck), Colors.DodgerBlue.GetLinearGradientBrush()),
                (typeof(BlockLSCode), typeof(PageBlockLSCode), Colors.White.GetLinearGradientBrush()),
                (typeof(BlockParse), typeof(PageBlockParse), Colors.Gold.GetLinearGradientBrush()),
                (typeof(BlockRecaptcha), typeof(PageBlockRecaptcha), Colors.Turquoise.GetLinearGradientBrush()),
                (typeof(BlockSolveCaptcha), typeof(PageBlockSolveCaptcha), Colors.Turquoise.GetLinearGradientBrush()),
                (typeof(BlockRequest), typeof(PageBlockRequest), Colors.LimeGreen.GetLinearGradientBrush()),
                (typeof(BlockTCP), typeof(PageBlockTCP), Colors.MediumPurple.GetLinearGradientBrush()),
                (typeof(BlockOcr), typeof(PageBlockOcr), Color.FromRgb(230, 230, 230).GetLinearGradientBrush()),
                (typeof(BlockWebSocket), typeof(PageBlockWebSocket), Color.FromRgb(245, 180, 0).GetLinearGradientBrush()),
                (typeof(BlockSpeechToText), typeof(PageBlockSpeechToText), Color.FromRgb(164, 198, 197).GetLinearGradientBrush()),
                (typeof(BlockUtility), typeof(PageBlockUtility), Colors.Wheat.GetLinearGradientBrush()),
                (typeof(SBlockBrowserAction), typeof(PageSBlockBrowserAction), Colors.Green.GetLinearGradientBrush()),
                (typeof(SBlockElementAction), typeof(PageSBlockElementAction), Colors.Firebrick.GetLinearGradientBrush()),
                (typeof(SBlockExecuteJS), typeof(PageSBlockExecuteJS), Color.FromRgb(60, 193, 226).GetLinearGradientBrush()),
                (typeof(SBlockNavigate), typeof(PageSBlockNavigate), Colors.RoyalBlue.GetLinearGradientBrush())
            };

            // Add block plugins to mappings
            foreach (var plugin in plugins.Item2)
            {
                try
                {
                    SB.BlockMappings.Add((plugin.GetType(), typeof(BlockPluginPage), plugin.LinearGradientBrush));
                    BlockParser.BlockMappings.Add(plugin.Name, plugin.GetType());
                    SB.Logger.LogInfo(Components.Main, $"Initialized {plugin.Name} block plugin");
                }
                catch (Exception ex)
                {
                    SB.Logger.LogError(Components.Main, $"{ex.Message}\n{plugin.Name}.dll", true);
                    Environment.Exit(0);
                }
            }


            // ViewModels
            SB.RunnerManager   = new RunnerManagerViewModel();
            SB.ProxyManager    = new ProxyManagerViewModel();
            SB.WordlistManager = new WordlistManagerViewModel();
            SB.ConfigManager   = new ConfigManagerViewModel();
            SB.HitsDB          = new HitsDBViewModel();

            // Views
            RunnerManagerPage = new RunnerManager();

            // If we create first runner and there was no session to restore
            if (SB.SBSettings.General.AutoCreateRunner & !SB.RunnerManager.RestoreSession())
            {
                var firstRunner = SB.RunnerManager.Create();
                CurrentRunnerPage = SB.RunnerManager.RunnersCollection.FirstOrDefault().View;
            }

            SB.Logger.LogInfo(Components.Main, "Initialized RunnerManager");
            ProxyManagerPage = new ProxyManager();
            SB.Logger.LogInfo(Components.Main, "Initialized ProxyManager");
            WordlistManagerPage = new WordlistManager();
            SB.Logger.LogInfo(Components.Main, "Initialized WordlistManager");
            ConfigsPage = new ConfigsSection();
            SB.Logger.LogInfo(Components.Main, "Initialized ConfigManager");
            HitsDBPage = new HitsDB();
            SB.Logger.LogInfo(Components.Main, "Initialized HitsDB");
            OBSettingsPage = new Settings();
            SB.Logger.LogInfo(Components.Main, "Initialized Settings");
            ToolsPage = new ToolsSection();
            SB.Logger.LogInfo(Components.Main, "Initialized Tools");
            PluginsPage = new PluginsSection(plugins.Item1);
            SB.Logger.LogInfo(Components.Main, "Initialized Plugins");
            AboutPage      = new Help();
            SilverZonePage = new SilverZone();

            menuOptionRunner_Click(this, null);

            var width  = SB.SBSettings.General.StartingWidth;
            var height = SB.SBSettings.General.StartingHeight;

            if (width > 800)
            {
                Width = width;
            }
            if (height > 600)
            {
                Height = height;
            }

            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            if (SB.SBSettings.Themes.EnableSnow)
            {
                Loaded += MainWindow_Loaded;
            }
        }