public static Packet ChangePacketClass(Packet pak, float newVersion)
        {
            LogPacketData packetData = GetPacketData(newVersion, pak.Code, pak.Direction);
            if (packetData != null && pak.GetType().Equals(packetData.Type))
            {
                pak.Attribute = packetData.Attribute;
                return pak;
            }

            Packet newPacket = CreatePacket(packetData, (int)pak.Length);
            newPacket.CopyFrom(pak);
            return newPacket;
        }
Пример #2
0
        /// <summary>
        /// Appends the packet data.
        /// </summary>
        /// <param name="text">The text to append packet data to.</param>
        /// <param name="pak">The paket.</param>
        /// <param name="stats">The current stats.</param>
        /// <param name="showPacketSequence">If set to <c>true</c> shows packet sequences.</param>
        /// <param name="baseTime">The base time.</param>
        /// <param name="timeDiff">If set to <c>true</c> shows packet time delta.</param>
        private void AppendPacketData(TextWriter text, Packet pak, ref LogDataStatistics stats, bool showPacketSequence, ref TimeSpan baseTime, bool timeDiff)
        {
            int pakIndex = 0;
            if (showPacketSequence)
            {
                if (pak.Protocol == ePacketProtocol.TCP)
                {
                    if (pak.Direction == ePacketDirection.ClientToServer)
                    {
                        pakIndex = ++stats.PacketsCountOutTCP;
                    }
                    else
                    {
                        pakIndex = ++stats.PacketsCountInTCP;
                    }
                }
                else if (pak.Protocol == ePacketProtocol.UDP)
                {
                    if (pak.Direction == ePacketDirection.ClientToServer)
                    {
                        pakIndex = ++stats.PacketsCountOutUDP;
                    }
                    else
                    {
                        pakIndex = ++stats.PacketsCountInUDP;
                    }
                }
                else
                {
                    throw new ArgumentException("Unknown packet protocol: " + (int) pak.Protocol);
                }
            }

            ++stats.PacketsCount;

            if (showPacketSequence)
            {
                text.Write("{0}:{1,-5} ", pak.Protocol, pakIndex);
            }

            // main description
            pak.ToHumanReadableString(text, baseTime, mnuPacketFlags.Checked);
            // if use WriteLine as \r\n then packets will have not correctly index in stream.
            // because after stream will be loaded in RichTextBox it will have lines delemiter as set in RichTextBox
            // Maybe need to set stream.NewLine
            text.WriteLine();

            if (timeDiff)
            {
                baseTime = pak.Time;
            }
        }
Пример #3
0
        private void UpdateInstantParseTab()
        {
            float ver;
            Util.ParseFloat(instantVersion.Text, out ver, -1);

            Packet pak = new Packet(0);
            int code;
            if (!Util.ParseInt(instantCode.Text, out code))
                code = 0;
            pak.Code = (byte)code;
            bool daocLoggerPacket = false;
            try
            {
                if (instantParseInput.Text[0] == '<')
                {
                    try
                    {
                        string[] lines = instantParseInput.Lines;

                        ePacketDirection dir;
                        ePacketProtocol prot;
                        TimeSpan time;
                        int dataLen = DaocLoggerV3TextLogReader.ParseHeader(lines[0], out code, out dir, out prot, out time);
                        pak.Code = (byte)code;
                        pak.Direction = dir;
                        pak.Protocol = prot;
                        pak.Time = time;

                        for (int i = 1; i < lines.Length; i++)
                        {
                            DaocLoggerV3TextLogReader.ParseDataLine(lines[i], pak);
                        }
                        daocLoggerPacket = true;

                        if (pak.Direction == ePacketDirection.ClientToServer)
                        {
                            instantClientToServer.Checked = true;
                        }
                        else
                        {
                            instantServerToClient.Checked = true;
                        }
                    }
                    catch(Exception) {}
                }
                // failed to read daoc logger format
                if (!daocLoggerPacket)
                {
                    pak.Position = 0;
                    foreach (string line in instantParseInput.Text.Split('\n'))
                    {
                        foreach (string str in line.Split(' '))
                        {
                            try
                            {
                                if (str.Trim().Length != 2) continue;
                                byte b = byte.Parse(str.Trim(), NumberStyles.HexNumber);
                                pak.WriteByte(b);
                            }
                            catch(Exception)
                            {
                            }
                        }
                    }
                }
            }
            catch(Exception)
            {
            }

            if (instantServerToClient.Checked)
                pak.Direction = ePacketDirection.ServerToClient;
            else
                pak.Direction = ePacketDirection.ClientToServer;

            pak = PacketManager.CreatePacket(ver, pak.Code,  pak.Direction).CopyFrom(pak);

            StringBuilder result = new StringBuilder();
            result.AppendFormat("ver:{0}  code:0x{1:X2} (old:0x{2:X2})  dir:{3}  len:{4} (0x{4:X})  logger packet:{5}", ver, pak.Code, pak.Code^168, pak.Direction, pak.Length, daocLoggerPacket);
            result.Append("\npacket class: ").Append(pak.GetType().Name).Append("\n");
            result.AppendFormat("desc: \"{0}\"\n\n", pak.Description);
            try
            {
                pak.InitException = null;
                pak.Initialized = false;
                pak.Position = 0;
                pak.Init();
                pak.PositionAfterInit = pak.Position;
                pak.Initialized = true;
                result.Append(pak.GetPacketDataString(true));
            }
            catch (OutOfMemoryException e)
            {
                pak.Initialized = false;
                pak.InitException = e;
                result.Append(e.ToString());
            }
            catch (Exception e)
            {
                pak.InitException = e;
                result.AppendFormat("{0}: {1}", e.GetType().ToString(), e.Message);
            //				result.Append("\n\n").Append(e.ToString());
            }

            if (pak.PositionAfterInit > pak.Length)
            {
                result.AppendFormat("\n(pak.PositionAfterInit > pak.Length !)");
            }

            //			string notInitialized = pak.GetNotInitializedData();
            //			if (notInitialized.Length > 0)
            //			{
            //				result.AppendFormat("\n\nnot initialized:\n{0}", notInitialized);
            //			}
            using (StringWriter sw = new StringWriter())
            {
                pak.AppendNotInitializedData(sw);
                if (sw.ToString().Length > 0)
                    result.AppendFormat("\n\nnot initialized:\n{0}", sw.ToString());
            }

            result.Append('\n');

            instantParseOut.Text = result.ToString();

            if (daocLoggerPacket)
            {
                instantCode.Text = "0x"+pak.Code.ToString("X2");
                instantClientToServer.Checked = pak.Direction == ePacketDirection.ClientToServer;
            }
        }
