Exemplo n.º 1
0
        public void Decrypt(byte[] data, int count)
        {
            if (this.IsInitialized)
            {
                goto IL_2C;
            }
IL_08:
            int arg_12_0 = -669052452;

IL_0D:
            switch ((arg_12_0 ^ -2090713909) % 4)
            {
            case 0:
                goto IL_08;

            case 2:
IL_2C:
                this.SARC4Decrypt.ProcessBuffer(data, count);
                arg_12_0 = -110949926;
                goto IL_0D;

            case 3:
                throw BNetCrypt.smethod_0(Module.smethod_33 <string>(2782540870u));
            }
        }
Exemplo n.º 2
0
        public void Encrypt(byte[] data, int count)
        {
            if (this.IsInitialized)
            {
                goto IL_2C;
            }
IL_08:
            int arg_12_0 = -407049644;

IL_0D:
            switch ((arg_12_0 ^ -1406051805) % 4)
            {
            case 0:
IL_2C:
                this.SARC4Encrypt.ProcessBuffer(data, count);
                arg_12_0 = -2042246406;
                goto IL_0D;

            case 2:
                goto IL_08;

            case 3:
                throw BNetCrypt.smethod_0(Module.smethod_33 <string>(2782540870u));
            }
        }
Exemplo n.º 3
0
        void Process(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                var socket = e.UserToken as Socket;
                var recievedBytes = e.BytesTransferred;

                if (recievedBytes != 0)
                {
                    // Enable packet encryption.
                    if (Crypt == null && dataBuffer[0] == 0x45 && dataBuffer[1] == 0x01)
                    {
                        Crypt = new BNetCrypt(SecureRemotePassword.SessionKey);

                        Buffer.BlockCopy(dataBuffer, 2, dataBuffer, 0, recievedBytes -= 2);

                        Log.Message(LogType.Debug, "Encryption for account '{0}' enabled", Account.Id);
                    }

                    if (Crypt != null && Crypt.IsInitialized)
                        Crypt.Decrypt(dataBuffer, recievedBytes);

                    ProcessPacket(recievedBytes);

                    if (client != null)
                        client.ReceiveAsync(e);
                }
                else
                    socket.Close();
            }
            catch (Exception ex)
            {
                Log.Message(LogType.Error, "{0}", ex.Message);
            }
        }
Exemplo n.º 4
0
 static BNetCrypt()
 {
     // Note: this type is marked as 'beforefieldinit'.
     byte[] expr_07 = new byte[16];
     BNetCrypt.smethod_3(expr_07, fieldof(Framework.< PrivateImplementationDetails >.FE5E26F28C22F788D40FAD92147032F58EC76833).FieldHandle);
     BNetCrypt.ServerEncryptionKey = expr_07;
     byte[] expr_1E = new byte[16];
     BNetCrypt.smethod_3(expr_1E, fieldof(Framework.< PrivateImplementationDetails >.F3FAF914B4E2D945DAF4562B7BE04C79D9C0F6CA).FieldHandle);
     BNetCrypt.ServerDecryptionKey = expr_1E;
 }
Exemplo n.º 5
0
        public BNetCrypt(byte[] sessionKey)
        {
            this.IsInitialized = false;
            if (this.IsInitialized)
            {
                throw BNetCrypt.smethod_0(Module.smethod_36 <string>(56398324u));
            }
            this.SARC4Encrypt = new SARC4();
            this.SARC4Decrypt = new SARC4();
            HMACSHA256 hashAlgorithm_  = BNetCrypt.smethod_1(sessionKey);
            HMACSHA256 hashAlgorithm_2 = BNetCrypt.smethod_1(sessionKey);

            this.SARC4Encrypt.PrepareKey(BNetCrypt.smethod_2(hashAlgorithm_2, BNetCrypt.ServerEncryptionKey));
            this.SARC4Decrypt.PrepareKey(BNetCrypt.smethod_2(hashAlgorithm_, BNetCrypt.ServerDecryptionKey));
            this.IsInitialized = true;
        }
Exemplo n.º 6
0
        async void Process(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                var socket = e.UserToken as Socket;
                var recievedBytes = e.BytesTransferred;

                if (recievedBytes != 0)
                {
                    var buff = new byte[recievedBytes];

                    Buffer.BlockCopy(dataBuffer, 0, buff, 0, recievedBytes);

                    // Enable packet encryption
                    if (Crypt == null && buff[0] == 0x45 && buff[1] == 0x01)
                    {
                        Crypt = new BNetCrypt(SecureRemotePassword.SessionKey);

                        Buffer.BlockCopy(buff, 2, buff, 0, recievedBytes -= 2);

                        Log.Debug($"Encryption for account '{Account.Id}' enabled");
                    }
                    
                    Crypt?.Decrypt(buff, recievedBytes);

                    client.ReceiveAsync(e);

                    await ProcessPacket(buff, recievedBytes);
                }
                else
                    socket.Close();
            }
            catch (Exception ex)
            {
                Dispose();

                ExceptionLog.Write(ex);

                Log.Error(ex.Message);
            }
        }