Ejemplo n.º 1
0
        internal static void channel_process(int channelID, RdpPacket data)
        {
            data.ReadLittleEndian32();
            var num = (CHANNEL_FLAG)data.ReadLittleEndian32();

            if (num.HasFlag(CHANNEL_FLAG.CHANNEL_FLAG_FIRST))
            {
                m_FullPacket = new RdpPacket();
            }

            m_FullPacket.Append(data);

            if (num.HasFlag(CHANNEL_FLAG.CHANNEL_FLAG_LAST))
            {
                m_FullPacket.Position = 0L;

                foreach (IVirtualChannel channel in m_Channels)
                {
                    if (channel.ChannelID == channelID)
                    {
                        channel.channel_process(m_FullPacket);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static bool parsePublicKey(RdpPacket data)
        {
            int num  = 0;
            int num2 = 0;

            num = data.ReadLittleEndian32();

            if (num != 0x31415352)
            {
                int num3 = 0x31415352;
                throw new RDFatalException("Bad magic header ! Need " + num3.ToString() + " but got " + num.ToString());
            }

            num2 = data.ReadLittleEndian32();

            if (num2 != (modulus_size + 8))
            {
                modulus_size = num2 - 8;
            }

            data.Position += 8L;
            m_Exponent     = new byte[4];
            data.Read(m_Exponent, 0, 4);
            m_Modulus = new byte[modulus_size];
            data.Read(m_Modulus, 0, modulus_size);

            return(data.Position <= data.Length);
        }
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
0
        internal static RdpPacket Secure_receive(out bool bFastPath)
        {
            int num, num2;

            MCS.TS_SECURITY_HEADER num3;
            RdpPacket packet = null;

Label_0001:
            bFastPath = false;
            packet    = ReceiveMCS(out num, out num2);

            if (packet == null)
            {
                return(null);
            }

            switch (num2)
            {
            case 0xff:
                bFastPath = true;
                return(packet);

            case 0xfe:
                packet    = Secure.DecryptPacket(packet);
                bFastPath = true;
                return(packet);
            }

            if (Secure.RDPEncrypted() || Licence.IsLicensePacket(packet))
            {
                num3 = (MCS.TS_SECURITY_HEADER)packet.ReadLittleEndian32();

                if (num3.HasFlag(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT))
                {
                    packet = Secure.DecryptPacket(packet);
                }

                if (num3.HasFlag(MCS.TS_SECURITY_HEADER.SEC_LICENSE_PKT))
                {
                    Licence.process(packet);
                    goto Label_0001;
                }

                if (num3.HasFlag(MCS.TS_SECURITY_HEADER.SEC_REDIRECTION_PKT))
                {
                    ControlFlow.processRedirection(packet, true);
                    goto Label_0001;
                }
            }

            if (num != MCS.MSC_GLOBAL_CHANNEL)
            {
                Channels.channel_process(num, packet);
                goto Label_0001;
            }

            return(packet);
        }
Ejemplo n.º 7
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.º 8
0
 /// <summary>
 /// Server MCS Connect Response PDU with GCC Conference Create Response
 /// Part 2.1
 ///
 /// Rdp 5 supported
 /// </summary>
 private static void processSrvCoreInfo(RdpPacket data)
 {
     // 0x00080001 - RDP 4.0 servers
     // 0x00080004 - RDP 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, and 8.0 servers
     if (data.ReadLittleEndian32() == 0x00080001)
     {
         Options.use_rdp5 = false;
     }
 }
Ejemplo n.º 9
0
        public static bool IsLicensePacket(RdpPacket packet)
        {
            if (m_bLicensed)
            {
                return(false);
            }

            int num = packet.ReadLittleEndian32();

            packet.Position -= 4L;

            return((num & 0x80) != 0);
        }
Ejemplo n.º 10
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.º 11
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.º 12
0
        private static void processDeskSave(RdpPacket data, int present, bool delta)
        {
            if ((present & 1) != 0)
            {
                DeskSaveOrder.Offset = data.ReadLittleEndian32();
            }

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

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

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

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

            if ((present & 0x20) != 0)
            {
                DeskSaveOrder.Action = data.ReadByte();
            }

            int cx = (DeskSaveOrder.Right - DeskSaveOrder.Left) + 1;
            int cy = (DeskSaveOrder.Bottom - DeskSaveOrder.Top) + 1;

            if (DeskSaveOrder.Action == 0)
            {
                int[] numArray = Options.Canvas.GetPixels(DeskSaveOrder.Left, DeskSaveOrder.Top, cx, cy);
                Cache.putDesktop(DeskSaveOrder.Offset, cx, cy, numArray);
            }
            else
            {
                int[] src = Cache.getDesktopInt(DeskSaveOrder.Offset, cx, cy);
                Options.Canvas.SetPixels(DeskSaveOrder.Left, DeskSaveOrder.Top, cx, cy, src, 0, 0, cx);
            }
        }
Ejemplo n.º 13
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.º 14
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.º 15
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.º 16
0
        public byte[] ProcessChallenge(byte[] Challenge)
        {
            byte[]    bytes;
            RdpPacket packet = new RdpPacket();

            this.m_ChallengeMsg = Challenge;
            packet.Write(Challenge, 0, Challenge.Length);
            packet.Position = 0L;
            long position = packet.Position;

            if (packet.ReadString(8) != "NTLMSSP\0")
            {
                throw new Exception("Invalid negotiation token!");
            }

            if (packet.ReadLittleEndian32() != 2)
            {
                throw new Exception("Expected challenge!");
            }

            int count = packet.ReadLittleEndian16();

            packet.ReadLittleEndian16();
            int  num4  = packet.ReadLittleEndian32();
            uint flags = (uint)packet.ReadLittleEndian32();

            DumpFlags(flags);
            byte[] buffer = new byte[8];
            packet.Read(buffer, 0, 8);
            DumpHex(buffer, buffer.Length, "Server Challenge");
            byte[] buffer2 = new byte[8];
            packet.Read(buffer2, 0, 8);
            int num5 = packet.ReadLittleEndian16();

            packet.ReadLittleEndian16();
            int num6 = packet.ReadLittleEndian32();

            if ((flags & 0x2000000) != 0)
            {
                byte[] buffer3 = new byte[8];
                packet.Read(buffer3, 0, 8);
            }

            if ((flags & 0x20000000) == 0)
            {
                throw new Exception("Strong Encryption not supported by server");
            }

            byte[] buffer4 = null;

            if (count > 0)
            {
                buffer4         = new byte[count];
                packet.Position = position + num4;
                packet.Read(buffer4, 0, count);
                Encoding.Unicode.GetString(buffer4, 0, buffer4.Length);
            }

            AV_PAIRS av_pairs = new AV_PAIRS();

            byte[] buffer5 = null;

            if (num5 <= 0)
            {
                throw new Exception("No TargetInfo!");
            }

            packet.Position = position + num6;
            buffer5         = new byte[num5];
            packet.Read(buffer5, 0, num5);
            packet = new RdpPacket();
            packet.Write(buffer5, 0, buffer5.Length);
            packet.Position = 0L;
            av_pairs.Parse(packet);

            buffer5 = av_pairs.Serialise();

            byte[] data = nTOWFv2(this.m_sDomain, this.m_sUsername, this.m_sPassword);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    data = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ResponseKeyNT);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ResponseKeyNT, data);
                }
            }

            byte[] blob = new byte[8];
            RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();

            provider.GetBytes(blob);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    blob = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ClientChallenge);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ClientChallenge, blob);
                }
            }

            DumpHex(blob, blob.Length, "Client Challenge");
            byte[] buffer8 = getLMv2Response(data, buffer, blob);
            DumpHex(buffer8, buffer8.Length, "LM Response");

            if (this.m_bNTLMv2)
            {
                Array.Clear(buffer8, 0, buffer8.Length);
            }

            bool bGenerateMIC = false;

            if ((av_pairs.Timestamp.length <= 0) || !this.m_bNTLMv2)
            {
                bytes = BitConverter.GetBytes(DateTime.UtcNow.ToFileTimeUtc());
            }
            else
            {
                bytes        = av_pairs.Timestamp.value;
                bGenerateMIC = true;
                av_pairs.ProcessForNTLMv2();
                buffer5 = av_pairs.Serialise();
            }

            DumpHex(buffer5, buffer5.Length, "targetinfo");
            byte[] keyExchangeKey = null;
            byte[] buffer11       = getNTLMv2Response(data, buffer, blob, bytes, buffer5, out keyExchangeKey);
            DumpHex(buffer11, buffer11.Length, "NTLMv2 Response");

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    keyExchangeKey = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_KeyExchangeKey);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_KeyExchangeKey, keyExchangeKey);
                }
            }

            byte[] encryptedRandomSessionKey = null;
            byte[] buffer13 = null;
            buffer13 = new byte[0x10];
            provider.GetBytes(buffer13);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    buffer13 = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ExportedSessionKey);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ExportedSessionKey, buffer13);
                }
            }

            encryptedRandomSessionKey = new byte[0x10];
            RC4 rc = new RC4();

            rc.engineInitEncrypt(keyExchangeKey);
            encryptedRandomSessionKey = rc.crypt(buffer13);

            if ((flags & 0x40000000) == 0)
            {
                encryptedRandomSessionKey = new byte[0];
                buffer13 = keyExchangeKey;
            }

            this.InitSignKeys(buffer13);

            return(this.Authenticate(buffer8, buffer11, this.m_sDomain, this.m_sUsername, this.m_sWorkstation, encryptedRandomSessionKey, buffer13, bGenerateMIC));
        }
