private void TryReadHeader(string fileName) { // sniff may not contain build var lastWriteTimeUtc = File.GetLastWriteTimeUtc(fileName); // non tiawps // sqlite_sequnce (name, seq) while seq is the amount of files // packets table (id integer primary key autoincrement, sess_id integer/*not used*, timestamp datetime, direction integer, opcode integer, data blob) // tiawps // header table (`key` string primary key, value string) // packets table (id integer primary key autoincrement, timestamp datetime, direction integer, opcode integer, data blob) try { ReadHeader(); // might be non tiawps } catch (SQLiteException) { var build = ClientVersion.GetVersion(lastWriteTimeUtc); using (var command = _connection.CreateCommand()) { command.CommandText = "SELECT timestamp FROM packets limit 1"; var dateTime = Convert.ToDateTime(command.ExecuteScalar()); build = ClientVersion.GetVersion(dateTime); } ClientVersion.SetVersion((ClientVersionBuild)build); ClientLocale.SetLocale("enUS"); } }
private void ReadHeader() { using (var command = _connection.CreateCommand()) { command.CommandText = "SELECT key, value FROM header;"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var key = reader.GetString(0); var value = reader.GetValue(1); if (string.Compare(key, "clientbuild", StringComparison.InvariantCultureIgnoreCase) == 0) { int build; if (int.TryParse(value.ToString(), out build)) { ClientVersion.SetVersion((ClientVersionBuild)build); ClientLocale.SetLocale("enUS"); } break; } } reader.Close(); } } }
static void SetLocale(string locale) { ClientLocale.SetLocale(locale); }
private static void Main(string[] args) { SetUpConsole(); var files = args.ToList(); if (files.Count == 0) { PrintUsage(); return; } // config options are handled in Misc.Settings Utilities.RemoveConfigOptions(ref files); if (!Utilities.GetFiles(ref files)) { EndPrompt(); return; } Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; if (Settings.UseDBC) { var startTime = DateTime.Now; DBC.DBC.Load(); var span = DateTime.Now.Subtract(startTime); Trace.WriteLine($"DBC loaded in { span.ToFormattedString() }."); } // Disable DB when we don't need its data (dumping to a binary file) if (!Settings.DumpFormatWithSQL()) { SQLConnector.Enabled = false; SSHTunnel.Enabled = false; } else { Filters.Initialize(); } SQLConnector.ReadDB(); var count = 0; foreach (var file in files) { SessionHandler.ZStreams.Clear(); if (Settings.ClientBuild != Enums.ClientVersionBuild.Zero) { ClientVersion.SetVersion(Settings.ClientBuild); } ClientLocale.SetLocale(Settings.ClientLocale.ToString()); try { var sf = new SniffFile(file, Settings.DumpFormat, Tuple.Create(++count, files.Count)); sf.ProcessFile(); } catch (IOException ex) { Console.WriteLine($"Can't process {file}. Skipping. Message: {ex.Message}"); } } if (!string.IsNullOrWhiteSpace(Settings.SQLFileName) && Settings.DumpFormatWithSQL()) { Builder.DumpSQL("Dumping global sql", Settings.SQLFileName, SniffFile.GetHeader("multi")); } SQLConnector.Disconnect(); SSHTunnel.Disconnect(); if (Settings.LogErrors) { Logger.WriteErrors(); } Trace.Listeners.Remove("ConsoleMirror"); EndPrompt(); }