Esempio n. 1
0
        private void BinaryDump(string fileName, ICollection <Packet> packets)
        {
            Trace.WriteLine(string.Format("{0}: Copying {1} packets to .pkt format...", _logPrefix, packets.Count));

            try
            {
                BinaryPacketWriter.Write(SniffType.Pkt, fileName, Encoding.ASCII, packets);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.GetType());
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }
Esempio n. 2
0
        private void BinaryDump()
        {
            Trace.WriteLine(string.Format("{0}: Copying {1} packets to .pkt format...", _logPrefix, _packets.Count));
            var dumpFileName = Path.ChangeExtension(_fileName, null) + "_excerpt.pkt";

            try
            {
                BinaryPacketWriter.Write(SniffType.Pkt, dumpFileName, Encoding.ASCII, _packets);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.GetType());
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }
 private void BinaryDump(string fileName, ICollection <Packet> packets)
 {
     Trace.WriteLine($"{_logPrefix}: Copying {packets.Count} packets to .pkt format...");
     BinaryPacketWriter.Write(SniffType.Pkt, fileName, Encoding.ASCII, packets);
 }
Esempio n. 4
0
        private static void ReadFile(string file, string[] filters, string[] ignoreFilters, int packetNumberLow, int packetNumberHigh, int packetsToRead, DumpFormatType dumpFormat, int threads, bool sqlOutput, bool prompt)
        {
            string fileName = Path.GetFileName(file);
            Console.WriteLine("{0}: Opening file", fileName);
            Console.WriteLine("{0}: Reading packets...", fileName);

            try
            {
                var packets = Reader.Read(file, filters, ignoreFilters, packetNumberLow, packetNumberHigh, packetsToRead, (dumpFormat == DumpFormatType.SummaryHeader));
                if (packets.Count <= 0)
                {
                    Console.WriteLine("{0}: Packet count is 0", fileName);
                    return;
                }

                if (dumpFormat == DumpFormatType.Bin || dumpFormat == DumpFormatType.Pkt)
                {
                    SniffType format = dumpFormat == DumpFormatType.Bin ? SniffType.Bin : SniffType.Pkt;
                    var fileExtension = dumpFormat.ToString().ToLower();
                    Console.WriteLine("{0}: Copying {1} packets to .{2} format...", fileName, packets.Count, fileExtension);

                    var dumpFileName = Path.ChangeExtension(file, null) + "_excerpt." + fileExtension;
                    var writer = new BinaryPacketWriter(format, dumpFileName, Encoding.ASCII);
                    writer.Write(packets);
                }
                else
                {
                    var numberOfThreads = threads != 0 ? threads.ToString() : "a recommended number of";

                    Console.WriteLine("{0}: Assumed version: {1}", fileName, ClientVersion.Build);
                    Console.WriteLine("{0}: Parsing {1} packets with {2} threads...", fileName, packets.Count, numberOfThreads);

                    Statistics.Total = (uint)packets.Count;

                    Statistics.StartTime = DateTime.Now;
                    var outFileName = Path.ChangeExtension(file, null) + "_parsed";
                    var outLogFileName = outFileName + ".txt";
                    var outSqlFileName = outFileName + ".sql";

                    SQLStore.Initialize(outSqlFileName, sqlOutput);

                    bool headersOnly = (dumpFormat == DumpFormatType.TextHeader || dumpFormat == DumpFormatType.SummaryHeader);
                    if (threads == 0) // Number of threads is automatically choosen by the Parallel library
                        packets.AsParallel().SetCulture().ForAll(packet => Handler.Parse(packet, headersOnly));
                    else
                        packets.AsParallel().SetCulture().WithDegreeOfParallelism(threads).ForAll(packet => Handler.Parse(packet, headersOnly));

                    Console.WriteLine("{0}: Writing data to file...", fileName);

                    if (sqlOutput)
                    {
                        // Experimental, will remove
                        SQLStore.WriteData(Builder.QuestTemplate());
                        SQLStore.WriteData(Builder.NpcTrainer());
                        SQLStore.WriteData(Builder.NpcVendor());
                        SQLStore.WriteData(Builder.NpcTemplate());
                        SQLStore.WriteData(Builder.GameObjectTemplate());
                    }

                    SQLStore.WriteToFile();
                    if (dumpFormat != DumpFormatType.None)
                        Handler.WriteToFile(packets, outLogFileName);

                    Statistics.EndTime = DateTime.Now;

                    Console.WriteLine(Statistics.Stats(fileName));
                    Console.WriteLine("{0}: Saved file to '{1}'", fileName, outLogFileName);
                    Console.WriteLine();
                    Statistics.Reset();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType());
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                EndPrompt(prompt);
            }
        }