Пример #1
0
        private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary <uint, byte[]> pBuffer, MapleStream pStream, DateTime pArrivalDate)
        {
            if (pTCPPacket.SequenceNumber > pSequence)
            {
                byte[] data;

                while (pBuffer.TryGetValue(pSequence, out data))
                {
                    pBuffer.Remove(pSequence);
                    pStream.Append(data);
                    pSequence += (uint)data.Length;
                }
                if (pTCPPacket.SequenceNumber > pSequence)
                {
                    pBuffer[(uint)pTCPPacket.SequenceNumber] = pTCPPacket.PayloadData;
                }
            }
            if (pTCPPacket.SequenceNumber < pSequence)
            {
                int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
                if (difference > 0)
                {
                    byte[] data = pTCPPacket.PayloadData;
                    if (data.Length > difference)
                    {
                        pStream.Append(data, difference, data.Length - difference);
                        pSequence += (uint)(data.Length - difference);
                    }
                }
            }
            else if (pTCPPacket.SequenceNumber == pSequence)
            {
                byte[] data = pTCPPacket.PayloadData;
                pStream.Append(data);
                pSequence += (uint)data.Length;
            }

            MaplePacket packet;
            bool        refreshOpcodes = false;

            try
            {
                mPacketList.BeginUpdate();

                while ((packet = pStream.Read(pArrivalDate)) != null)
                {
                    AddPacket(packet);
                    Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
                    if (!mOpcodes.Exists(op => op.Outbound == packet.Outbound && op.Header == packet.Opcode))
                    {
                        mOpcodes.Add(new Opcode(packet.Outbound, packet.Opcode));
                        refreshOpcodes = true;
                    }
                    if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore)
                    {
                        continue;
                    }
                    if (packet.Outbound && !mViewOutboundMenu.Checked)
                    {
                        continue;
                    }
                    if (!packet.Outbound && !mViewInboundMenu.Checked)
                    {
                        continue;
                    }

                    mPacketList.Items.Add(packet);
                    if (mPacketList.SelectedItems.Count == 0)
                    {
                        packet.EnsureVisible();
                    }
                }

                mPacketList.EndUpdate();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                mTerminated = true;
                Text       += " (Terminated)";
                //MainForm.CloseSession(this);
                return;
            }

            if (DockPanel != null && DockPanel.ActiveDocument == this && refreshOpcodes)
            {
                MainForm.SearchForm.RefreshOpcodes(true);
            }
        }
Пример #2
0
        private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary<uint, byte[]> pBuffer, MapleStream pStream, DateTime pArrivalDate)
        {
            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.PayloadData;
            }
            if (pTCPPacket.SequenceNumber < pSequence)
            {
                int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
                if (difference > 0)
                {
                    byte[] data = pTCPPacket.PayloadData;
                    if (data.Length > difference)
                    {
                        pStream.Append(data, difference, data.Length - difference);
                        pSequence += (uint)(data.Length - difference);
                    }
                }
            }
            else if (pTCPPacket.SequenceNumber == pSequence)
            {
                byte[] data = pTCPPacket.PayloadData;
                pStream.Append(data);
                pSequence += (uint)data.Length;
            }

            MaplePacket packet;
            bool refreshOpcodes = false;
            try
            {
                while ((packet = pStream.Read(pArrivalDate, mBuild, mLocale)) != null)
                {
                    mPackets.Add(packet);
                    Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
                    if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode))
                    {
                        mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
                        refreshOpcodes = true;
                    }
                    if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue;
                    mPacketList.Items.Add(packet);
                    if (mPacketList.SelectedItems.Count == 0) packet.EnsureVisible();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                mTerminated = true;
                Text += " (Terminated)";
                //MainForm.CloseSession(this);
                return;
            }

            if (DockPanel.ActiveDocument == this && refreshOpcodes) MainForm.SearchForm.RefreshOpcodes(true);
        }
