Beispiel #1
0
        public void Init([NotNull] TcpClient client)
        {
            // Allow Client to close immediately
            client.LingerState = new LingerOption(true, 0);

            byte[] sivBytes = new byte[4];
            byte[] rivBytes = new byte[4];
            Rng.GetBytes(sivBytes);
            Rng.GetBytes(rivBytes);
            Siv = BitConverter.ToUInt32(sivBytes);
            Riv = BitConverter.ToUInt32(rivBytes);

            Client        = client;
            NetworkStream = client.GetStream();
            MapleStream   = new MapleStream();
            SendCipher    = MapleCipher.Encryptor(VERSION, Siv, BLOCK_IV);
            RecvCipher    = MapleCipher.Decryptor(VERSION, Riv, BLOCK_IV);
        }
Beispiel #2
0
        internal Results BufferTcpPacket(TcpPacket pTcpPacket, DateTime pArrivalTime)
        {
            if (mTerminated)
            {
                return(Results.Terminated);
            }

            if (pTcpPacket.Finished || pTcpPacket.Reset)
            {
                Terminate();
                return(mPackets.Count == 0 ? Results.CloseMe : Results.Terminated);
            }

            if (pTcpPacket.Synchronize)
            {
                if (!pTcpPacket.Acknowledgment)
                {
                    mLocalPort  = pTcpPacket.SourcePort;
                    mRemotePort = pTcpPacket.DestinationPort;
                    Text        = $"Port {mLocalPort} - {mRemotePort}";
                    startTime   = DateTime.Now;

                    try {
                        mRemoteEndpoint = $"{((IPv4Packet) pTcpPacket.ParentPacket).SourceAddress}:{mLocalPort}";
                        mLocalEndpoint  = $"{((IPv4Packet) pTcpPacket.ParentPacket).DestinationAddress}:{mRemotePort}";
                        logger.Debug($"[CONNECTION] From {mRemoteEndpoint} to {mLocalEndpoint}");
                    } catch {
                        return(Results.CloseMe);
                    }
                }
            }

            bool isOutbound = pTcpPacket.SourcePort == mLocalPort;

            tcpReassembler.ReassembleStream(pTcpPacket);

            MapleStream packetStream = isOutbound ? tcpReassembler.OutStream : tcpReassembler.InStream;
            int         opcodeCount  = Opcodes.Count;
            bool        show         = false;

            try {
                while (packetStream.TryRead(out byte[] packet))
                {
                    Results result = ProcessPacket(packet, isOutbound, pArrivalTime);
                    switch (result)
                    {
                    case Results.Continue:
                        continue;

                    case Results.Show:
                        show = true;
                        break;

                    default:
                        return(result);
                    }
                }
            } catch (Exception ex) {
                logger.Fatal(ex, "Exception while buffering packets");
                Terminate();
                return(Results.Terminated);
            }

            if (DockPanel != null && DockPanel.ActiveDocument == this && opcodeCount != Opcodes.Count)
            {
                MainForm.SearchForm.RefreshOpcodes(true);
            }

            return(show ? Results.Show : Results.Continue);
        }