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); }
private void button1_Click(object sender, EventArgs e) { string ifn = Directory.GetCurrentDirectory() + "\\" + "A9.dump"; if (!File.Exists(ifn)) { MessageBox.Show("File " + ifn + " not found!"); return; } GenericReader gr = new GenericReader(ifn, Encoding.ASCII); string error_log = "errors.txt"; StreamWriter swe = new StreamWriter(error_log); string database_log = "data.txt"; StreamWriter data = new StreamWriter(database_log); string ofn = "A9_out.txt"; StreamWriter sw = new StreamWriter(ofn); sw.AutoFlush = true; swe.AutoFlush = true; data.AutoFlush = true; // A9 packet structure: // uint count (4 bytes) // byte 0 (unk, can be 1, 2 also...) (1 byte) // for(uint i = 0; i < count; i++) // { // byte updatetype (all below for UPDATETYPE_VALUES) (1 byte) // ulong guid(packed) (2-9 bytes) // byte count_of_blocks (1 byte) // uint*count_of_blocks bitmask array (4*count_of_blocks bytes) // for each non zero bit in bitmask exist block of data (uint/float) (4 bytes) // } //MessageBox.Show(br.BaseStream.Position.ToString() + " " + br.BaseStream.Length.ToString()); try { while (gr.PeekChar() >= 0) { uint result = ParsePacket(gr, sw, swe, data); if (result == 0 || result == 1) packet++; } } catch(Exception exc) { MessageBox.Show(exc.ToString()); } sw.Close(); swe.Close(); data.Close(); MessageBox.Show("Done!", "A9 parser", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false); //MessageBox.Show(br.BaseStream.Position.ToString() + " " + br.BaseStream.Length.ToString()); gr.Close(); }