private static bool ParseFile(FileInfo f) { DateTime filestarttime = DateTime.Now; Console.Write("Parsing {0}...", f.Name); SQLiteConnection connection = new SQLiteConnection("Data Source=" + f.FullName); SQLiteCommand command = new SQLiteCommand(connection); connection.Open(); command.CommandText = "SELECT id, sess_id, timestamp, direction, opcode, data FROM packets ORDER BY id;"; command.Prepare(); SQLiteDataReader reader = command.ExecuteReader(); MemoryStream ms = new MemoryStream(); while (reader.Read()) { uint id = (uint)reader.GetInt32(0); uint sess_id = (uint)reader.GetInt32(1); string timestamp = reader.GetString(2); byte direction = reader.GetByte(3); ushort opcode = (ushort)reader.GetInt32(4); if (opcode > 1054) { Console.WriteLine(opcode); throw new Exception("Test"); } byte[] data_ = (byte[])reader.GetValue(5); uint size = sizeof(uint) + sizeof(uint) + (uint)timestamp.Length + 1 + sizeof(byte) + sizeof(ushort) + (uint)data_.Length; byte[] id_arr = BitConverter.GetBytes(id); byte[] sessid_arr = BitConverter.GetBytes(sess_id); byte[] time_arr = Encoding.ASCII.GetBytes(timestamp); byte[] op = BitConverter.GetBytes(opcode); byte[] sz = BitConverter.GetBytes(size); ms.Write(sz, 0, sz.Length); ms.Write(id_arr, 0, id_arr.Length); ms.Write(sessid_arr, 0, sessid_arr.Length); ms.Write(time_arr, 0, time_arr.Length); ms.WriteByte(0); ms.WriteByte(direction); ms.Write(op, 0, op.Length); ms.Write(data_, 0, data_.Length); } reader.Close(); connection.Close(); GenericReader gr = new GenericReader(ms, Encoding.ASCII); gr.BaseStream.Position = 0; string error_log = f.FullName + ".errors.txt"; StreamWriter swe = new StreamWriter(error_log); string database_log = f.FullName + ".data.txt"; StreamWriter data = new StreamWriter(database_log); string hex_log = f.FullName + ".hex.log"; StreamWriter hex = new StreamWriter(hex_log); string ofn = f.FullName + ".data_out.txt"; StreamWriter sw = new StreamWriter(ofn); sw.AutoFlush = true; swe.AutoFlush = true; data.AutoFlush = true; hex.AutoFlush = true; while (gr.PeekChar() >= 0) { //try //{ if (ParseHeader(gr, sw, swe, data, hex)) packet++; //} //catch (Exception exc) //{ // MessageBox.Show(exc.ToString()); // swe.WriteLine("error in pos " + gr.BaseStream.Position.ToString("X16")); //} } // clear objects list... m_objects.Clear(); sw.Close(); swe.Close(); data.Close(); hex.Close(); gr.Close(); TimeSpan fileworktime = DateTime.Now - filestarttime; Console.WriteLine(" Parsed in {0}", fileworktime); return true; }