private PreLoginHandshakeStatus ConsumePreLoginHandshake(bool encrypt, bool trustServerCert, out bool marsCapable)
        {
            marsCapable = this._fMARS;
            bool flag = false;
            this._fAwaitingPreLogin = true;
            this._physicalStateObj.ReadNetworkPacket();
            this._fAwaitingPreLogin = false;
            if ((this._physicalStateObj._inBytesRead == 0) || this._fPreLoginErrorOccurred)
            {
                if (encrypt)
                {
                    this.Errors.Add(new SqlError(20, 0, 20, this._server, SQLMessage.EncryptionNotSupportedByServer(), "", 0));
                    this._physicalStateObj.Dispose();
                    this.ThrowExceptionAndWarning();
                }
                return PreLoginHandshakeStatus.SphinxFailure;
            }
            byte[] buff = new byte[(this._physicalStateObj._inBytesRead - this._physicalStateObj._inBytesUsed) - this._physicalStateObj._inputHeaderLen];
            this._physicalStateObj.ReadByteArray(buff, 0, buff.Length);
            if (buff[0] == 170)
            {
                throw SQL.InvalidSQLServerVersionUnknown();
            }
            int num = 0;
            int index = 0;
            for (int i = buff[num++]; i != 0xff; i = buff[num++])
            {
                System.Data.SqlClient.EncryptionOptions options;
                switch (i)
                {
                    case 0:
                    {
                        index = (buff[num++] << 8) | buff[num++];
                        byte num1 = buff[num++];
                        byte num10 = buff[num++];
                        byte num7 = buff[index];
                        byte num11 = buff[index + 1];
                        byte num12 = buff[index + 2];
                        byte num13 = buff[index + 3];
                        flag = num7 >= 9;
                        if (!flag)
                        {
                            marsCapable = false;
                        }
                        goto Label_0327;
                    }
                    case 1:
                    {
                        index = (buff[num++] << 8) | buff[num++];
                        byte num14 = buff[num++];
                        byte num15 = buff[num++];
                        options = (System.Data.SqlClient.EncryptionOptions) buff[index];
                        switch (this._encryptionOption)
                        {
                            case System.Data.SqlClient.EncryptionOptions.OFF:
                                goto Label_01D3;

                            case System.Data.SqlClient.EncryptionOptions.NOT_SUP:
                                goto Label_01EC;
                        }
                        goto Label_0227;
                    }
                    case 2:
                        goto Label_02BC;

                    case 3:
                        num += 4;
                        goto Label_0327;

                    case 4:
                    {
                        index = (buff[num++] << 8) | buff[num++];
                        byte num18 = buff[num++];
                        byte num19 = buff[num++];
                        marsCapable = buff[index] != 0;
                        goto Label_0327;
                    }
                    default:
                        num += 4;
                        goto Label_0327;
                }
                if (options == System.Data.SqlClient.EncryptionOptions.NOT_SUP)
                {
                    this.Errors.Add(new SqlError(20, 0, 20, this._server, SQLMessage.EncryptionNotSupportedByServer(), "", 0));
                    this._physicalStateObj.Dispose();
                    this.ThrowExceptionAndWarning();
                }
                goto Label_0227;
            Label_01D3:
                if (options == System.Data.SqlClient.EncryptionOptions.OFF)
                {
                    this._encryptionOption = System.Data.SqlClient.EncryptionOptions.LOGIN;
                }
                else if (options == System.Data.SqlClient.EncryptionOptions.REQ)
                {
                    this._encryptionOption = System.Data.SqlClient.EncryptionOptions.ON;
                }
                goto Label_0227;
            Label_01EC:
                if (options == System.Data.SqlClient.EncryptionOptions.REQ)
                {
                    this.Errors.Add(new SqlError(20, 0, 20, this._server, SQLMessage.EncryptionNotSupportedByClient(), "", 0));
                    this._physicalStateObj.Dispose();
                    this.ThrowExceptionAndWarning();
                }
            Label_0227:
                if ((this._encryptionOption != System.Data.SqlClient.EncryptionOptions.ON) && (this._encryptionOption != System.Data.SqlClient.EncryptionOptions.LOGIN))
                {
                    goto Label_0327;
                }
                uint info = (uint) (((encrypt && !trustServerCert) ? 1 : 0) | (flag ? 2 : 0));
                if (SNINativeMethodWrapper.SNIAddProvider(this._physicalStateObj.Handle, SNINativeMethodWrapper.ProviderEnum.SSL_PROV, ref info) != 0)
                {
                    this.Errors.Add(this.ProcessSNIError(this._physicalStateObj));
                    this.ThrowExceptionAndWarning();
                }
                try
                {
                    goto Label_0327;
                }
                finally
                {
                    this._physicalStateObj._sniPacket.Dispose();
                    this._physicalStateObj._sniPacket = new SNIPacket(this._physicalStateObj.Handle);
                }
            Label_02BC:
                index = (buff[num++] << 8) | buff[num++];
                byte num16 = buff[num++];
                byte num17 = buff[num++];
                byte num6 = 1;
                byte num5 = buff[index];
                if (num5 == num6)
                {
                    return PreLoginHandshakeStatus.InstanceFailure;
                }
            Label_0327:
                if (num >= buff.Length)
                {
                    break;
                }
            }
            return PreLoginHandshakeStatus.Successful;
        }
        private void SendPreLoginHandshake(byte[] instanceName, bool encrypt)
        {
            this._physicalStateObj._outputMessageType = 0x12;
            int num2 = 0x1a;
            byte[] b = new byte[0x419];
            int index = 0;
            for (int i = 0; i < 5; i++)
            {
                int num3;
                int num4 = 0;
                this.WriteByte((byte) i, this._physicalStateObj);
                this.WriteByte((byte) (num2 & 0xff00), this._physicalStateObj);
                this.WriteByte((byte) (num2 & 0xff), this._physicalStateObj);
                switch (i)
                {
                    case 0:
                        b[index++] = 0x10;
                        b[index++] = 0;
                        b[index++] = 0;
                        b[index++] = 0;
                        b[index++] = 0;
                        b[index++] = 0;
                        num2 += 6;
                        num4 = 6;
                        goto Label_0196;

                    case 1:
                        if (this._encryptionOption != System.Data.SqlClient.EncryptionOptions.NOT_SUP)
                        {
                            break;
                        }
                        b[index] = 2;
                        goto Label_00EA;

                    case 2:
                        num3 = 0;
                        goto Label_010C;

                    case 3:
                    {
                        int currentThreadIdForTdsLoginOnly = TdsParserStaticMethods.GetCurrentThreadIdForTdsLoginOnly();
                        b[index++] = (byte) (0xff000000L & currentThreadIdForTdsLoginOnly);
                        b[index++] = (byte) (0xff0000 & currentThreadIdForTdsLoginOnly);
                        b[index++] = (byte) (0xff00 & currentThreadIdForTdsLoginOnly);
                        b[index++] = (byte) (0xff & currentThreadIdForTdsLoginOnly);
                        num2 += 4;
                        num4 = 4;
                        goto Label_0196;
                    }
                    case 4:
                        b[index++] = this._fMARS ? ((byte) 1) : ((byte) 0);
                        num2++;
                        num4++;
                        goto Label_0196;

                    default:
                        goto Label_0196;
                }
                if (encrypt)
                {
                    b[index] = 1;
                    this._encryptionOption = System.Data.SqlClient.EncryptionOptions.ON;
                }
                else
                {
                    b[index] = 0;
                    this._encryptionOption = System.Data.SqlClient.EncryptionOptions.OFF;
                }
            Label_00EA:
                index++;
                num2++;
                num4 = 1;
                goto Label_0196;
            Label_00FE:
                b[index] = instanceName[num3];
                index++;
                num3++;
            Label_010C:
                if (instanceName[num3] != 0)
                {
                    goto Label_00FE;
                }
                b[index] = 0;
                index++;
                num3++;
                num2 += num3;
                num4 = num3;
            Label_0196:
                this.WriteByte((byte) (num4 & 0xff00), this._physicalStateObj);
                this.WriteByte((byte) (num4 & 0xff), this._physicalStateObj);
            }
            this.WriteByte(0xff, this._physicalStateObj);
            this.WriteByteArray(b, index, 0, this._physicalStateObj);
            this._physicalStateObj.WritePacket(1);
        }