示例#1
0
        public bool TryLaunchWithSys(bool stat)
        {
            try
            {
                RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

                bool succ = false;

                if (stat)
                {
                    rk.SetValue("Litrojan", Process.GetCurrentProcess().MainModule.FileName);
                    succ = rk.GetValue("Litrojan") != null;
                }
                else
                {
                    rk.DeleteValue("Litrojan", false);
                    succ = rk.GetValue("Litrojan") == null;
                }

                infoDisp(succ
                    ? $"Auto launch configured to {stat}."
                    : $"Auto launch cannot be configured to {stat}.", "LiSettMgmt");
                notiDisp(succ
                    ? $"Auto launch configured to {stat}."
                    : $"Auto launch cannot be configured to {stat}.");

                return(succ);
            }
            catch (Exception e)
            {
                infoDisp(LitrojanUtils.ErrorFormatter("Failed to configure auto launch.", e), "LiSettMgmt");
                return(false);
            }
        }
示例#2
0
文件: Form1.cs 项目: siaimes/Litrojan
 private void BtnLogSave_Click(object sender, EventArgs e)
 {
     saveFileDialog1.AddExtension    = true;
     saveFileDialog1.CheckFileExists = false;
     saveFileDialog1.CheckPathExists = false;
     saveFileDialog1.DefaultExt      = "log";
     saveFileDialog1.Filter          = "Log files (*.log)|*.log|All files (*.*)|*.*";
     saveFileDialog1.CreatePrompt    = true;
     saveFileDialog1.OverwritePrompt = true;
     saveFileDialog1.SupportMultiDottedExtensions = true;
     saveFileDialog1.FileName         = $"Litrojan-{DateTime.Now.ToString("s")}.log";
     saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             File.WriteAllText(saveFileDialog1.FileName, logHost);
             UpdateTxtLogDisplay("Litrojan logs saved.", "LiUiLogs");
         }
         catch (Exception ex)
         {
             UpdateTxtLogDisplay(LitrojanUtils.ErrorFormatter("Litrojan logs cannot be saved.", ex), "LiUiLogs");
         }
     }
     else
     {
         UpdateTxtLogDisplay("Litrojan logs not saved.", "LiUiLogs");
     }
 }
示例#3
0
 public void AutoSave()
 {
     for (; ;)
     {
         LitrojanUtils.AutoIncrementalSave();
         Thread.Sleep(5000);
     }
 }
示例#4
0
文件: Form1.cs 项目: siaimes/Litrojan
        private void BtnSettExpo_Click(object sender, EventArgs e)
        {
            var p = tcm.ExportConfig(RunMode.Liconf, "", false);
            var s = $"tconf://{LitrojanUtils.Base64Encode(File.ReadAllText(p))}";

            TxtSettStatus.Text = s;
            Clipboard.SetText(s);
        }
示例#5
0
        public void TrojanStop()
        {
            infoDisp("Stopping Trojan instance.", "LiProcMgmt");
            if (TrojanStatus() == RunStatus.Stopped || TrojanStatus() == RunStatus.UnexpectedExit)
            {
                infoDisp("Trojan instance already stopped.", "LiProcMgmt");
                return;
            }

            bool bKilled = false;

            if ((proc?.Id).HasValue && proc.Id > 0)
            {
                try
                {
                    proc.Kill();
                    bKilled = true;
                }
                catch (Exception e)
                {
                    infoDisp(LitrojanUtils.ErrorFormatter("Failed to stop Trojan instance.", e), "LiProcMgmt");
                }
            }
            if (!bKilled)
            {
                infoDisp($"Trying wildcard kill.", "LiProcMgmt");

                // Main Target
                var killTarget = Process.GetProcessesByName(Path.GetFileName(exePath));
                BatchKill(killTarget);

                // Other Target
                foreach (string vName in GlobalVaribleHost.TrojanProcesses)
                {
                    killTarget = Process.GetProcessesByName(vName);
                    BatchKill(killTarget);
                }
            }

            _Status = RunStatus.Stopped;

            void BatchKill(Process[] Target)
            {
                foreach (Process p in Target)
                {
                    infoDisp($"Wildcard killing \"{p.MainModule.FileName}\"({p.Id}).", "LiProcMgmt");
                    try
                    {
                        p.Kill();
                    }
                    catch (Exception e)
                    {
                        infoDisp(LitrojanUtils.ErrorFormatter($"Failed to kill \"{p.MainModule.FileName}\"({p.Id}).", e), "LiProcMgmt");
                    }
                }
            }
        }
示例#6
0
文件: Form1.cs 项目: siaimes/Litrojan
 private void exitLitrojanToolStripMenuItem_Click(object sender, EventArgs e)
 {
     tsm.TryDisableLogSave();
     tsm.TryManualRestartTrojan();
     tpm.TrojanStop();
     UpdateTxtLogDisplay($"Litrojan ({GlobalVaribleHost.LitrojanVer}) Stopped.", "Litrojan");
     LitrojanUtils.AutoIncrementalSave();
     Environment.Exit(0);
 }
