Exemple #1
0
        internal static bool IncursionSetup(string source, double incursionStrength)
        {
            try
            {
                Console.CursorVisible = false;
                // 1. 黑屏
                Console.Clear();
                Thread.Sleep(5000);

                // 2. Unauthorized Connection Detected 红字
                Console.ForegroundColor = ConsoleColor.Red;
                for (var i = 0; i < 50; i++)
                {
                    Console.WriteLine(WAF_TextResource.Unauthorized_Connection);
                    Thread.Sleep(50);
                }

                Console.ResetColor();
                Thread.Sleep(2000);
                Console.Clear();
                Thread.Sleep(2000);

                // 3. 类似电脑蓝屏,启动防御(此处可参考E3 2077)
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                Console.ForegroundColor = ConsoleColor.White;
                for (var i = 0; i < Console.WindowHeight; i++)
                {
                    Console.SetCursorPosition(0, i);
                    Console.Write(string.Empty.PadLeft(Console.WindowWidth, ' '));
                }

                Console.SetCursorPosition(0, 0);
                Console.WriteLine(WAF_TextResource.Bsod_Text);

                // 动画跳转至WAFC继续编写


                var wafc = (WaFirecracker)((dynamic)GameController.HostList.Find(h => h.Addr == source))
                           .wafc; //如果没有wafc就输了
                if (wafc.IsAcquiredMasterKey)
                {
                    Console.ResetColor();
                    Console.WriteLine(WAF_TextResource.Wafc_Bypass);
                    Thread.Sleep(2000);
                    return(true);
                }

                var counter = new WaFirecracker.CounterMeasure(ref wafc.DefenceStrength, wafc.IsFirstTime); //这个使用主线程

                // 开一个线程用来加攻击
                var attackAnalyzerTask = new Task(() =>
                {
                    // ReSharper disable once AccessToDisposedClosure
                    while (!counter.Source.Token.IsCancellationRequested)
                    {
                        counter.AttackAnalyzer(incursionStrength);
                        Thread.Sleep(100);
                    }
                }, counter.Source.Token);

                var getResultTask = new Task <bool>(() =>
                {
                    var result = counter.GetResult();
                    if (counter.IsGetMasterKey)
                    {
                        wafc.IsAcquiredMasterKey = true;
                    }
                    // ReSharper disable once AccessToDisposedClosure
                    counter.Source.Cancel();
                    Task.WaitAll(attackAnalyzerTask);
                    return(result);
                });

                attackAnalyzerTask.Start();
                getResultTask.Start();

                Task.WaitAll(getResultTask, attackAnalyzerTask);
                if (getResultTask.Result)
                {
                    wafc.IsFirstTime      = false;
                    wafc.DefenceStrength += 0.04;
                }
                else
                {
                    BigFirework.YouDied();
                }

                Console.CursorVisible = true;
                counter.CmLock.Dispose();
                counter.Source.Dispose();
                return(getResultTask.Result);
            }
            catch
            {
                Thread.Sleep(2000);
                Console.WriteLine(WAF_TextResource.Wafc_Failed);
                Thread.Sleep(2000);
                Console.ResetColor();
                BigFirework.YouDied();
                return(false);
            }
        }
        internal static void Initialize()
        {
            if (File.Exists(@".\Save.resx"))
            {
                try
                {
                    using (var resxSet = new ResXResourceSet(@".\Save.resx"))
                    {
                        try
                        {
                            if (resxSet.GetObject("RootKit") != null)
                            {
                                BigFirework.YouDied();
                                return;
                            }
                        }
                        catch
                        {
                            // 忽略掉
                        }

                        HostList     = (List <Host>)resxSet.GetObject("hosts");
                        SaveLoadList = (List <SaveLoadActions>)resxSet.GetObject("slList");
                        if ((SaveLoadList ?? throw new BrokenSaveException()).Any(sla => !sla.Load(resxSet)))
                        {
                            throw new BrokenSaveException();
                        }
                    }

                    if (HostList == null)
                    {
                        throw new BrokenSaveException();
                    }
                }
                catch
                {
                    File.Delete(@".\Save.resx");
                    Initialize();
                }
            }
            else
            {
                var initTask = new Task(() =>
                {
                    HostList = HostStorage.InitializeHost();
                    var rm   = GlobalConfig.ResourceManager;
                    LinkStorage.ReLink(rm);
                    WafServer.FirewallInstall(rm);
                    MailServer.RebuildMails();
                    AutoSploitServer.AddExploit(rm);
                });
                //HostList = HostStorage.InitializeHost();

                //var rm = GlobalConfig.ResourceManager;

                //LinkStorage.ReLink(rm);
                //WafServer.FirewallInstall(rm);
                //MailServer.RebuildMails();
                //AutoSploitServer.AddExploit(rm);

                initTask.Start();

                foreach (var s in GameController_TextResource.BootUp.Replace("\r\n", "\n").Split('\n'))
                {
                    if (s.Trim() == string.Empty)
                    {
                        Thread.Sleep(1000);
                    }

                    Console.WriteLine(s);
                    Thread.Sleep(50);
                }
                initTask.Wait();
                PlotObserver.InitializePlot();
                PlotObserver.StartObserve();
                Console.Clear();
                Thread.Sleep(2000);
            }

            WafServer.FirewallBootUp();
            MediaPlayer.RegisterMediaFile();
            AutoSploit.RegisterExpFile();

            new Terminal(HostList?[0].Sh).Open();
        }