Ejemplo n.º 17
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.º 18
0
        internal static int parseCryptInfo(RdpPacket data)
        {
            int num2, num3, num4, num5, num6, num7, num8 = 0;

            num7 = data.ReadLittleEndian32(); // ENCRYPTION_METHOD
            num8 = data.ReadLittleEndian32(); // ENCRYPTION_LEVEL

            //System.Windows.Forms.MessageBox.Show(
            //    "Encryption Method : " + ((MCS.EncryptionMethod)num7).ToString() +
            //    "\r\nEncryption Level: " + ((MCS.EncryptionLevel)num8).ToString());

            if (num8 == 0)
            {
                if (!Network.SSLConnection)
                {
                    throw new RDFatalException("Server does not support encrypted connections!");
                }

                return(0);
            }

            int count = data.ReadLittleEndian32();

            num2 = data.ReadLittleEndian32();

            if (count != 0x20)
            {
                string[] strArray = new string[] { "Wrong size of random key size! Accepted ", count.ToString(), " but ", 0x20.ToString(), "!" };
                throw new RDFatalException(string.Concat(strArray));
            }

            m_Server_Random = new byte[count];
            data.Read(m_Server_Random, 0, count);
            num6 = ((int)data.Position) + num2;

            if (num6 > data.Length)
            {
                throw new RDFatalException("Crypt Info too short!");
            }

            if ((data.ReadLittleEndian32() & 1) != 0)
            {
                data.Position += 8L;

                while (data.Position < data.Length)
                {
                    num3 = data.ReadLittleEndian16();
                    num4 = data.ReadLittleEndian16();
                    num5 = ((int)data.Position) + num4;

                    switch (num3)
                    {
                    case 6:
                        if (parsePublicKey(data))
                        {
                            break;
                        }
                        return(0);
                    }

                    data.Position = num5;
                }

                return(num7);
            }

            int num9  = data.ReadLittleEndian32();
            int num10 = 0;

            if (num9 < 2)
            {
                throw new RDFatalException("Illegal number of certificates " + num9.ToString());
            }

            while (num9 > 2)
            {
                num10          = data.ReadLittleEndian32();
                data.Position += num10;
                num9--;
            }

            byte[] buffer = new byte[data.ReadLittleEndian32()];
            data.Read(buffer, 0, buffer.Length);
            X509Certificate certificate = new X509Certificate(buffer);

            m_Server_Public_Key = new byte[Main.SecureValue1];
            Array.Copy(certificate.GetPublicKey(), 5, m_Server_Public_Key, 0, Main.SecureValue1);
            byte[] buffer2 = new byte[data.ReadLittleEndian32()];
            data.Read(buffer2, 0, buffer2.Length);
            X509Certificate certificate2 = new X509Certificate(buffer2);

            m_Server_Public_Key = new byte[Main.SecureValue1];
            Array.Copy(certificate2.GetPublicKey(), 5, m_Server_Public_Key, 0, Main.SecureValue1);
            readCert = true;

            return(num7);
        }
