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); } }
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"); } }
public void AutoSave() { for (; ;) { LitrojanUtils.AutoIncrementalSave(); Thread.Sleep(5000); } }
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); }
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"); } } } }
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); }
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"); } }
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; } }
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; } } }
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); }
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),"); } }
private void BtnLogClear_Click(object sender, EventArgs e) { LitrojanUtils.AutoIncrementalSave(); logHost = ""; TxtLogDisplay.Clear(); }