// MaverickPipeOwner.exe — descobre o DONO do pipe pelo API do Windows. // Conecta no pipe e chama GetNamedPipeServerProcessId: retorna o PID do servidor. // csc /nologo /optimize+ /out:MaverickPipeOwner.exe MaverickPipeOwner.cs // MaverickPipeOwner.exe // MaverickPipeOwner.exe --pipe gfn-ccjsonrpc using System; using System.Diagnostics; using System.IO.Pipes; using System.Runtime.InteropServices; using System.Text; using System.Threading; internal static class MaverickPipeOwner { [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetNamedPipeServerProcessId(IntPtr pipe, out uint serverProcessId); [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetNamedPipeServerSessionId(IntPtr pipe, out uint serverSessionId); static string Describe(uint pid) { try { Process p = Process.GetProcessById((int)pid); string path = ""; DateTime started = DateTime.MinValue; try { path = p.MainModule.FileName; } catch { } try { started = p.StartTime; } catch { } p.Dispose(); return string.Format("{0} (PID {1}) iniciado {2:HH:mm:ss} {3}", p.ProcessName, pid, started, path); } catch (Exception ex) { return string.Format("(PID {0} — nao foi possivel abrir: {1})", pid, ex.GetType().Name); } } static void Probe(string pipe) { Console.WriteLine("== " + pipe); NamedPipeClientStream client = null; try { client = new NamedPipeClientStream(".", pipe, PipeDirection.InOut, PipeOptions.None); client.Connect(2000); } catch (TimeoutException) { Console.WriteLine(" nao conectou: timeout (instancia ocupada ou inexistente)"); if (client != null) client.Dispose(); return; } catch (Exception ex) { Console.WriteLine(" nao conectou: " + ex.GetType().Name + " " + ex.Message); if (client != null) client.Dispose(); return; } try { IntPtr h = client.SafePipeHandle.DangerousGetHandle(); uint spid, ssid; bool okPid = GetNamedPipeServerProcessId(h, out spid); int errPid = Marshal.GetLastWin32Error(); bool okSid = GetNamedPipeServerSessionId(h, out ssid); if (okPid) Console.WriteLine(" SERVIDOR: " + Describe(spid)); else Console.WriteLine(" GetNamedPipeServerProcessId falhou err=" + errPid); if (okSid) Console.WriteLine(" sessao do servidor: " + ssid); } finally { client.Dispose(); } Console.WriteLine(); } static int Main(string[] args) { Console.WriteLine("=== MaverickPipeOwner ==="); Console.WriteLine("user=" + Environment.UserName + " session=" + Process.GetCurrentProcess().SessionId); Console.WriteLine(); string[] pipes; string only = null; for (int i = 0; i < args.Length; i++) if (args[i] == "--pipe" && i + 1 < args.Length) only = args[++i]; if (only != null) pipes = new[] { only }; else pipes = new[] { "gfn-ccjsonrpc", "gfn-ccpipe", "NvMessageBusBroadcast", "NvMessageBusBroadcastNVIDIA.Display.Driver", "NvWksServiceRivermaxDisplayPipe", }; foreach (string p in pipes) Probe(p); return 0; } }