Ejemplo n.º 19
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++;
                }
            }
        }
Ejemplo n.º 20
0
        internal static void processRedirection(RdpPacket data, bool bStdRedirect)
        {
            if (!bStdRedirect)
            {
                data.ReadLittleEndian16();
            }

            data.ReadLittleEndian16();
            data.ReadLittleEndian16();
            Options.sessionID = data.ReadLittleEndian32();
            int num = data.ReadLittleEndian32();

            if ((num & 1) != 0)
            {
                Options.Host = data.ReadUnicodeString();
            }

            byte[] buffer = null;

            if ((num & 2) != 0)
            {
                int count = data.ReadLittleEndian32();
                buffer = new byte[count];
                data.Read(buffer, 0, count);
            }

            if ((num & 4) != 0)
            {
                Options.Username = data.ReadUnicodeString();
            }

            if ((num & 8) != 0)
            {
                Options.Domain = data.ReadUnicodeString();
            }

            if ((num & 0x10) != 0)
            {
                Options.Password = data.ReadUnicodeString();
            }

            if ((num & 0x200) != 0)
            {
                Options.Host = data.ReadUnicodeString();
            }

            if ((num & 0x100) != 0)
            {
                Options.Host = data.ReadUnicodeString();
            }

            if (!string.IsNullOrEmpty(Options.Domain))
            {
                Options.DomainAndUsername = Options.Domain + @"\" + Options.Username;
            }
            else
            {
                Options.DomainAndUsername = Options.Username;
            }

            if ((num & 0x80) == 0)
            {
                Network.Close();
                Licence.Reset();
                Network.Connect(Options.Host, Options.Port);
                MCS.sendСonnectionRequest(buffer, false);
            }
        }
