Exemplo n.º 1
0
        public static void WriteProtocolVersion(Stream a_stream, VncEnum.Version a_version)
        {
            int version = 0;

            switch (a_version)
            {
            case VncEnum.Version.Version33:
                version = 3;
                break;

            case VncEnum.Version.Version37:
                version = 7;
                break;

            case VncEnum.Version.Version38:
                version = 8;
                break;

            default:
                throw new ArgumentException($"Unknown version. {a_version}");
            }

            byte[] buffer = Encoding.ASCII.GetBytes($"RFB 003.00{version}\n");
            a_stream.Write(buffer, 0, buffer.Length);
        }
Exemplo n.º 2
0
        public static VncEnum.Version ReadProtocolVersion(Stream a_stream, VncEnum.Version a_forceVersion)
        {
            byte[] buffer = new byte[12];
            a_stream.ReadAll(buffer, 0, buffer.Length);
            if (buffer.SequenceEqual(Encoding.ASCII.GetBytes("RFB 003.003\n")) ||
                buffer.SequenceEqual(Encoding.ASCII.GetBytes("RFB 003.005\n")))
            {
                return(VncEnum.Version.Version33);
            }
            else if (buffer.SequenceEqual(Encoding.ASCII.GetBytes("RFB 003.007\n")))
            {
                return(VncEnum.Version.Version37);
            }
            else if (buffer.SequenceEqual(Encoding.ASCII.GetBytes("RFB 003.008\n")))
            {
                return(VncEnum.Version.Version38);
            }

            // In rare cases, it may be a strange response, so if a_forceVersion is not Invalid, it is permitted if the beginning matches.
            if (a_forceVersion != VncEnum.Version.None)
            {
                if (Encoding.ASCII.GetString(buffer).Contains("RFB 003"))
                {
                    return(a_forceVersion);
                }
            }

            throw new InvalidDataException($"Unknown version. Length = {buffer.Length} Text = [{Encoding.ASCII.GetString(buffer)}]");
        }
Exemplo n.º 3
0
 public VncConfig(string a_address, int a_port, string a_password, VncEnum.Version a_forceVersion, VncEnum.EncodeType[] a_encodings, bool a_isColourSpecified, PixelFormat a_specifiedColour, bool a_isSendKeyboard, bool a_isSendPointer)
 {
     Address           = a_address;
     Port              = a_port;
     Password          = a_password;
     ForceVersion      = a_forceVersion;
     Encodings         = a_encodings;
     IsColourSpecified = a_isColourSpecified;
     SpecifiedColour   = a_specifiedColour;
     IsSendKeyboard    = a_isSendKeyboard;
     IsSendPointer     = a_isSendPointer;
 }
Exemplo n.º 4
0
        public static VncEnum.SecurityResult ReadSecurityResult(Stream a_stream, VncEnum.Version a_vncVersion)
        {
            byte[] buffer = new byte[4];
            a_stream.ReadAll(buffer, 0, buffer.Length);

            UInt32 securityResult = BigEndianBitConverter.ToUInt32(buffer, 0);

            if (securityResult == (UInt32)VncEnum.SecurityResult.Failed)
            {
                if (a_vncVersion == VncEnum.Version.Version33 ||
                    a_vncVersion == VncEnum.Version.Version37)
                {
                    throw new SecurityException("SecurityResult is Failed.");
                }
                else
                {
                    string str = readReasonString(a_stream);
                    throw new SecurityException($"SecurityResult is Failed. ({str})");
                }
            }

            return((VncEnum.SecurityResult)securityResult);
        }
Exemplo n.º 5
0
        private void c_connectButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(c_addressTextBox.Text) ||
                string.IsNullOrEmpty(c_passwordTextBox.Text))
            {
                return;
            }

            if (m_connectMode)
            {
                // Protocol Version
                VncEnum.Version version = VncEnum.Version.None;
                if (Properties.Settings.Default.Protocol33)
                {
                    version = VncEnum.Version.Version33;
                }
                else if (Properties.Settings.Default.Protocol37)
                {
                    version = VncEnum.Version.Version37;
                }
                else if (Properties.Settings.Default.Protocol38)
                {
                    version = VncEnum.Version.Version38;
                }
                // Encodings
                var useEncodingList = new List <VncEnum.EncodeType>();
                foreach (var v in Properties.Settings.Default.EncodingList)
                {
                    useEncodingList.Add((VncEnum.EncodeType)(int.Parse(v)));
                }
                // Colour
                bool        isColourSpecified = !Properties.Settings.Default.ColourLevelReceived;
                PixelFormat specifiedColor    = PixelFormat.PixelFormatDepth24;
                if (Properties.Settings.Default.ColourLevelDepth16)
                {
                    specifiedColor = PixelFormat.PixelFormatDepth16;
                }
                else if (Properties.Settings.Default.ColourLevelDepth8Colour64)
                {
                    specifiedColor = PixelFormat.PixelFormatDepth8Colour64;
                }
                else if (Properties.Settings.Default.ColourLevelDepth8Colour8)
                {
                    specifiedColor = PixelFormat.PixelFormatDepth8Colour8;
                }

                var config = new VncConfig(c_addressTextBox.Text,
                                           5900,
                                           c_passwordTextBox.Text,
                                           version,
                                           useEncodingList.ToArray(),
                                           isColourSpecified,
                                           specifiedColor,
                                           Properties.Settings.Default.SendKeyboard,
                                           Properties.Settings.Default.SendPointer);
                bool result = c_vncControl.Connect(config);
                if (result)
                {
                    c_connectButton.Text = "Disconnect";
                    m_connectMode        = false;
                }
            }
            else
            {
                c_vncControl.Disconnect();
                c_connectButton.Text = "Connect";
                m_connectMode        = true;
            }
        }