示例#7
0
文件: Form1.cs 项目: siaimes/Litrojan
 private void BtnLogCopy_Click(object sender, EventArgs e)
 {
     try
     {
         Clipboard.SetText(logHost);
         UpdateTxtLogDisplay("Litrojan logs copied.", "LiUiLogs");
     }
     catch (Exception ex)
     {
         UpdateTxtLogDisplay(LitrojanUtils.ErrorFormatter("Litrojan logs cannot be copied.", ex), "LiUiLogs");
     }
 }
示例#8
0
        public void TrojanStart(string confPath, RunMode Mode)
        {
            _confPath = confPath;
            _Mode     = Mode;
            infoDisp($"Starting Trojan instance as {Enum.GetName(typeof(RunMode), Mode)}.", "LiProcMgmt");
            if (TrojanStatus() == RunStatus.Running)
            {
                infoDisp("Trojan instance already running.", "LiProcMgmt");
                return;
            }
            else if (TrojanStatus() == RunStatus.Exceptional)
            {
                TrojanStop();
            }

            try
            {
                proc = new Process();
                proc.StartInfo.FileName        = exePath;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow  = true;
                proc.StartInfo.Arguments       = $"\"{confPath}\"";

                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;

                proc.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        infoDisp(e.Data, "TrojanCore");
                    }
                });
                proc.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        infoDisp(e.Data, "TrojanCore"); // well, stderr is used
                    }
                });

                proc.Start();
                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();
                _Status = RunStatus.Running;
            }
            catch (Exception e)
            {
                infoDisp(LitrojanUtils.ErrorFormatter($"Failed to start Trojan instance.", e), "LiProcMgmt");
                _Status = RunStatus.Exceptional;
            }
        }
示例#9
0
文件: Form1.cs 项目: siaimes/Litrojan
 public void LogicInit()
 {
     tcm = new TrojanConfigManager(LitrojanUtils.GetLocalPath("trojan.json"), UpdateTxtLogDisplay);
     tcm.LoadConfig();
     tpm = new TrojanProcessManager(LitrojanUtils.GetLocalPath("trojan.exe"), UpdateTxtLogDisplay);
     tsm = new TrojanSettingManager(LitrojanUtils.GetLocalPath("settings.json"), UpdateTxtLogDisplay, UpdateNoticeDisplay, tpm);
     tsm.LoadSetting();
     tnm = new TrojanNetworkManager(tcm.Config, UpdateNoticeDisplay);
     UpdateTheme(tsm.Setting.DarkUITheme);
     foreach (var i in panel1.Controls)
     {
         if (i is RadioButton rb && Enum.GetName(typeof(RunMode), tcm.Config.RunMode) == rb.Text)
         {
             rb.Checked = true;
             break;
         }
     }
 }
示例#10
0
文件: Form1.cs 项目: siaimes/Litrojan
        private void BtnSettImpo_Click(object sender, EventArgs e)
        {
            var s = Clipboard.GetText();

            if (!s.StartsWith("tconf://"))
            {
                s = TxtSettStatus.Text;
            }
            if (!s.StartsWith("tconf://"))
            {
                TxtSettStatus.Text = "Please paste share link here.";
                return;
            }
            var p = Path.GetTempFileName();

            s = LitrojanUtils.Base64Decode(s.Remove(0, "tconf://".Length));
            File.WriteAllText(p, s);
            tcm.LoadConfig(p);
        }
示例#11
0
        public void Ping()
        {
            notiDisp($"Pinging server [{conf.remote_addr}]:");
            long total = 0L;
            long min   = long.MaxValue;
            long max   = 0L;
            int  div   = 0;

            for (int i = 1; i <= 5; i++)
            {
                var succ = LitrojanUtils.PingHost(conf.remote_addr, out var t);

                if (succ)
                {
                    notiDisp($"Ping {i}/5. Reply from {conf.remote_addr}: time={t}ms.");
                    total += t;
                    div++;
                    min = Math.Min(t, min);
                    max = Math.Max(t, max);
                }
                else
                {
                    notiDisp($"Ping {i}/5. Request timed out.");
                }
            }
            notiDisp($"Ping statistics for {conf.remote_addr}:");
            if (div > 0)
            {
                notiDisp($"    Packets: Sent = 5, Received = {div}, Lost = {5 - div} ({100 * (5 - div) / 5}% loss),");
                notiDisp("Approximate round trip times in milli-seconds:");
                notiDisp($"    Minimum = {min}ms, Maximum = {max}ms, Average = {total / div}ms");
            }
            else
            {
                notiDisp($"    Packets: Sent = 5, Received = 0, Lost = 5 (100% loss),");
            }
        }
示例#12
0
文件: Form1.cs 项目: siaimes/Litrojan
 private void BtnLogClear_Click(object sender, EventArgs e)
 {
     LitrojanUtils.AutoIncrementalSave();
     logHost = "";
     TxtLogDisplay.Clear();
 }