示例#1
0
        private void ProcessTCPPacket(TCPPacket pTCPPacket, ref uint pSequence, Dictionary<uint, byte[]> pBuffer, FiestaStream pStream)
        {
            if (pTCPPacket.SequenceNumber > pSequence)
            {
                byte[] data;
                while ((data = pBuffer.GetOrDefault(pSequence, null)) != null)
                {
                    pBuffer.Remove(pSequence);
                    pStream.Append(data);
                    pSequence += (uint)data.Length;
                }
                if (pTCPPacket.SequenceNumber > pSequence) pBuffer[(uint)pTCPPacket.SequenceNumber] = pTCPPacket.TCPData;
            }
            if (pTCPPacket.SequenceNumber < pSequence)
            {
                int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
                if (difference > 0)
                {
                    byte[] data = pTCPPacket.TCPData;
                    if (data.Length > difference)
                    {
                        pStream.Append(data, difference, data.Length - difference);
                        pSequence += (uint)(data.Length - difference);
                    }
                }
            }
            else if (pTCPPacket.SequenceNumber == pSequence)
            {
                byte[] data = pTCPPacket.TCPData;
                pStream.Append(data);
                pSequence += (uint)data.Length;
            }

            FiestaPacket packet;
            try
            {
                while ((packet = pStream.Read(pTCPPacket.Timeval.Date)) != null)
                {
                    mPackets.Add(packet);
                    Definition definition = Config.Instance.Definitions.Find(d => d.Build == 1 && d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);
                    if (!mOpcodes.Exists(kv => kv.Item1 == packet.Outbound && kv.Item2 == packet.Opcode))
                    {
                        mOpcodes.Add(new Tuple<bool, ushort>(packet.Outbound, packet.Opcode));

                    }
                    if (definition != null && definition.Ignore) continue;
                    if (!FilterOut(packet))
                    {
                        mPacketList.Items.Add(packet);
                    }
                    if (mPacketList.SelectedItems.Count == 0) packet.EnsureVisible();
                }
            }
            catch (Exception exc)
            {
                OutputForm output = new OutputForm("Packet Error");
                output.Append(exc.ToString());
                output.Show(DockPanel, new Rectangle(MainForm.Location, new Size(400, 400)));
                mTerminated = true;
                Text += " (Terminated)";
            }
        }
示例#2
0
 internal void BufferTCPPacket(TCPPacket pTCPPacket)
 {
     if (pTCPPacket.Fin || pTCPPacket.Rst)
     {
         mTerminated = true;
         Text += " (Terminated)";
         return;
     }
     if (pTCPPacket.Syn && !pTCPPacket.Ack)
     {
         mLocalPort = (ushort)pTCPPacket.SourcePort;
         mRemotePort = (ushort)pTCPPacket.DestinationPort;
         mOutboundSequence = (uint)(pTCPPacket.SequenceNumber + 1);
         Text = "Port " + mLocalPort.ToString();
         return;
     }
     if (pTCPPacket.Syn && pTCPPacket.Ack) { mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); return; }
     if (pTCPPacket.PayloadDataLength == 0) return;
     if (!gotKey)
     {
         byte[] tcpData = pTCPPacket.TCPData;
         if (BitConverter.ToUInt16(tcpData, 1) != 0x0807)
         {
             this.Close();
             mInboundSequence += (uint)tcpData.Length; //not valid xorkey
             return;
         }
         ushort xorKey = BitConverter.ToUInt16(tcpData, 3);
         mOutboundStream = new FiestaStream(true, xorKey);
         mInboundStream = new FiestaStream(false, 0);
         gotKey = true;
         mInboundSequence += (uint)tcpData.Length;
         return;
     }
     if (pTCPPacket.SourcePort == mLocalPort) ProcessTCPPacket(pTCPPacket, ref mOutboundSequence, mOutboundBuffer, mOutboundStream); //process fromclient
     else ProcessTCPPacket(pTCPPacket, ref mInboundSequence, mInboundBuffer, mInboundStream); //process fromserver
 }