Beispiel #1
0
        private void SetEncodings()
        {
            // We use a stack here.  The least favored encoding is pushed onto the stack first.
            Stack stack = new Stack();

            stack.Push(RfbEncoding.Raw);
            stack.Push(RfbEncoding.CopyRect);
            stack.Push(RfbEncoding.Rre);

            // We do support CoRRE encoding.
            // However, Ultra-VNC server is broken.
            // If we use CoRRE and server-side scaling is enabled, the server will
            // send us frame buffer updates with number of rectangles set incorrectly.
            // So the morale of the story is not to use CoRRE. If we know the server
            // does not scale the buffer, then we can enable CoRRE.
            // But this can all be avoided by using Hextile.
            //stack.Push(RfbEncoding.CoRre);

            stack.Push(RfbEncoding.Hex);

            stack.Push(RfbEncoding.NewFBSize);

            byte[] msg;
            msg = RfbProtoUtil.GetSetEncodingsMsgHdr((UInt16)stack.Count);
            WriteBytes(msg, RfbCliMsgType.SetEncodings);
            RfbEncoding[] encodings = new RfbEncoding[stack.Count];
            stack.ToArray().CopyTo(encodings, 0);
            msg = RfbProtoUtil.GetSetEncodingsMsg(encodings);
            WriteBytes(msg);
        }
Beispiel #2
0
        private void NegoProtoVer(string info)
        {
            string verMsg = ReadAsciiStr(RfbSize.VerMsg);

            if (!RfbProtoUtil.IsValidVerMsg(verMsg))
            {
                if (string.IsNullOrEmpty(info))
                {
                    throw new WarnEx(App.GetStr("The server is not a RDP server!"));
                }
                else
                {
                    throw new WarnEx(App.GetStr(info + "Á¬½Óʧ°Ü£¡"));
                }
            }

            RfbProtoUtil.GetVerFromMsg(verMsg, out majorVer, out minorVer);

            if (majorVer == 3 && minorVer < 3)
            {
                throw new WarnEx(App.GetStr("This server version is not supported!"));
            }
            else
            {
                majorVer = ViewerRfbMajorVer;
                minorVer = ViewerRfbMinorVer;
            }

            verMsg = RfbProtoUtil.GetVerMsg(majorVer, minorVer);
            WriteAsciiStr(verMsg);
        }
Beispiel #3
0
        private void ReadServCutTxt()
        {
            // .NET CF does not have built-in support for the clipboard.
            // We ignore this message at the moment.

            byte[] msg = ReadBytes(RfbSize.ServCutTxt - 1);
            UInt32 len = RfbProtoUtil.GetLenFromServCutTxtMsg(msg);
            string txt = ReadAsciiStr((int)len);
        }
Beispiel #4
0
 private void SetPixelFormat()
 {
     byte[] msg;
     if (opts.ViewOpts.PixelSize == PixelSize.Force8Bit)
     {
         bpp         = 8;
         depth       = 8;
         isBigEndian = false;
         isTrueColor = true;
         redMax      = 7;
         greenMax    = 7;
         blueMax     = 3;
         redShift    = 0;
         greenShift  = 3;
         blueShift   = 6;
         bytesPp     = 1;
     }
     else if (opts.ViewOpts.PixelSize == PixelSize.Force16Bit)//|| !servInit.IsTrueColor
     {
         bpp         = 16;
         depth       = 16;
         isBigEndian = false;
         isTrueColor = true;
         redMax      = 63;
         greenMax    = 31;
         blueMax     = 31;
         redShift    = 0;
         greenShift  = 6;
         blueShift   = 11;
         bytesPp     = 2;
     }
     else
     {
         bpp         = servInit.Bpp;
         depth       = servInit.Depth;
         isBigEndian = false;
         isTrueColor = servInit.IsTrueColor;
         redMax      = servInit.RedMax;
         greenMax    = servInit.GreenMax;
         blueMax     = servInit.BlueMax;
         redShift    = servInit.RedShift;
         greenShift  = servInit.GreenShift;
         blueShift   = servInit.BlueShift;
         bytesPp     = (byte)((bpp + 7) / 8);
     }
     msg = RfbProtoUtil.GetSetPixelFormatMsg(bpp, depth, isBigEndian, isTrueColor, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
     WriteBytes(msg, RfbCliMsgType.SetPixelFormat);
 }
Beispiel #5
0
        private void NegoProtoVer()
        {
            string verMsg = ReadAsciiStr(RfbSize.VerMsg);

            if (!RfbProtoUtil.IsValidVerMsg(verMsg))
            {
                throw new WarnEx(App.GetStr("The server is not a VNC server!"));
            }

            RfbProtoUtil.GetVerFromMsg(verMsg, out majorVer, out minorVer);

            if (majorVer == 3 && minorVer < 3)
            {
                throw new WarnEx(App.GetStr("This server version is not supported!"));
            }
            else
            {
                majorVer = ViewerRfbMajorVer;
                minorVer = ViewerRfbMinorVer;
            }

            verMsg = RfbProtoUtil.GetVerMsg(majorVer, minorVer);
            WriteAsciiStr(verMsg);
        }
Beispiel #6
0
        private void ReadScrnUpd()
        {
            byte[] msg      = ReadBytes(RfbSize.FrameBufUpd - 1);
            UInt16 numRects = RfbProtoUtil.GetNumRectsFromFrameBufUpdMsg(msg);

            for (int i = 0; i < numRects; i++)
            {
                msg = ReadBytes(RfbSize.FrameBufUpdRectHdr);
                FrameBufUpdRectMsgHdr frameBufUpdRectHdr = new FrameBufUpdRectMsgHdr(msg);
                Rectangle             rect = new Rectangle(frameBufUpdRectHdr.X, frameBufUpdRectHdr.Y, frameBufUpdRectHdr.Width, frameBufUpdRectHdr.Height);

                if (frameBufUpdRectHdr.Encoding == RfbEncoding.NewFBSize)
                {
                    frameBufWidth  = (UInt16)rect.Width;
                    frameBufHeight = (UInt16)rect.Height;
                    if (!termBgThread)
                    {
                        view.NewFrameBuf(frameBufWidth, frameBufHeight);
                    }
                    break;
                }

                switch (frameBufUpdRectHdr.Encoding)
                {
                case RfbEncoding.Raw:
                    ReadRawRect(rect);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(rect);
                    }
                    break;

                case RfbEncoding.CopyRect:
                    ReadCopyRect(rect);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(rect);
                    }
                    break;

                case RfbEncoding.Rre:
                    ReadRreRect(rect);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(rect);
                    }
                    break;

                case RfbEncoding.CoRre:
                    ReadCoRreRect(rect);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(rect);
                    }
                    break;

                case RfbEncoding.Hex:
                    ReadHexRect(rect);
                    break;

                default:
                    throw new WarnEx(App.GetStr("Server is using unknown encoding!"));
                }
            }

            if (opts.ViewOpts.ScrnUpdAlgo != ScrnUpdAlgo.Asap)
            {
                view.Invalidate();
            }

            // Do this in the UI thread so we always send data in one thread.
            view.SendUpdReq();
        }
