Exemple #1
0
        /// <summary>
        /// Decrypts the packet data
        /// </summary>
        private void Decrypt(byte[] data)
        {
            if (!RecvCipher.Handshaken)
            {
                RecvCipher.RecvHandshake(ref data);
                ArrayReader pr = new ArrayReader(data);
                pr.ReadShort();       //Version
                pr.ReadMapleString(); //Sub Version
                uint siv = pr.ReadUInt();
                uint riv = pr.ReadUInt();
                SendCipher.SetIV(siv);
                RecvCipher.SetIV(riv);

                if (HandshakeFinished != null)
                {
                    HandshakeFinished(siv, riv);
                }
            }
            else
            {
                RecvCipher.Decrypt(ref data);
                if (data.Length == 0)
                {
                    return;
                }

                if (PacketFinished != null)
                {
                    PacketFinished(data);
                }
            }
            Wait();
        }
Exemple #2
0
        /// <summary>
        /// Decrypts the packet data
        /// </summary>
        private void Decrypt(byte[] data)
        {
            if (!RecvCipher.Handshaken)
            {
                RecvCipher.Handshake(ref data);
                ArrayReader pr = new ArrayReader(data);
                Console.WriteLine("Server version {0}.{1}", pr.ReadShort(), pr.ReadMapleString());
                uint siv = pr.ReadUInt();
                uint riv = pr.ReadUInt();
                SendCipher.SetIV(siv);
                RecvCipher.SetIV(riv);

                if (HandshakeFinished != null)
                {
                    HandshakeFinished(siv, riv);
                }
            }
            else
            {
                RecvCipher.Decrypt(ref data);
                if (data.Length == 0)
                {
                    return;
                }

                if (PacketFinished != null)
                {
                    PacketFinished(data);
                }
            }
            Wait();
        }
        /// <summary>
        /// Decrypts the packet data
        /// </summary>
        public void Decrypt(Span <byte> data)
        {
            if (!RecvCipher.Handshaken)
            {
                var pr = new BinaryReader(new MemoryStream(MapleCipher.Handshake(data).ToArray(), false),
                                          Encoding.ASCII);
                var version          = pr.ReadInt16();
                var subVersionLength = pr.ReadInt16();
                var subVersion       = new string(pr.ReadChars(subVersionLength));
                var siv        = pr.ReadUInt32();
                var riv        = pr.ReadUInt32();
                var serverType = pr.ReadByte();
                SendCipher.SetIv(siv);
                RecvCipher.SetIv(riv);
                HandshakeFinished?.Invoke(siv, riv, version, subVersion, serverType);
            }
            else
            {
                if (!RecvCipher.CheckHeader(data, !ToClient))
                {
                    throw new InvalidOperationException($"Packet header mismatch Size:{data.Length}");
                }

                var decrypted = RecvCipher.Decrypt(data);

                if (decrypted.Length == 0)
                {
                    return;
                }

                PacketFinished?.Invoke(decrypted.ToArray());
            }
        }
Exemple #4
0
 /// <summary>
 /// Gets the packet header from the current packet.
 /// </summary>
 private void GetHeader()
 {
     if (!RecvCipher.Handshaken)
     {
         WaitMore(BitConverter.ToInt16(buffer, 0));
     }
     else
     {
         int packetLength = RecvCipher.GetPacketLength(buffer);
         WaitMore(packetLength);
     }
 }
Exemple #5
0
 /// <summary>
 /// Sets the Recv and Send Vectors for the ciphers
 /// </summary>
 public void SetVectors(uint SIV, uint RIV)
 {
     SendCipher.SetIV(SIV);
     RecvCipher.SetIV(RIV);
 }
 /// <summary>
 /// Sets the Recv and Send Vectors for the ciphers
 /// </summary>
 public void SetVectors(uint siv, uint riv)
 {
     SendCipher.SetIv(siv);
     RecvCipher.SetIv(riv);
 }