Пример #4
0
        public void RestoreLogPositionByPacket(Packet restorePacket)
        {
            if (restorePacket != null)
            {
                int restoreIndex = -1;
                {
                    restoreIndex = LogManager.FindTextIndexByPacket(restorePacket);
                }

                if (restoreIndex >= 0)
                {
                    logDataText.SelectionLength = 0;
                    logDataText.SelectionStart = restoreIndex;
                    logDataText.Focus();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PacketInfo"/> class.
 /// </summary>
 /// <param name="newPacket">The new packet.</param>
 /// <param name="newTextIndex">New index of the text.</param>
 /// <param name="newPacketLocation">New packet location.</param>
 public PacketInfo(Packet newPacket, int newTextIndex, PacketLocation newPacketLocation)
 {
     Packet = newPacket;
     TextEndIndex = newTextIndex;
     PacketLocation = newPacketLocation;
 }
 /// <summary>
 /// Raises the filtering packet event.
 /// </summary>
 /// <param name="pak">The pak.</param>
 private void RaiseFilteringPacketEvent(Packet pak)
 {
     try
     {
         PacketAction e = FilteringPacketEvent;
         if (e != null)
             e(pak);
     }
     catch (Exception e)
     {
         Log.Error(e.Message, e);
     }
 }
        /// <summary>
        /// Determines whether the specified packet is ignored.
        /// </summary>
        /// <param name="pak">The packet.</param>
        /// <returns>
        /// 	<c>true</c> if the specified packet is ignored; otherwise, <c>false</c>.
        /// </returns>
        public bool IsPacketIgnored(Packet pak)
        {
            if (m_IgnoreFilters) // temporary Ignore filters
                return false;

            // Notify all listeners
            RaiseFilteringPacketEvent(pak);

            bool ret = false;

            if (m_loading)
            {
                ret = true;
            }
            else
            {
                if (CombineFilters) // allow if not ignored by at least on filter
                {
                    ret = true;
                    for (int i = 0; i < m_filters.Count; i++)
                    {
                        ILogFilter filter = (ILogFilter)m_filters[i];
                        if (filter.IsPacketIgnored(pak) == m_invertCheck) // not ignored = allow
                        {
                            ret = false;
                            break;
                        }
                    }
                }
                else
                {
                    ret = false;
                    for (int i = 0; i < m_filters.Count; i++)
                    {
                        ILogFilter filter = (ILogFilter)m_filters[i];
                        if (filter.IsPacketIgnored(pak) != m_invertCheck) // not ignored = allow
                        {
                            ret = true;
                            break;
                        }
                    }
                }
            }

            return ret;
        }
 /// <summary>
 /// Finds the text index by packet.
 /// </summary>
 /// <param name="packet">The packet.</param>
 /// <returns></returns>
 public int FindTextIndexByPacket(Packet packet)
 {
     return m_packetTextLocations.FindTextIndexByPacket(packet);
 }
Пример #9
0
		/// <summary>
		/// Copy all data from another packet and init private fields if any
		/// </summary>
		/// <param name="pak"></param>
		/// <returns>The target packet instance (this)</returns>
		public virtual Packet CopyFrom(Packet pak)
		{
			m_code = pak.m_code;
			m_direction = pak.m_direction;
			m_time = pak.m_time;
			m_protocol = pak.m_protocol;
			SetLength(0);
			Position = 0;
			pak.Position = 0;
			pak.WriteTo(this);
			return this;
		}
 /// <summary>
 /// Processes start of filtering of a packet by filter manager.
 /// </summary>
 /// <param name="packet"></param>
 protected virtual void FilterManager_OnFilteringPacketEvent(Packet packet)
 {
 }