Beispiel #7
0
        private void ReadHexRect(Rectangle rect)
        {
            Color     bgColor = App.Black;
            UInt32    fgPixel = 0;
            Rectangle tile    = new Rectangle();

            for (tile.Y = rect.Y; tile.Y < rect.Bottom; tile.Y += 16)
            {
                for (tile.X = rect.X; tile.X < rect.Right; tile.X += 16)
                {
                    tile.Width  = 16;
                    tile.Height = 16;
                    tile.Width  = Math.Min(tile.Right, rect.Right) - tile.Left;
                    tile.Height = Math.Min(tile.Bottom, rect.Bottom) - tile.Top;

                    RfbHexSubEncoding encoding = (RfbHexSubEncoding)ReadByte();

                    if ((encoding & RfbHexSubEncoding.Raw) != 0)
                    {
                        ReadRawRect(tile);
                        if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                        {
                            view.InvalidateRect(tile);
                        }
                        continue;
                    }

                    byte[] data;
                    if ((encoding & RfbHexSubEncoding.BgSpec) != 0)
                    {
                        data    = ReadBytes(bytesPp);
                        bgColor = GetColorFromData(data, 0);
                    }

                    if ((encoding & RfbHexSubEncoding.FgSpec) != 0)
                    {
                        data    = ReadBytes(bytesPp);
                        fgPixel = RfbProtoUtil.GetPixelFromData(data, 0, bytesPp);
                    }

                    byte numSubRects = 0;
                    if ((encoding & RfbHexSubEncoding.AnySubRects) != 0)
                    {
                        numSubRects = ReadByte();
                    }

                    bool subRectsColored = ((encoding & RfbHexSubEncoding.SubRectsColored) != 0);

                    int subRectSize = RfbSize.HexSubRect;
                    subRectSize += subRectsColored ? (int)bytesPp : 0;
                    RreSubRectMsg[] subRects  = new RreSubRectMsg[numSubRects];
                    byte[]          rectBytes = ReadBytes(subRectSize * numSubRects);
                    for (int i = 0; i < numSubRects; i++)
                    {
                        subRects[i] = new HexSubRectMsg(rectBytes, (UInt32)(i * subRectSize), bytesPp, subRectsColored, fgPixel);
                    }
                    FillRreRect(tile, bgColor, subRects);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(tile);
                    }
                }
            }
        }
Beispiel #8
0
 private Color GetColorFromData(byte[] data, UInt32 offset)
 {
     return(GetColorFromPixel(RfbProtoUtil.GetPixelFromData(data, offset, bytesPp)));
 }
Beispiel #9
0
 internal void SendSetScale(byte scale)
 {
     byte[] msg = RfbProtoUtil.GetSetScaleMsg(scale);
     WriteBytes(msg, RfbCliMsgType.SetScale);
 }
Beispiel #10
0
 private void SendUpdReq(UInt16 x, UInt16 y, UInt16 width, UInt16 height, bool incremental)
 {
     byte[] msg = RfbProtoUtil.GetFrameBufUpdReqMsg(x, y, width, height, incremental);
     WriteBytes(msg, RfbCliMsgType.FrameBufUpdReq);
 }
Beispiel #11
0
 private void SendCliInit()
 {
     byte[] msg = RfbProtoUtil.GetCliInitMsg(opts.ViewOpts.ShareServ);
     WriteBytes(msg);
 }