Пример #3
0
        private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary <uint, byte[]> pBuffer, MapleStream pStream, DateTime pArrivalDate)
        {
            if (pTCPPacket.SequenceNumber > pSequence)
            {
                byte[] data;

                while (pBuffer.TryGetValue(pSequence, out data))
                {
                    pBuffer.Remove(pSequence);
                    pStream.Append(data);
                    pSequence += (uint)data.Length;
                }
                if (pTCPPacket.SequenceNumber > pSequence)
                {
                    pBuffer[(uint)pTCPPacket.SequenceNumber] = pTCPPacket.PayloadData;
                }
            }
            if (pTCPPacket.SequenceNumber < pSequence)
            {
                int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
                if (difference > 0)
                {
                    byte[] data = pTCPPacket.PayloadData;
                    if (data.Length > difference)
                    {
                        pStream.Append(data, difference, data.Length - difference);
                        pSequence += (uint)(data.Length - difference);
                    }
                }
            }
            else if (pTCPPacket.SequenceNumber == pSequence)
            {
                byte[] data = pTCPPacket.PayloadData;
                pStream.Append(data);
                pSequence += (uint)data.Length;
            }

            MaplePacket packet;
            bool        refreshOpcodes = false;

            try
            {
                mPacketList.BeginUpdate();

                while ((packet = pStream.Read(pArrivalDate)) != null)
                {
                    if (Locale == MapleLocale.GLOBAL && Build >= 193)
                    {
                        if (packet.Outbound)
                        {
                            if (isOpcodeTableLoaded)
                            {
                                ushort realOpcode = 0;

                                if (mOpcodeTable.TryGetValue(packet.Opcode, out realOpcode))
                                {
                                    packet.Opcode = realOpcode;
                                }

                                packet.SubItems[3].Text = $"0x{packet.Opcode.ToString("X4")}";
                            }
                        }
                        else
                        {
                            if (!isOpcodeTableLoaded && packet.Opcode == HeaderTableOpcode)
                            {
                                bool healthy = false;
                                int  blockSize, length = 0;

                                healthy = packet.ReadInt(out blockSize);
                                healthy = packet.ReadInt(out length);

                                byte[] buffer = new byte[length];
                                byte[] key    = Encoding.ASCII.GetBytes("M@PleStoryMaPLe!");

                                healthy = packet.ReadBytes(buffer);

                                if (healthy)
                                {
                                    string opcodes = TripleDESCipher.Decrypt(buffer, key);

                                    for (ushort i = 0; i < 0x0A7F - Begin_User; i++)
                                    {
                                        if (i * 4 + 4 <= opcodes.Length)
                                        {
                                            string sOpcode = opcodes.Substring(i * 4, 4);

                                            ushort uOpcode;
                                            if (!UInt16.TryParse(sOpcode, out uOpcode))
                                            {
                                                break;
                                            }

                                            mOpcodeTable.Add(uOpcode, (ushort)(Begin_User + i));
                                        }
                                        else
                                        {
                                            healthy = false;
                                        }
                                    }
                                }

                                if (healthy)
                                {
                                    isOpcodeTableLoaded = true;
                                }
                            }
                        }
                    }

                    AddPacket(packet);
                    Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
                    if (!mOpcodes.Exists(op => op.Outbound == packet.Outbound && op.Header == packet.Opcode))
                    {
                        mOpcodes.Add(new Opcode(packet.Outbound, packet.Opcode));
                        refreshOpcodes = true;
                    }
                    if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore)
                    {
                        continue;
                    }
                    if (packet.Outbound && !mViewOutboundMenu.Checked)
                    {
                        continue;
                    }
                    if (!packet.Outbound && !mViewInboundMenu.Checked)
                    {
                        continue;
                    }

                    mPacketList.Items.Add(packet);
                    if (mPacketList.SelectedItems.Count == 0)
                    {
                        packet.EnsureVisible();
                    }
                }

                mPacketList.EndUpdate();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                mTerminated = true;
                Text       += " (Terminated)";
                //MainForm.CloseSession(this);
                return;
            }

            if (DockPanel != null && DockPanel.ActiveDocument == this && refreshOpcodes)
            {
                MainForm.SearchForm.RefreshOpcodes(true);
            }
        }
        private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary <uint, byte[]> pBuffer, MapleStream pStream, DateTime pArrivalDate, bool isInbound)
        {
            /*
             *
             * 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.PayloadData;
             * }
             * if (pTCPPacket.SequenceNumber < pSequence)
             * {
             *  int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
             *  if (difference > 0)
             *  {
             *      byte[] data = pTCPPacket.PayloadData;
             *      if (data.Length > difference)
             *      {
             *          pStream.Append(data, difference, data.Length - difference);
             *          pSequence += (uint)(data.Length - difference);
             *      }
             *  }
             * }
             *
             * else if (pTCPPacket.SequenceNumber == pSequence)
             * {*/
            byte[] data = pTCPPacket.PayloadData;
            if (isInbound)
            {
                pStream.Append(data, ref inboundBuffer);
            }
            else
            {
                pStream.Append(data, ref outboundBuffer);
            }
            //pSequence += (uint)data.Length;
            // }

            MaplePacket packet;
            bool        refreshOpcodes = false;

            try
            {
                while ((isInbound ? (packet = pStream.Read(pArrivalDate, mBuild, mLocale, ref isFirstPacket, ref inboundBuffer, ref curInboundIV)) : (packet = pStream.Read(pArrivalDate, mBuild, mLocale, ref isFirstPacket, ref outboundBuffer, ref curOutboundIV))) != null)
                {
                    Console.WriteLine("OK");
                    Console.WriteLine(" ");
                    mPackets.Add(packet);
                    Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
                    if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode))
                    {
                        mOpcodes.Add(new Pair <bool, ushort>(packet.Outbound, packet.Opcode));
                        refreshOpcodes = true;
                    }
                    //if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue;
                    mPacketList.Items.Add(packet);
                    if (mPacketList.SelectedItems.Count == 0)
                    {
                        packet.EnsureVisible();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                mTerminated = true;
                Text       += " (Terminated)";
                //MainForm.CloseSession(this);

                return;
            }

            if (DockPanel.ActiveDocument == this && refreshOpcodes)
            {
                MainForm.SearchForm.RefreshOpcodes(true);
            }
        }