Exemplo n.º 1
0
        /*
         * Basic check to detect and tag opcode that doesn't contains any string nor array (static length)
         */
        public void StaticSizeCheck()
        {
            Parallel.ForEach(Directory.GetFiles(PATH + VERSION + Path.DirectorySeparatorChar, "*" + SPLITTED_LOGS_EXTENSION, SearchOption.AllDirectories), (file) =>
            {
                var isSameSize      = true;
                var initialeSize    = 0;
                var reader          = new PacketLogFile(file);
                string opcode       = Path.GetFileName(file);
                int numberOfPackets = 0;
                initialeSize        = reader.Messages.ElementAt(0).Payload.Count;
                Parallel.ForEach(reader.Messages, (message) => {
                    numberOfPackets++;
                    if (message.Payload.Count != initialeSize)
                    {
                        isSameSize = false;
                    }
                });

                // If number of packet < 50, we considere the we don't have enought data to do anything
                if (isSameSize && numberOfPackets > MINIMUM_PACKET_NUMBER)
                {
                    //Debug.WriteLine("Opcode: " + opcode + " is static size: " +initialeSize + "; nbpackets: "+numberOfPackets);
                    File.WriteAllText(PATH + VERSION + Path.DirectorySeparatorChar + opcode + DEF_EXTENSION, initialeSize.ToString());
                }
                if (numberOfPackets < MINIMUM_PACKET_NUMBER)
                {
                    //Debug.WriteLine("Uncommon packet: Opcode: " + opcode + " ;nbpackets: " + numberOfPackets);
                    File.WriteAllText(PATH + VERSION + Path.DirectorySeparatorChar + opcode + IGNORE_EXTENSION, "Not enough data, only " + numberOfPackets + " packets");
                }
            });
        }
Exemplo n.º 2
0
 /*
  * Create a different log file for every opcode found.
  */
 public void SplitLogsIntoSeparatorOpcodeFiles()
 {
     foreach (var file in Directory.GetFiles(PATH + Path.DirectorySeparatorChar + VERSION, "*" + LOGS_EXTENSION, SearchOption.AllDirectories))
     {
         var reader = new PacketLogFile(file);
         foreach (var message in reader.Messages)
         {
             var writer = GetOrInitializeWriter(message.OpCode);
             writer.Append(message);
         }
     }
     CloseReaders();
 }
Exemplo n.º 3
0
        public void DynamicSizeCheck()
        {
            var path = PATH + VERSION + Path.DirectorySeparatorChar;

            Parallel.ForEach(Directory.GetFiles(path, "*" + SPLITTED_LOGS_EXTENSION, SearchOption.AllDirectories), (file) =>
            {
                var filename = Path.GetFileName(file);
                if (File.Exists(path + filename + DEF_EXTENSION) || File.Exists(path + filename + IGNORE_EXTENSION))
                {
                    return;
                }
                var reader = new PacketLogFile(file);
                foreach (var message in reader.Messages)
                {
                    var structure = FindStruc(message);
                }
            });
        }
Exemplo n.º 4
0
        public static List <Message> LoadLogFromFile(string filename)
        {
            var plf         = new PacketLogFile(filename);
            var messageList = plf.Messages.ToList();

            if (messageList.ElementAt(0).OpCode != 19900)
            {
                throw new Exception("Analysing a log without starting by the beginning is meaningless");
            }
            if (messageList.ElementAt(0).Payload.Count == 30) // Old log, need to remove the last 2 bytes
            {
                Console.WriteLine("Old log detected, removing the last 2 bytes");
                Parallel.ForEach(messageList, message =>
                {
                    message.Data = new ArraySegment <byte>(message.Data.Array, 0, message.Data.Count - 2);
                });
            }
            return(messageList);
        }
Exemplo n.º 5
0
        private void OpenPacketLogMenuItem_Click(object sender, EventArgs e)
        {
            if (OpenPacketLogFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            _teraSniffer.Enabled = false;

            var log = new PacketLogFile(OpenPacketLogFileDialog.FileName);

            var server = new Server(string.Format("[{0}] Packet Log", log.Header.Region), log.Header.Region ?? "EU", null);

            HandleNewConnection(server);

            foreach (var message in log.Messages)
            {
                HandleMessageReceived(message);
            }
        }