public ProxyUDPSocketService(IPEndPoint src, IPEndPoint dest, string output, string format, bool modify) : base(src) { this.src = src; this.dest = dest; this.modify = modify; try { if (format.Equals("asciibin")) { writer = new HexLogWriter(); writer.Open(output, "w"); } else if (format.Equals("json")) { writer = new JSONLogWriter(); writer.Open(output, "w"); } } catch (System.IO.IOException ioe) { Console.WriteLine("Error opening output {0} for writing (logging disabled): {1}", output, ioe.Message); } }
public int ProcessData() { int ret = SetDecryptor(decrypto.dll); if (ret != 0) { return(ret); } if (decrypto.format.Equals("json")) { var output = new IntPtr(); var output_size = 0; string sender = ""; reader = new JSONLogWriter(); reader.Open(decrypto.input, "r"); Transmissions trans = reader.ReadTransmission(); foreach (LogEvent e in trans.LogEventList) { try { if (e.sender == CLIENT) { sender = "client"; } else { sender = "server"; } Console.WriteLine("sender: {0} packet: {1} length: {2}", sender, e.count, e.data.Length); Decrypt.Decrypt(e.sender, e.data, e.data.Length, e.count, ref output, ref output_size); byte[] decrypted = new byte[output_size]; Marshal.Copy(output, decrypted, 0, output_size); Console.WriteLine("\nAfter decrypt: {0}", Encoding.ASCII.GetString(decrypted)); Console.WriteLine("--------------------------------------"); if (writer != null) { writer.LogTransmission(decrypted, sender, e.count); } } finally { if (output != IntPtr.Zero) { Marshal.FreeCoTaskMem(output); } } } } return(0); }
public DecryptFileProcessor(DecryptOptions decrypto) { this.decrypto = decrypto; if (!this.decrypto.output.Equals("")) { if (this.decrypto.outputformat.Equals("json")) { writer = new JSONLogWriter(); } else if (this.decrypto.outputformat.Equals("asciibin")) { writer = new HexLogWriter(); } else { Console.WriteLine("Error only asciibin and json supported!"); return; } writer.Open(this.decrypto.output, "w"); } }
static void Main(string[] args) { bool show_help = false; DecryptFileProcessor dfp = null; DecryptOptions decrypto = new DecryptOptions(); var p = new OptionSet() { { "d|dll=", "dll to be used to decrypt packets, must export decrypt() and init() functions.", v => decrypto.dll = v }, { "i|input=", "logfile where raw data was captured.", v => decrypto.input = v }, { "f|format=", "logfile format for how the data was captured.", v => decrypto.format = v }, { "o|output=", "Where to store the decrypted output.", v => decrypto.output = v }, { "of|outputformat=", "Output format (json|asciibin).", v => decrypto.outputformat = v }, { "h|?|help", "show this message and exit", v => show_help = v != null }, }; p.Parse(args); if (show_help) { ShowHelp(p, null); } if (decrypto.input == null) { ShowHelp(p, "input is required."); } else if (decrypto.output == null) { ShowHelp(p, "output is required."); } else if (decrypto.format == null) { ShowHelp(p, "format is required."); } if (decrypto.dll != null) { dfp = new DecryptFileProcessor(decrypto); dfp.ProcessData(); } else { IULogWriter logger = null; if (decrypto.format.Equals("json")) { logger = new JSONLogWriter(); logger.Open(decrypto.input, "r"); Transmissions trans = logger.ReadTransmission(); foreach (LogEvent e in trans.LogEventList) { Console.WriteLine("{0} {1} {2}", e.sender, e.count, Encoding.ASCII.GetString(e.data)); } } } }