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 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 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; } }