Ejemplo n.º 21
0
            public void Parse(RdpPacket packet)
            {
                NTLM.AV_ID av_id;
                byte[]     buffer = null;
                do
                {
                    av_id = (NTLM.AV_ID)packet.ReadLittleEndian16();
                    int count = packet.ReadLittleEndian16();
                    if (count > 0)
                    {
                        if (av_id != NTLM.AV_ID.MsvAvFlags)
                        {
                            buffer = new byte[count];
                            packet.Read(buffer, 0, count);
                        }
                        else
                        {
                            this.Flags = packet.ReadLittleEndian32();
                        }
                    }
                    switch (av_id)
                    {
                    case NTLM.AV_ID.MsvAvNbComputerName:
                        this.NbComputerName.length = count;
                        this.NbComputerName.value  = buffer;
                        this.sNbComputerName       = Encoding.Unicode.GetString(this.NbComputerName.value, 0, this.NbComputerName.value.Length);
                        break;

                    case NTLM.AV_ID.MsvAvNbDomainName:
                        this.NbDomainName.length = count;
                        this.NbDomainName.value  = buffer;
                        this.sNbDomainName       = Encoding.Unicode.GetString(this.NbDomainName.value, 0, this.NbDomainName.value.Length);
                        break;

                    case NTLM.AV_ID.MsvAvDnsComputerName:
                        this.DnsComputerName.length = count;
                        this.DnsComputerName.value  = buffer;
                        this.sDnsComputerName       = Encoding.Unicode.GetString(this.DnsComputerName.value, 0, this.DnsComputerName.value.Length);
                        break;

                    case NTLM.AV_ID.MsvAvDnsDomainName:
                        this.DnsDomainName.length = count;
                        this.DnsDomainName.value  = buffer;
                        this.sDnsDomainName       = Encoding.Unicode.GetString(this.DnsDomainName.value, 0, this.DnsDomainName.value.Length);
                        break;

                    case NTLM.AV_ID.MsvAvDnsTreeName:
                        this.DnsTreeName.length = count;
                        this.DnsTreeName.value  = buffer;
                        break;

                    case NTLM.AV_ID.MsvAvTimestamp:
                        this.Timestamp.length = count;
                        this.Timestamp.value  = buffer;
                        break;

                    case NTLM.AV_ID.MsvAvRestrictions:
                        this.Restrictions.length = count;
                        this.Restrictions.value  = buffer;
                        break;

                    case NTLM.AV_ID.MsvAvTargetName:
                        this.TargetName.length = count;
                        this.TargetName.value  = buffer;
                        break;

                    case NTLM.AV_ID.MsvChannelBindings:
                        this.ChannelBindings.length = count;
                        this.ChannelBindings.value  = buffer;
                        break;
                    }
                }while (av_id != NTLM.AV_ID.MsvAvEOL);
            }