// MaverickPipeHex.exe — le e escreve bytes crus no pipe, sem decodificar nada. // O MaverickPipeFrame decodificava UTF-8; "-31" pode ser ASCII literal ou parte de frame binario. // csc /nologo /optimize+ /out:MaverickPipeHex.exe MaverickPipeHex.cs // MaverickPipeHex.exe --pipe gfn-ccpipe --listen 10 // MaverickPipeHex.exe --pipe gfn-ccpipe --write-hex "2d 33 31" --listen 5 // MaverickPipeHex.exe --pipe gfn-ccpipe --write-hosts "ping" --listen 5 using System; using System.IO; using System.IO.Pipes; using System.Text; using System.Threading; internal static class MaverickPipeHex { static readonly StringBuilder LogBuf = new StringBuilder(); static string LogPath = "MaverickPipeHex.log"; static void Log(string m) { string line = DateTime.Now.ToString("HH:mm:ss.fff") + " " + m; LogBuf.AppendLine(line); Console.WriteLine(line); try { File.WriteAllText(LogPath, LogBuf.ToString()); } catch { } } static string Hex(byte[] b, int n) { var sb = new StringBuilder(); for (int i = 0; i < n; i++) sb.Append(b[i].ToString("X2")).Append(' '); return sb.ToString().Trim(); } static string Ascii(byte[] b, int n) { var sb = new StringBuilder(); for (int i = 0; i < n; i++) sb.Append(b[i] >= 32 && b[i] < 127 ? (char)b[i] : '.'); return sb.ToString(); } static bool PipeExists(string name) { try { foreach (string p in Directory.GetFiles(@"\\.\pipe\")) if (string.Equals(p.Substring(9), name, StringComparison.OrdinalIgnoreCase)) return true; } catch { } return false; } static byte[] ParseHex(string s) { var parts = s.Split(new[] { ' ', ',', '-' }, StringSplitOptions.RemoveEmptyEntries); var bytes = new byte[parts.Length]; for (int i = 0; i < parts.Length; i++) bytes[i] = Convert.ToByte(parts[i], 16); return bytes; } static int Main(string[] args) { string pipe = "gfn-ccpipe"; int listen = 10; int waitPipe = 30; string writeHex = null; string writeText = null; for (int i = 0; i < args.Length; i++) { if (args[i] == "--pipe" && i + 1 < args.Length) pipe = args[++i]; else if (args[i] == "--listen" && i + 1 < args.Length) int.TryParse(args[++i], out listen); else if (args[i] == "--wait" && i + 1 < args.Length) int.TryParse(args[++i], out waitPipe); else if (args[i] == "--write-hex" && i + 1 < args.Length) writeHex = args[++i]; else if (args[i] == "--write-text" && i + 1 < args.Length) writeText = args[++i]; } string dir = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); LogPath = Path.Combine(dir ?? ".", "MaverickPipeHex.log"); Log("=== MaverickPipeHex pipe=" + pipe + " listen=" + listen + "s"); Log("user=" + Environment.UserName + " session=" + System.Diagnostics.Process.GetCurrentProcess().SessionId); var end = DateTime.UtcNow.AddSeconds(waitPipe); while (!PipeExists(pipe) && DateTime.UtcNow < end) Thread.Sleep(200); if (!PipeExists(pipe)) { Log("pipe ausente."); return 2; } Log("pipe presente."); using (var client = new NamedPipeClientStream(".", pipe, PipeDirection.InOut, PipeOptions.None)) { try { client.Connect(2000); } catch (Exception ex) { Log("connect falhou: " + ex.GetType().Name + " " + ex.Message); return 3; } Log("conectado."); if (writeHex != null) { byte[] d = ParseHex(writeHex); client.Write(d, 0, d.Length); client.Flush(); Log("--> " + d.Length + " B " + Hex(d, d.Length)); } else if (writeText != null) { byte[] d = Encoding.UTF8.GetBytes(writeText); client.Write(d, 0, d.Length); client.Flush(); Log("--> " + d.Length + " B " + Hex(d, d.Length) + " | " + writeText); } else { Log("(modo escuta: nada enviado)"); } var buf = new byte[8192]; var deadline = DateTime.UtcNow.AddSeconds(listen); int total = 0; int chunks = 0; while (DateTime.UtcNow < deadline) { try { var task = client.ReadAsync(buf, 0, buf.Length); if (!task.Wait(300)) continue; int n = task.Result; if (n <= 0) { Log("servidor fechou."); break; } total += n; chunks++; Log("<-- " + n + " B " + Hex(buf, Math.Min(n, 64))); Log(" ascii: " + Ascii(buf, Math.Min(n, 64))); if (total > 20000) break; } catch (Exception ex) { Log("read: " + ex.GetType().Name); break; } } Log("fim. chunks=" + chunks + " bytes=" + total); } return 0; } }