public async Task StartAsync(string parameters) { await Task.Yield(); EnsureExists(); Stop(); //单实例单进程 _process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, FileName = FFmpegExePath, Arguments = parameters }, EnableRaisingEvents = true }; _process.Exited += (o, e) => { _process.Dispose(); ProcessExited?.Invoke(this, new EventArgs()); }; _process.Start(); await ReadOutputAsync(_process.StandardError); }
/// <summary> /// Initializes a new instance of the <see cref="AProcessSharp" /> class. /// </summary> /// <param name="native">The native process.</param> /// <param name="type">The type of memory being manipulated.</param> public AProcessSharp(System.Diagnostics.Process native, AMemoryType type) { native.EnableRaisingEvents = true; native.Exited += (s, e) => { ProcessExited?.Invoke(s, e); HandleProcessExiting(); }; Native = native; Handle = AMemoryHelper.OpenProcess(ProcessAccessFlags.AllAccess, Native.Id); switch (type) { case AMemoryType.Local: Memory = new ALocalProcessMemory(Handle); break; case AMemoryType.Remote: Memory = new AExternalProcessMemory(Handle); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } native.ErrorDataReceived += OutputDataReceived; native.OutputDataReceived += OutputDataReceived; ThreadFactory = new AThreadFactory(this); ModuleFactory = new AModuleFactory(this); MemoryFactory = new AMemoryFactory(this); WindowFactory = new AWindowFactory(this); }
public virtual int ExitProcess(uint ExitCode) { ProcessExited?.Invoke(this, (int)ExitCode); _exited = true; return((int)DEBUG_STATUS.BREAK); }
/// <summary> /// Initializes a new instance of the <see cref="MemoryBase" /> class. /// </summary> /// <param name="proc">The process.</param> /// <remarks>Created 2012-02-15</remarks> protected MemoryBase(Process proc) { if (proc.HasExited) { throw new AccessViolationException("Process: " + proc.Id + " has already exited. Can not attach to it."); } // Process.EnterDebugMode(); // Good to set this too if ure using events. proc.EnableRaisingEvents = true; // Since people tend to not realize it exists, we make sure to handle it. proc.Exited += (s, e) => { ProcessExited?.Invoke(s, e); HandleProcessExiting(); }; Process = proc; proc.ErrorDataReceived += OutputDataReceived; proc.OutputDataReceived += OutputDataReceived; Handle = NativeMethods.OpenProcess(ProcessAccessFlags.AllAccess, false, proc.Id); ImageBase = Process.MainModule.BaseAddress; // Create instances of the factories Factories = new List <IFactory>(); Factories.AddRange( new IFactory[] { Assembly = new AssemblyFactory(this), Memory = new MemoryFactory(this), Modules = new ModuleFactory(this), Threads = new ThreadFactory(this), Windows = new WindowFactory(this), Patches = new PatchManager(this) }); }
private void ProcessInstance_Exited(object sender, EventArgs e) { _processInstance.OutputDataReceived -= ProcessInstance_OutputDataReceived; _processInstance.ErrorDataReceived -= ProcessInstance_ErrorDataReceived; OnExited(); ProcessExited?.Invoke(); }
public void Initialize() { if (initialized) { return; } cmd = Command.Run(executable, args) .RedirectTo(outputStream) .RedirectStandardErrorTo(errorStream); Task = System.Threading.Tasks.Task.Run(async() => { try { var result = await cmd.Task.ConfigureAwait(false); return(new CommandResultAdapter(result) as IShellResult); } finally { ProcessExited?.Invoke(this, EventArgs.Empty); } }); initialized = true; }
/// <summary> /// 构造函数。将会建立 Process 对象,并赋给它一些值。 /// </summary> /// <param name="ExecPath"></param> /// <param name="ExecArguments"></param> /// <param name="description"></param> /// <param name="createNoWindow"></param> public AIProcess(string ExecPath, string ExecArguments, string description, bool createNoWindow) { proc = new Process(); Description = description ?? "Process"; proc.StartInfo.FileName = ExecPath; proc.StartInfo.Arguments = ExecArguments; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.CreateNoWindow = createNoWindow; proc.EnableRaisingEvents = true; //尝试运行一下该 proc,以证明其有效性。 proc.Start(); if (!proc.HasExited) { proc.Kill(); } //当proc有行输出的时候,做出反应 proc.OutputDataReceived += (sender, e) => { // 首先等待主程序开启 AllowOutputAndWait。 allowMoveHandle.WaitOne(); // 主程序开启了 AllowOutputAndWait 之后,解除 AllowOutputAndWait 中的阻塞。(所以,要不就是主程序等进程,要不就是进程等主程序。两个阻塞不可能同时发生,一个阻塞开始前必然解除另一个阻塞) outputWaitHandle.Set(); // 因为进程还有可能继续给出输出,所以解除了之后要重新锁上 allowMoveHandle.Reset(); if (proc.HasExited) { return; } if (e.Data == null) { } else { LineProcess?.Invoke(e.Data); } }; // 当 proc 退出时,作出反应 proc.Exited += (sender, e) => { ProcStarted = false; try { proc.CancelOutputRead(); } catch (InvalidOperationException) { Trace.TraceWarning("取消 " + Description + " 的输出流错误,可能原来未开启,或这一操作已经完成。"); } ProcessExited?.Invoke(); }; }
internal static void Detach() { MemorySharp?.Dispose(); MemorySharp = null; ProcessExited?.Invoke(); OffsetScanner.Reset(); }
private void MonitorForExit(object o) { if (HasExited()) { _exitMonitorTimer.Dispose(); ProcessExited?.Invoke(this, null); } }
private void Timer_Tick(object sender, EventArgs e) { if (Process.HasExited) { Close(); ProcessExited?.Invoke(); } }
void ICorDebugManagedCallback.ExitProcess(ICorDebugProcess process) { if (DebugOutput) { Console.WriteLine("info: ExitProcess"); } ProcessExited?.Invoke(this, new ProcessExitedEventArgs(process)); process.Continue(0); }
private void Process_Exited(object sender, EventArgs e) { if (_configurationManager.RestoreRealmlist) { RestoreRealmlist(_path); } ProcessExited?.Invoke(sender, e); }
/// <summary> /// 进程结束了,释放资源 /// </summary> /// <param name="process"></param> protected virtual void OnProcessExited(Process process) { ProcessExited?.Invoke(this, new ProcessEventArgs(process)); if (process.StartInfo.RedirectStandardOutput) { process.CancelErrorRead(); process.CancelOutputRead(); } try { currentProcess?.Dispose(); } catch { } }
void process_Exited(object sender, EventArgs e) { Process process = (Process)sender; if (Process == process) { Clear(process); process?.Dispose(); ProcessExited?.Invoke(this, e); Process = null; } }
public static void Listen() { var session = new TraceEventSession(KernelTraceEventParser.KernelSessionName); session.StopOnDispose = true; session.EnableKernelProvider(KernelTraceEventParser.Keywords.ImageLoad | KernelTraceEventParser.Keywords.Process); session.Source.Kernel.ProcessStart += (ProcessTraceData data) => { ProcessCreated?.Invoke(data); }; session.Source.Kernel.ProcessStop += (ProcessTraceData data) => { ProcessExited?.Invoke(data); }; new Thread(() => session.Source.Process()).Start(); }
// Called to start the launched process in a secondary thread private void Start() { try { // Attempt to launch the executable Logger.Log($"[Launcher] Launching: {process.StartInfo.FileName} {process.StartInfo.Arguments}"); process.Start(); // Begin reading from process's stdout/err process.BeginOutputReadLine(); process.BeginErrorReadLine(); // Wait for executable to exit Logger.Log("[Launcher] Process Started"); process.WaitForExit(); Running = false; // Prep exit event args ProcessExitedArgs exitArgs = new ProcessExitedArgs(); if (Error != null) { exitArgs.Errored = true; exitArgs.Error = Error; } // Emit exit event ProcessExited?.Invoke(this, exitArgs); } catch (Exception ex) { Running = false; Error = ex; Logger.Log($"[Launcher] Process failed to start: {ex.Message}"); // Prep exit event args ProcessExitedArgs exitArgs = new ProcessExitedArgs(); exitArgs.Errored = true; exitArgs.Error = Error; // Emit exit event ProcessExited?.Invoke(this, exitArgs); } }
public static bool TryObserveProcessExit(int processId) { try { var process = Process.GetProcessById(processId); Log.Debug("Observing process {Id} for exit", processId); EventHandler processOnExited = null; processOnExited = (sender, args) => { ProcessExited?.Invoke(null, processId); process.Exited -= processOnExited; }; process.Exited += processOnExited; return(true); } catch (Exception e) { Log.Error(e, "Failed to observe process {Id}", processId); return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="ProcessSharp" /> class. /// </summary> /// <param name="native">The native process.</param> public ProcessSharp(System.Diagnostics.Process native) { native.EnableRaisingEvents = true; native.Exited += (s, e) => { ProcessExited?.Invoke(s, e); HandleProcessExiting(); }; Native = native; Handle = MemoryHelper.OpenProcess(ProcessAccessFlags.AllAccess, Native.Id); native.ErrorDataReceived += OutputDataReceived; native.OutputDataReceived += OutputDataReceived; ThreadFactory = new ThreadFactory(this); ModuleFactory = new ModuleFactory(this); MemoryFactory = new MemoryFactory(this); WindowFactory = new WindowFactory(this); }
public static void Remap() { Process javaProcess = new Process(); javaProcess.StartInfo.FileName = WorkingFile.Java; javaProcess.StartInfo.Arguments = string.Join("", $" -jar {WorkingFile.SpecialSource}", $" --in-jar {WorkingFile.SourceJar}", $" --out-jar {WorkingFile.RemappedJar}", $" --srg-in {WorkingFile.MappingInfoTsrg}", " --kill-lvt --progress-interval 1"); //= $" -jar {WorkingFile.SpecialSource} --in-jar {WorkingFile.SourceJar} --out-jar {WorkingFile.RemappedJar} --srg-in {WorkingFile.MappingInfoTsrg} --kill-lvt --progress-interval 1"; javaProcess.StartInfo.UseShellExecute = false; javaProcess.StartInfo.RedirectStandardOutput = true; javaProcess.StartInfo.CreateNoWindow = true; javaProcess.OutputDataReceived += (sender, e) => { OutputDataReceived.Invoke(sender, e); }; javaProcess.Start(); javaProcess.BeginOutputReadLine(); javaProcess.WaitForExit(); ProcessExited.Invoke(javaProcess, new EventArgs()); javaProcess.Dispose(); }
public async Task <int> RunAsync(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } string fullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); bool isExists = await Task.Run(() => File.Exists(fullName)); if (!isExists) { throw new FileNotFoundException($"{fullName} file not exist"); } try { Process process = new Process(); process.StartInfo.FileName = fullName; process.EnableRaisingEvents = true; process.Exited += (sender, e) => { ProcessExited?.Invoke(sender, e); }; process.Start(); return(process.Id); } catch (Exception ex) { Console.WriteLine(ex.Message); return(-1); } }
public ExProcess(Process process, MemoryAccessType memoryAccessType) { Process = process; Handle = Kernel32.OpenProcess(ProcessAccessFlags.AllAccess, false, process.Id); Handle.Validate(true); switch (memoryAccessType) { case MemoryAccessType.Local: Memory = new ProcessMemoryLocal(Handle); break; case MemoryAccessType.Remote: Memory = new ProcessMemoryRemote(Handle); break; default: throw new NotSupportedException(); } Process.EnableRaisingEvents = true; Process.Exited += (s, e) => ProcessExited?.Invoke(this); }
void OnProcessExited(ProcessExitedEventArgs e) { ProcessExited?.Invoke(this, e); }
protected virtual void OnProcessExited() { ProcessExited?.Invoke(this, new ExecutableEventArgs(this)); }
private void TriggerProcessExitEventUnsafe() { ProcessExited?.Invoke(this, EventArgs.Empty); }
protected virtual void OnProcessExited() { ProcessExited?.Invoke(this, EventArgs.Empty); }
protected virtual void OnProcessExited() { ProcessExited?.Invoke(this, new EventArgs()); }
void proc_Exited(object sender, EventArgs e) { ProcessExited?.Invoke(this, new EventArgs()); }
private void OnProcessExited(object sender, int exitCode) { ProcessExited?.Invoke(this, null); }
private static void P_Exited(object sender, EventArgs e) { ProcessExited?.Invoke(sender, e); }
protected void FireProcessExited() { ProcessExited?.Invoke(this, EventArgs.Empty); }