Ejemplo n.º 1
0
        internal void serverClipboardCapabilities(RdpPacket data)
        {
            if (!((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.NOT_SET))
            {
                throw new Exception("Error NOT_SET message flag!");
            }

            int length = data.ReadLittleEndian32();

            int cCapabilitiesSets = data.ReadLittleEndian16();

            data.ReadLittleEndian16(); // Padding 2

            for (int i = 0; i < cCapabilitiesSets; i++)
            {
                if (data.ReadLittleEndian16() != (int)CapsType.CB_CAPSTYPE_GENERAL)
                {
                    throw new Exception("Error CB_CAPSTYPE_GENERAL value!");
                }

                int num = data.ReadLittleEndian16();

                if (num != 12)
                {
                    data.Position += (num - 4);
                }
                else
                {
                    data.ReadLittleEndian32();                                    // version
                    ServerGeneralFlags = (GeneralFlags)data.ReadLittleEndian32(); // generalFlags
                }
            }
        }
Ejemplo n.º 2
0
        internal static void processUpdate(RdpPacket data)
        {
            switch (data.ReadLittleEndian16())
            {
            case 0:
                data.Position += 2L;
                int num2 = data.ReadLittleEndian16();
                data.Position += 2L;
                Orders.processOrders(data, ISO.next_packet, num2);
                return;

            case 1:
                Bitmaps.processBitmapUpdates(data);
                return;

            case 2:
                Palette.processPalette(data);
                break;

            case 3:
                break;

            default:
                return;
            }
        }
Ejemplo n.º 3
0
        internal static RdpPacket Secure_receive(out int type)
        {
            int num = 0;

            if ((m_Packet == null) || (next_packet >= m_Packet.Length))
            {
                lastchannel = 0;
                bool bFastPath = false;
                m_Packet = Secure_receive(out bFastPath);

                if (m_Packet == null)
                {
                    type = 0;
                    return(null);
                }

                if (bFastPath)
                {
                    type        = 0xff;
                    next_packet = (int)m_Packet.Length;
                    return(m_Packet);
                }

                next_packet = (int)m_Packet.Position;
            }
            else
            {
                m_Packet.Position = next_packet;
            }

            num = m_Packet.ReadLittleEndian16();

            switch (num)
            {
            case 0x8000:
                next_packet += 8;
                type         = 0;
                return(m_Packet);

            case 0:
                throw new Exception("Invalid Data packet length!");
            }

            type = m_Packet.ReadLittleEndian16() & 15;

            if (m_Packet.Position != m_Packet.Length)
            {
                m_Packet.Position += 2L;
            }

            next_packet += num;
            lastchannel  = type;

            //Debug.WriteLine("Packet type: " + type);

            return(m_Packet);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Server MCS Connect Response PDU with GCC Conference Create Response
        /// Part 2.
        ///
        /// serverCoreData
        /// serverSecurityData
        /// serverNetworkData
        /// serverMessageChannelData
        /// </summary>
        private static void processMcsData(RdpPacket mcsData)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            mcsData.Position += 0x15L;

            if ((mcsData.ReadByte() & 0x80) != 0)
            {
                mcsData.ReadByte();
            }

            while (mcsData.Position < mcsData.Length)
            {
                num  = mcsData.ReadLittleEndian16();
                num2 = mcsData.ReadLittleEndian16();

                if (num2 <= 4)
                {
                    return;
                }

                num3 = (int)((mcsData.Position + num2) - 4L);

                switch ((SERVER)num)
                {
                case SERVER.SC_CORE:
                    processSrvCoreInfo(mcsData);
                    break;

                case SERVER.SC_SECURITY:
                    Secure.processCryptInfo(mcsData);
                    break;

                case SERVER.SC_NET:
                    processSrvNetInfo(mcsData);
                    break;

                case SERVER.SC_MCS_MSGCHANNEL:
                    int channel = mcsData.ReadLittleEndian16();
                    Debug.WriteLine("Network Characteristics Detection channel: " + channel);
                    //Channels.RegisteredChannels.Add(new NetworkCharacteristicsDetection(channel));
                    break;

                default:
                    throw new RDFatalException("MSC data incorrect tag " + num.ToString());
                }

                mcsData.Position = num3;
            }
        }
Ejemplo n.º 5
0
        internal void serverFormatListResponse(RdpPacket data)
        {
            if (((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.CB_RESPONSE_OK))
            {
                Debug.WriteLine("Server FormatListResponse: OK");
            }
            else if (((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.CB_RESPONSE_FAIL))
            {
                Debug.WriteLine("Server FormatListResponse: FAIL");
            }

            data.ReadLittleEndian32(); // length
        }
Ejemplo n.º 6
0
        private static void processFontCache(RdpPacket data, int extraFlags)
        {
            int font      = 0;
            int num2      = 0;
            int character = 0;
            int offset    = 0;
            int baseline  = 0;
            int width     = 0;
            int height    = 0;
            int count     = 0;

            byte[] buffer = null;
            int    num9   = (extraFlags >> 4) & 15;

            if ((num9 & 2) != 0)
            {
                font = extraFlags & 15;
                num2 = extraFlags >> 8;
            }
            else
            {
                font = data.ReadByte();
                num2 = data.ReadByte();
            }

            for (int i = 0; i < num2; i++)
            {
                if ((num9 & 2) != 0)
                {
                    character = data.ReadByte();
                    offset    = data.ReadEncodedSigned16();
                    baseline  = data.ReadEncodedSigned16();
                    width     = data.ReadEncodedUnsigned16();
                    height    = data.ReadEncodedUnsigned16();
                }
                else
                {
                    character = data.ReadLittleEndian16();
                    offset    = data.ReadLittleEndian16();
                    baseline  = data.ReadLittleEndian16();
                    width     = data.ReadLittleEndian16();
                    height    = data.ReadLittleEndian16();
                }

                count  = ((height * ((width + 7) / 8)) + 3) & -4;
                buffer = new byte[count];
                data.Read(buffer, 0, count);
                Glyph glyph = new Glyph(font, character, offset, baseline, width, height, buffer);
                Cache.putFont(glyph);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Server X.224 Connection Confirm PDU
        /// </summary>
        private static int receiveConnectNegotiation()
        {
            RdpPacket packet = ISO.Receive();

            packet.Position += 7L;

            if (packet.Position >= packet.Length)
            {
                return(0);
            }

            switch (packet.ReadByte())
            {
            // TYPE_RDP_NEG_RSP
            case 0x02:
                Options.serverNegotiateFlags = (NegotiationFlags)packet.ReadByte();
                packet.ReadLittleEndian16();
                return(packet.ReadLittleEndian32());

            // TYPE_RDP_NEG_FAILURE
            case 0x03:
                packet.ReadByte();
                packet.ReadLittleEndian16();

                switch ((NegotiationFailureCodes)packet.ReadLittleEndian32())
                {
                case NegotiationFailureCodes.SSL_REQUIRED_BY_SERVER:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security with TLS 1.0");

                case NegotiationFailureCodes.SSL_NOT_ALLOWED_BY_SERVER:
                    return(0x10000000);

                case NegotiationFailureCodes.SSL_CERT_NOT_ON_SERVER:
                    throw new RDFatalException("The server does not possess a valid authentication certificate and cannot initialize the External Security Protocol Provider");

                case NegotiationFailureCodes.INCONSISTENT_FLAGS:
                    throw new RDFatalException("The list of requested security protocols is not consistent with the current security protocol in effect.");

                case NegotiationFailureCodes.HYBRID_REQUIRED_BY_SERVER:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security with CredSSP");

                case NegotiationFailureCodes.SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security and certificate-based client authentication");
                }

                throw new RDFatalException("Unknown Negotiation failure!");
            }

            throw new RDFatalException("Negotiation failed, requested security level not supported by server.");
        }
Ejemplo n.º 8
0
        private static void processColorCache(RdpPacket data)
        {
            byte[] buffer = null;
            byte[] r      = null;
            byte[] g      = null;
            byte[] b      = null;
            int    index  = 0;
            int    num2   = data.ReadByte();
            int    count  = data.ReadLittleEndian16();

            buffer = new byte[count * 4];
            r      = new byte[count];
            g      = new byte[count];
            b      = new byte[count];
            data.Read(buffer, 0, buffer.Length);

            for (int i = 0; i < count; i++)
            {
                b[i]   = buffer[index];
                g[i]   = buffer[index + 1];
                r[i]   = buffer[index + 2];
                index += 4;
            }

            Cache.put_colourmap(num2, new Palette(8, count, r, g, b));
        }
Ejemplo n.º 9
0
        internal static void process_issue(RdpPacket data)
        {
            int count = 0;
            RC4 rc    = new RC4();

            byte[] destinationArray = new byte[m_LicenceKey.Length];
            Array.Copy(m_LicenceKey, 0, destinationArray, 0, m_LicenceKey.Length);
            data.ReadLittleEndian16();
            count = data.ReadLittleEndian16();

            if ((data.Position + count) <= data.Length)
            {
                rc.engineInitDecrypt(destinationArray);
                byte[] buffer = new byte[count];
                data.Read(buffer, 0, count);
                rc.crypt(buffer, 0, count, buffer, 0);
            }
        }
Ejemplo n.º 10
0
        internal void serverMonitorReady(RdpPacket data)
        {
            if (!((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.NOT_SET))
            {
                throw new Exception("Error NOT_SET message flag!");
            }

            data.ReadLittleEndian32(); // length
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Server MCS Connect Response PDU with GCC Conference Create Response
        /// Part 2.2
        ///
        /// I/O channels server supported
        /// </summary>
        private static void processSrvNetInfo(RdpPacket data)
        {
            int MCSChannelId = data.ReadLittleEndian16();

            Debug.WriteLine("Server support channel: " + MCSChannelId.ToString()); // MCSChannelId = 1003

            serverSupportedChannels.Clear();
            int channelCount = data.ReadLittleEndian16(); // channelCount

            // Проверяем каналы, поддерживаемые сервером
            for (int i = 0; i < channelCount; i++)
            {
                int channelId = data.ReadLittleEndian16();
                serverSupportedChannels.Add(channelId);

                Debug.WriteLine("Server support channel: " + channelId.ToString());
            }
        }
Ejemplo n.º 12
0
        private static void processLine(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                LineOrder.Mixmode = data.ReadLittleEndian16();
            }

            if ((present & 2) != 0)
            {
                LineOrder.StartX = setCoordinate(data, LineOrder.StartX, delta);
            }

            if ((present & 4) != 0)
            {
                LineOrder.StartY = setCoordinate(data, LineOrder.StartY, delta);
            }

            if ((present & 8) != 0)
            {
                LineOrder.EndX = setCoordinate(data, LineOrder.EndX, delta);
            }

            if ((present & 0x10) != 0)
            {
                LineOrder.EndY = setCoordinate(data, LineOrder.EndY, delta);
            }

            if ((present & 0x20) != 0)
            {
                LineOrder.BackgroundColor = setColor(data);
            }

            if ((present & 0x40) != 0)
            {
                LineOrder.Opcode = data.ReadByte();
            }

            present = present >> 7;

            if ((present & 1) != 0)
            {
                LineOrder.PenStyle = data.ReadByte();
            }

            if ((present & 2) != 0)
            {
                LineOrder.PenWidth = data.ReadByte();
            }

            if ((present & 4) != 0)
            {
                LineOrder.PenColor = setColor(data);
            }

            LineOrder.drawLineOrder();
        }
Ejemplo n.º 13
0
        internal static void processDemandActive(RdpPacket data)
        {
            int num3;

            rdp_shareid = data.ReadLittleEndian32();
            int num = data.ReadLittleEndian16();

            data.ReadLittleEndian16();
            data.Position += num;
            int numCaps = data.ReadLittleEndian16();

            data.ReadLittleEndian16();
            processServerCapabilities(data, numCaps);
            sendConfirmActive();
            sendSynchronize();
            sendControl(4);
            sendControl(1);
            ISO.Secure_receive(out num3);
            ISO.Secure_receive(out num3);
            ISO.Secure_receive(out num3);

            if (Options.persistentBmpCache && !m_bInitialised)
            {
                sendPersistKeyList();
            }

            List <Rdp.InputInfo> inputToSend = new List <Rdp.InputInfo>
            {
                new Rdp.InputInfo(0, Rdp.InputType.INPUT_EVENT_SYNC, 0, 0, 0)
            };

            //if (m_bInitialised)
            //{
            //    Options.OnInitialise();
            //}
            m_bInitialised = true;

            IsoLayer.FastSendInput(inputToSend);
            sendFontList();
            ISO.Secure_receive(out num3);
            resetOrderState();
        }
Ejemplo n.º 14
0
        private static void processMemBlt(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                MemBltOrder.CacheID    = data.ReadByte();
                MemBltOrder.ColorTable = data.ReadByte();
            }

            if ((present & 2) != 0)
            {
                MemBltOrder.X = setCoordinate(data, MemBltOrder.X, delta);
            }

            if ((present & 4) != 0)
            {
                MemBltOrder.Y = setCoordinate(data, MemBltOrder.Y, delta);
            }

            if ((present & 8) != 0)
            {
                MemBltOrder.CX = setCoordinate(data, MemBltOrder.CX, delta);
            }

            if ((present & 0x10) != 0)
            {
                MemBltOrder.CY = setCoordinate(data, MemBltOrder.CY, delta);
            }

            if ((present & 0x20) != 0)
            {
                MemBltOrder.Opcode = ROP2_S(data.ReadByte());
            }

            if ((present & 0x40) != 0)
            {
                MemBltOrder.SrcX = setCoordinate(data, MemBltOrder.SrcX, delta);
            }

            if ((present & 0x80) != 0)
            {
                MemBltOrder.SrcY = setCoordinate(data, MemBltOrder.SrcY, delta);
            }

            if ((present & 0x100) != 0)
            {
                MemBltOrder.CacheIDX = data.ReadLittleEndian16();
            }

            MemBltOrder.drawMemBltOrder();
        }
Ejemplo n.º 15
0
        internal void serverFormatDataRequest(RdpPacket data)
        {
            if (!((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.NOT_SET))
            {
                throw new Exception("Error NOT_SET message flag!");
            }

            data.ReadLittleEndian32(); // length

            if (ClipboardFormatID != data.ReadLittleEndian32())
            {
                Debug.WriteLine("Error Clipboard Format ID!");
            }
        }
Ejemplo n.º 16
0
        internal static void process(RdpPacket data)
        {
            int num = 0;

            num = data.ReadByte();
            data.ReadByte();
            data.ReadLittleEndian16();

            switch (num)
            {
            case 1:
                process_demand(data);
                return;

            case 2:
                process_authreq(data);
                return;

            case 3:
                process_issue(data);
                m_bLicensed = true;
                return;

            case 4:
                m_bLicensed = true;
                return;

            case 0xff:
                data.ReadLittleEndian32();
                data.ReadLittleEndian32();
                data.ReadLittleEndian16();
                data.ReadLittleEndian16();
                m_bLicensed = true;
                return;
            }
        }
Ejemplo n.º 17
0
        private static int setCoordinate(RdpPacket data, int coordinate, bool delta)
        {
            sbyte num = 0;

            if (delta)
            {
                num         = (sbyte)data.ReadByte();
                coordinate += num;
                return(coordinate);
            }

            coordinate = data.ReadLittleEndian16();

            return(coordinate);
        }
Ejemplo n.º 18
0
        private static void processLogonInfo(RdpPacket data)
        {
            // Вызываем событие инициализации
            Options.OnAutorization();

            int num;

            switch (data.ReadLittleEndian32())
            {
            case 0:
            case 1:
            case 2:
                return;

            case 3:
                data.ReadLittleEndian16();
                num = data.ReadLittleEndian32();

                if ((num & 1) != 0)
                {
                    if (data.ReadLittleEndian32() != 0x1c)
                    {
                        throw new Exception("Invalid length for AutoReconnectCookie!");
                    }

                    data.ReadLittleEndian32();
                    Options.LogonID = data.ReadLittleEndian32();

                    if (Options.ReconnectCookie == null)
                    {
                        Options.ReconnectCookie = new byte[0x10];
                    }

                    data.Read(Options.ReconnectCookie, 0, 0x10);
                    break;
                }
                break;

            default:
                return;
            }

            if ((num & 2) != 0)
            {
                data.ReadLittleEndian32();
                data.ReadLittleEndian32();
            }
        }
Ejemplo n.º 19
0
        internal static bool parse_authreq(RdpPacket data)
        {
            int count = 0;

            data.Position += 6L;
            count          = data.ReadLittleEndian16();

            if (count != 10)
            {
                throw new RDFatalException("Illegal length of license token!");
            }

            m_In_Token = new byte[count];
            data.Read(m_In_Token, 0, count);
            m_In_Sig = new byte[0x10];
            data.Read(m_In_Sig, 0, 0x10);

            return(data.Position == data.Length);
        }
Ejemplo n.º 20
0
        private static void processPolyLine(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                PolylineOrder.X = setCoordinate(data, PolylineOrder.X, delta);
            }

            if ((present & 2) != 0)
            {
                PolylineOrder.Y = setCoordinate(data, PolylineOrder.Y, delta);
            }

            if ((present & 4) != 0)
            {
                PolylineOrder.Opcode = data.ReadByte();
            }

            if ((present & 8) != 0)
            {
                data.ReadLittleEndian16();
            }

            if ((present & 0x10) != 0)
            {
                PolylineOrder.PenColor = setColor(data);
            }

            if ((present & 0x20) != 0)
            {
                PolylineOrder.Lines = data.ReadByte();
            }

            if ((present & 0x40) != 0)
            {
                int num = data.ReadByte();
                PolylineOrder.DataSize = num;
                byte[] buffer = new byte[num];
                data.Read(buffer, 0, buffer.Length);
                PolylineOrder.Data = buffer;
            }

            PolylineOrder.drawPolyLineOrder();
        }
Ejemplo n.º 21
0
        internal void serverFileContentsRequest(RdpPacket data)
        {
            if (!((MsgFlags)data.ReadLittleEndian16()).HasFlag(MsgFlags.NOT_SET))
            {
                throw new Exception("Error NOT_SET message flag!");
            }

            data.ReadLittleEndian32();             // length

            StreamID = data.ReadLittleEndianU32(); // Stream ID
            data.ReadLittleEndianU32();            // lindex

            var flag = (FILECONTENTS_SIZE)data.ReadLittleEndianU32();

            if (flag.HasFlag(FILECONTENTS_SIZE.FILECONTENTS_SIZE))
            {
                Debug.WriteLine("FILECONTENTS_SIZE!");

                data.ReadLittleEndian32(); // 0x00000000
                data.ReadLittleEndian32(); // 0x00000000

                if (data.ReadLittleEndian32() != 0x00000008)
                {
                    Debug.WriteLine("The cbRequested field MUST be set to 0x00000008!");
                }

                data.ReadLittleEndian32(); // clipDataId

                FileCanLoad = false;
                Debug.WriteLine("FILECONTENTS_SIZE!");
            }
            else if (flag.HasFlag(FILECONTENTS_SIZE.FILECONTENTS_RANGE))
            {
                FileCanLoad = true;
                Debug.WriteLine("FILECONTENTS_RANGE!");

                data.ReadLittleEndian32();
                data.ReadLittleEndian32();

                BufferNextPart = data.ReadLittleEndian32(); // cbRequested
            }
        }
Ejemplo n.º 22
0
        private static Rectangle[] readEncodedDeltaRects(RdpPacket data, int DeltaEntries)
        {
            Rectangle[] rectangleArray = new Rectangle[DeltaEntries];
            int         num            = data.ReadLittleEndian16();
            long        position       = data.Position;
            BitStream   stream         = new BitStream(true);

            stream.Write(data, (DeltaEntries + 1) >> 1);
            Rectangle rectangle = new Rectangle(0, 0, 0, 0);

            for (int i = 0; i < DeltaEntries; i++)
            {
                if (stream.ReadNextBit() == 0)
                {
                    rectangle.X += data.ReadEncodedSignedExtended16();
                }
                if (stream.ReadNextBit() == 0)
                {
                    rectangle.Y += data.ReadEncodedSignedExtended16();
                }
                if (stream.ReadNextBit() == 0)
                {
                    rectangle.Width = data.ReadEncodedSignedExtended16();
                }
                if (stream.ReadNextBit() == 0)
                {
                    rectangle.Height = data.ReadEncodedSignedExtended16();
                }
                rectangleArray[i] = rectangle.Clone();
            }

            long num5 = data.Position - position;

            if (num5 != num)
            {
                throw new Exception("Invalid Encoded Delta Rects!");
            }

            return(rectangleArray);
        }
Ejemplo n.º 23
0
        internal static void processPalette(RdpPacket data)
        {
            int num = 0;

            byte[] buffer = null;
            int    index  = 0;

            data.Position   += 2L;
            num              = data.ReadLittleEndian16();
            data.Position   += 2L;
            buffer           = new byte[num * 3];
            m_Global.m_Red   = new byte[num];
            m_Global.m_Green = new byte[num];
            m_Global.m_Blue  = new byte[num];
            data.Read(buffer, 0, buffer.Length);
            for (int i = 0; i < num; i++)
            {
                m_Global.m_Red[i]   = buffer[index];
                m_Global.m_Green[i] = buffer[index + 1];
                m_Global.m_Blue[i]  = buffer[index + 2];
                index += 3;
            }
        }
Ejemplo n.º 24
0
        private static void processSecondaryOrders(RdpPacket data)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            num = data.ReadLittleEndian16();
            int extraFlags = data.ReadLittleEndian16();

            num2 = data.ReadByte();
            num3 = (((int)data.Position) + num) + 7;

            switch (num2)
            {
            case 0:
                // Raw BitmapCache Order
                processBitmapCache(data, false, false);
                goto Label_019B;

            case 1:
                // ColourCache Order
                processColorCache(data);
                goto Label_019B;

            case 2:
                // BitmapCache Order
                processBitmapCache(data, true, (extraFlags & 0x400) != 0);
                goto Label_019B;

            case 3:
                // FontCache Order
                processFontCache(data, extraFlags);
                goto Label_019B;

            case 4:
                // Raw BitmapCacheV2 Order
                try
                {
                    process_bmpcache2(data, extraFlags, false);
                    goto Label_019B;
                }
                catch (IOException exception)
                {
                    throw new RDFatalException(exception.Message);
                }
                break;

            case 5:
                break;

            case 7:
                goto Label_0132;

            case 8:
                goto Label_015C;

            default:
                goto Label_0185;
            }

            // BitmapCacheV2 Order
            try
            {
                process_bmpcache2(data, extraFlags, true);
                goto Label_019B;
            }
            catch (IOException exception2)
            {
                throw new RDFatalException(exception2.Message);
            }

Label_0132:
            try
            {
                // BrushCache Order
                process_bmpcache2(data, extraFlags, true);
                goto Label_019B;
            }
            catch (IOException exception3)
            {
                throw new RDFatalException(exception3.Message);
            }

Label_015C:
            try
            {
                // BitmapCacheV3 Order
                process_bmpcache3(data, extraFlags);
                goto Label_019B;
            }
            catch (IOException exception4)
            {
                throw new RDFatalException(exception4.Message);
            }

Label_0185:
            throw new RDFatalException("Unsupported secondary order: " + num2);

Label_019B:
            if (data.Position > num3)
            {
                throw new Exception("Secondary Order overflow!");
            }

            data.Position = num3;
        }
Ejemplo n.º 25
0
        private static bool processData(RdpPacket data)
        {
            int num3, num = 0;

            data.Position += 6L;
            data.ReadLittleEndian16();
            num = data.ReadByte();
            data.ReadByte();
            data.ReadLittleEndian16();

            switch (num)
            {
            case 0x26:
                // RDP_DATA_PDU_SAVE_SESSION_INFO
                processLogonInfo(data);
                goto Label_015E;

            case 0x2f:
                // RDP_DATA_PDU_SET_ERROR_INFO
                num3 = data.ReadLittleEndian32();

                switch (num3)
                {
                case 0:
                case 12:
                    goto Label_015E;

                case 1:
                    throw new RDFatalException("The disconnection was initiated by an administrative tool on the server in another session.");

                case 2:
                    throw new RDFatalException("The disconnection was due to a forced logoff initiated by an administrative tool on the server in another session.");

                case 3:
                    throw new RDFatalException("The idle session limit timer on the server has elapsed.");

                case 4:
                    throw new RDFatalException("The active session limit timer on the server has elapsed.");

                case 5:
                    throw new RDFatalException("Another user connected to the server, forcing the disconnection of the current connection.");

                case 7:
                    throw new RDFatalException("The server denied the connection.");

                case 9:
                    throw new RDFatalException("The user cannot connect to the server due to insufficient access privileges.");

                case 11:
                    throw new RDFatalException("The disconnection was initiated by an administrative tool on the server running in the user's session.");

                case 0x102:
                    throw new RDFatalException("There are no Client Access Licenses available for the target remote computer, please contact your network administrator.");
                }
                break;

            case 2:
                processUpdate(data);
                return(false);

            case 0x1b:
                return(false);

            default:
                goto Label_015E;
            }

            // Неизвестная ошибка, наблюдалась на виртуалке нестабильной.
            if (num3 == 4498)
            {
                return(false);
            }

            throw new RDFatalException("Error code: " + num3.ToString("X8") + ", please contact Developer with this error code");

Label_015E:
            return(false);
        }
Ejemplo n.º 26
0
        internal static void processBitmapUpdates(RdpPacket data)
        {
            int num   = 0;
            int x     = 0;
            int y     = 0;
            int num4  = 0;
            int num5  = 0;
            int cx    = 0;
            int cy    = 0;
            int num8  = 0;
            int num9  = 0;
            int num10 = 0;
            int num11 = 0;
            int size  = 0;

            byte[] buffer = null;
            num = data.ReadLittleEndian16();
            for (int i = 0; i < num; i++)
            {
                x    = data.ReadLittleEndian16();
                y    = data.ReadLittleEndian16();
                num4 = data.ReadLittleEndian16();
                num5 = data.ReadLittleEndian16();
                cx   = data.ReadLittleEndian16();
                cy   = data.ReadLittleEndian16();
                int bpp = (data.ReadLittleEndian16() + 7) / 8;
                num10 = data.ReadLittleEndian16();
                num11 = data.ReadLittleEndian16();
                num8  = (num4 - x) + 1;
                num9  = (num5 - y) + 1;
                if (num10 == 0)
                {
                    buffer = new byte[(cx * cy) * bpp];
                    for (int j = 0; j < cy; j++)
                    {
                        data.Read(buffer, ((cy - j) - 1) * (cx * bpp), cx * bpp);
                    }
                    uint[] src = RdpBitmap.convertImage(buffer, bpp);
                    ChangedRect.Invalidate(x, y, cx, cy);
                    Options.Canvas.SetPixels(x, y, num8, num9, src, 0, 0, cx);
                }
                else
                {
                    if ((num10 & 0x400) != 0)
                    {
                        size = num11;
                    }
                    else
                    {
                        data.Position += 2L;
                        size           = data.ReadLittleEndian16();
                        data.Position += 4L;
                    }
                    if (bpp == 1)
                    {
                        buffer = RdpBitmap.decompress(cx, cy, size, data, bpp);
                        ChangedRect.Invalidate(x, y, num8, num9);
                        for (int k = 0; k < num9; k++)
                        {
                            int index = k * cx;
                            int num18 = 0;
                            while (num18 < num8)
                            {
                                int num19 = buffer[index];
                                Options.Canvas.SetPixel(x + num18, y + k, RdpBitmap.convertFrom8bit(num19));
                                num18++;
                                index++;
                            }
                        }
                    }
                    else
                    {
                        uint[] numArray2 = RdpBitmap.decompressInt(cx, cy, size, data, bpp);
                        ChangedRect.Invalidate(x, y, num8, num9);
                        Options.Canvas.SetPixels(x, y, num8, num9, numArray2, 0, 0, cx);
                    }
                }
            }
        }
Ejemplo n.º 27
0
        private static void processGlyphIndex(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                Text2Order.Font = data.ReadByte();
            }

            if ((present & 2) != 0)
            {
                Text2Order.Flags = data.ReadByte();
            }

            if ((present & 4) != 0)
            {
                Text2Order.Opcode = data.ReadByte();
            }

            if ((present & 8) != 0)
            {
                Text2Order.Mixmode = data.ReadByte();
            }

            if ((present & 0x10) != 0)
            {
                Text2Order.ForegroundColor = setColor(data);
            }

            if ((present & 0x20) != 0)
            {
                Text2Order.BackgroundColor = setColor(data);
            }

            if ((present & 0x40) != 0)
            {
                Text2Order.ClipLeft = data.ReadLittleEndian16();
            }

            if ((present & 0x80) != 0)
            {
                Text2Order.ClipTop = data.ReadLittleEndian16();
            }

            if ((present & 0x100) != 0)
            {
                Text2Order.ClipRight = data.ReadLittleEndian16();
            }

            if ((present & 0x200) != 0)
            {
                Text2Order.ClipBottom = data.ReadLittleEndian16();
            }

            if ((present & 0x400) != 0)
            {
                Text2Order.BoxLeft = data.ReadLittleEndian16();
            }

            if ((present & 0x800) != 0)
            {
                Text2Order.BoxTop = data.ReadLittleEndian16();
            }

            if ((present & 0x1000) != 0)
            {
                Text2Order.BoxRight = data.ReadLittleEndian16();
            }

            if ((present & 0x2000) != 0)
            {
                Text2Order.BoxBottom = data.ReadLittleEndian16();
            }

            parseBrush(data, Text2Order.Brush, present >> 14);

            if ((present & 0x80000) != 0)
            {
                Text2Order.X = data.ReadLittleEndian16();
            }

            if ((present & 0x100000) != 0)
            {
                Text2Order.Y = data.ReadLittleEndian16();
            }

            if ((present & 0x200000) != 0)
            {
                int num = data.ReadByte();
                Text2Order.GlyphLength = num;
                byte[] buffer = new byte[num];
                data.Read(buffer, 0, buffer.Length);
                Text2Order.GlyphIndices = buffer;
            }

            Text2Order.drawText();
        }
Ejemplo n.º 28
0
        private static void processTriBlt(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                TriBltOrder.CacheID    = data.ReadByte();
                TriBltOrder.ColorTable = data.ReadByte();
            }

            if ((present & 2) != 0)
            {
                TriBltOrder.X = setCoordinate(data, TriBltOrder.X, delta);
            }

            if ((present & 4) != 0)
            {
                TriBltOrder.Y = setCoordinate(data, TriBltOrder.Y, delta);
            }

            if ((present & 8) != 0)
            {
                TriBltOrder.CX = setCoordinate(data, TriBltOrder.CX, delta);
            }

            if ((present & 0x10) != 0)
            {
                TriBltOrder.CY = setCoordinate(data, TriBltOrder.CY, delta);
            }

            if ((present & 0x20) != 0)
            {
                TriBltOrder.Opcode = data.ReadByte();
            }

            if ((present & 0x40) != 0)
            {
                TriBltOrder.SrcX = setCoordinate(data, TriBltOrder.SrcX, delta);
            }

            if ((present & 0x80) != 0)
            {
                TriBltOrder.SrcY = setCoordinate(data, TriBltOrder.SrcY, delta);
            }

            if ((present & 0x100) != 0)
            {
                TriBltOrder.BackgroundColor = setColor(data);
            }

            if ((present & 0x200) != 0)
            {
                TriBltOrder.ForegroundColor = setColor(data);
            }

            parseBrush(data, TriBltOrder.Brush, present >> 10);

            if ((present & 0x8000) != 0)
            {
                TriBltOrder.CacheIDX = data.ReadLittleEndian16();
            }

            if ((present & 0x10000) != 0)
            {
                TriBltOrder.Unknown = data.ReadLittleEndian16();
            }

            TriBltOrder.drawTriBltOrder();
        }
Ejemplo n.º 29
0
        private static void processBitmapCache(RdpPacket data, bool bCompressed, bool bNoCompressionHdr)
        {
            int num2;
            int num  = num2 = 0;
            int num3 = data.ReadByte();

            data.ReadByte();
            int width  = data.ReadByte();
            int height = data.ReadByte();
            int bpp    = (data.ReadByte() + 7) / 8;

            num = data.ReadLittleEndian16();
            int num8 = data.ReadLittleEndian16();

            if (!bCompressed)
            {
                byte[] buffer = new byte[(width * height) * bpp];
                int    offset = (height - 1) * (width * bpp);

                for (int i = 0; i < height; i++)
                {
                    data.Read(buffer, offset, width * bpp);
                    offset -= width * bpp;
                }

                Cache.putBitmap(num3, num8, new RdpBitmap(buffer, width, height, bpp, 0, 0), 0);
            }
            else
            {
                if (!bNoCompressionHdr)
                {
                    data.ReadLittleEndian16();
                    num2 = data.ReadLittleEndian16();
                    data.ReadLittleEndian16();
                    data.ReadLittleEndian16();
                }
                else
                {
                    num2 = num;
                }

                if (bpp == 1)
                {
                    byte[] buffer2 = RdpBitmap.decompress(width, height, num2, data, bpp);

                    if (buffer2 != null)
                    {
                        Cache.putBitmap(num3, num8, new RdpBitmap(buffer2, width, height, bpp, 0, 0), 0);
                    }
                }
                else
                {
                    uint[] numArray = RdpBitmap.decompressInt(width, height, num2, data, bpp);

                    if (numArray != null)
                    {
                        Cache.putBitmap(num3, num8, new RdpBitmap(numArray, width, height, bpp, 0, 0), 0);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private static void process_bmpdata(RdpPacket data, int flags, int cache_id, int cache_idx, ulong persist_key)
        {
            RdpBitmap bitmap;

            byte[] buffer;
            int    bpp = data.ReadByte();

            data.ReadByte();
            data.ReadByte();
            int num2   = data.ReadByte();
            int width  = data.ReadLittleEndian16();
            int height = data.ReadLittleEndian16();
            int size   = data.ReadLittleEndian32();

            if (num2 == 1)
            {
                if (bpp == 1)
                {
                    buffer = RdpBitmap.decompress(width, height, size, data, bpp);

                    if (buffer == null)
                    {
                        return;
                    }

                    bitmap = new RdpBitmap(buffer, width, height, bpp, 0, 0);
                }
                else
                {
                    uint[] numArray = RdpBitmap.decompressInt(width, height, size, data, bpp);

                    if (numArray == null)
                    {
                        return;
                    }

                    bitmap = new RdpBitmap(numArray, width, height, bpp, 0, 0);
                }
            }
            else
            {
                buffer = new byte[(width * height) * bpp];

                for (int i = 0; i < height; i++)
                {
                    data.Read(buffer, ((height - i) - 1) * (width * bpp), width * bpp);
                }

                if (bpp == 1)
                {
                    bitmap = new RdpBitmap(buffer, width, height, bpp, 0, 0);
                }
                else
                {
                    bitmap = new RdpBitmap(RdpBitmap.convertImage(buffer, bpp), width, height, bpp, 0, 0);
                }
            }

            if (bitmap != null)
            {
                Cache.putBitmap(cache_id, cache_idx, bitmap, 0);

                if ((flags & 0x100) != 0)
                {
                    bitmap.PersistCache(persist_key);
                    Cache.m_BitmapCaches++;
                }
            }
        }