Exemplo n.º 1
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));
        }
Exemplo n.º 2
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++;
                }
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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);
                    }
                }
            }
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Client MCS Connect Initial PDU
        /// Part 2
        ///
        /// Create packet
        /// </summary>
        internal static RdpPacket sendMcsData(bool useRdp5, int num_channels, int serverSelectedProtocol)
        {
            RdpPacket packet = new RdpPacket();

            // Проверка длины Client Name
            string clientName = Options.ClientName;

            if (clientName.Length > 15)
            {
                clientName = clientName.Substring(0, 15);
            }

            int num  = 2 * clientName.Length;
            int num2 = 0x9e;

            if (useRdp5)
            {
                num2 += 0x60;
            }

            if (useRdp5 && (num_channels > 0))
            {
                num2 += (num_channels * 12) + 8;
            }

            if (Options.serverNegotiateFlags.HasFlag(NegotiationFlags.EXTENDED_CLIENT_DATA_SUPPORTED))
            {
                num2 += 8;
            }

            packet.WriteBigEndian16((short)5);
            packet.WriteBigEndian16((short)20);
            packet.WriteByte(0x7c);
            packet.WriteBigEndian16((short)1);
            packet.WriteBigEndian16((short)(num2 | 0x8000));
            packet.WriteBigEndian16((short)8);
            packet.WriteBigEndian16((short)0x10);
            packet.WriteByte(0);
            packet.WriteLittleEndian16((ushort)0xc001);
            packet.WriteByte(0);
            packet.WriteLittleEndian32(0x61637544);
            packet.WriteBigEndian16((short)((num2 - 14) | 0x8000));

            // Client Core Data (TS_UD_CS_CORE)
            packet.WriteLittleEndian16((ushort)CLIENT.CS_CORE);
            packet.WriteLittleEndian16(useRdp5 ? ((short)0xd8) : ((short)0x88));
            packet.WriteLittleEndian16(useRdp5 ? ((short)4) : ((short)1));
            packet.WriteLittleEndian16((short)8);
            packet.WriteLittleEndian16((short)Options.width);  // Width
            packet.WriteLittleEndian16((short)Options.height); // Height
            packet.WriteLittleEndian16((ushort)0xca01);
            packet.WriteLittleEndian16((ushort)0xaa03);
            packet.WriteLittleEndian32(Options.Keyboard);        // Клавиатура
            packet.WriteLittleEndian32(useRdp5 ? 0xa28 : 0x1a3); // Client Build
            packet.WriteUnicodeString(clientName);               // Client Name
            packet.Position += 30 - num;
            packet.WriteLittleEndian32(0x00000004);              // IBM enhanced (101- or 102-key) keyboard
            packet.WriteLittleEndian32(0);
            packet.WriteLittleEndian32(12);                      // Функциональные клавиши (F1-F12)
            packet.Position += 0x40L;
            packet.WriteLittleEndian16((ushort)0xCA01);          // NS_UD_COLOR_8BPP
            packet.WriteLittleEndian16(useRdp5 ? ((short)1) : ((short)0));

            if (useRdp5)
            {
                packet.WriteLittleEndian32(0);
                packet.WriteLittleEndian16((short)((byte)Options.server_bpp));
                packet.WriteLittleEndian16((short)7);
                packet.WriteLittleEndian16((short)1);
                packet.Position += 0x40L;
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteLittleEndian32(serverSelectedProtocol);

                // Client Cluster Data (TS_UD_CS_CLUSTER)
                packet.WriteLittleEndian16((ushort)CLIENT.CS_CLUSTER);
                packet.WriteLittleEndian16((short)12);
                int num3 = 13;

                if (Options.flags.HasFlag(HostFlags.ConsoleSession) || (Options.sessionID != 0))
                {
                    num3 |= 2;
                }

                packet.WriteLittleEndian32(num3);
                packet.WriteLittleEndian32(Options.sessionID);
            }

            // Client Security Data (TS_UD_CS_SEC)
            packet.WriteLittleEndian16((ushort)CLIENT.CS_SECURITY);
            packet.WriteLittleEndian16(useRdp5 ? ((short)12) : ((short)8));

            int num4 = 0;

            if (serverSelectedProtocol == 0)
            {
                num4 |= 3;
            }

            packet.WriteLittleEndian32(num4);

            if (useRdp5)
            {
                packet.WriteLittleEndian32(0);
            }

            // Client Network Data (TS_UD_CS_NET)
            if (useRdp5 && (num_channels > 0))
            {
                packet.WriteLittleEndian16((ushort)CLIENT.CS_NET);
                packet.WriteLittleEndian16((short)((num_channels * 12) + 8));
                packet.WriteLittleEndian32(num_channels);

                foreach (IVirtualChannel channel in Channels.RegisteredChannels)
                {
                    Debug.WriteLine("Client Network Data. Channel name length: " + channel.ChannelName.Length);

                    packet.WriteString(channel.ChannelName, false);
                    packet.WriteBigEndian32((uint)(CHANNEL_DEF.CHANNEL_OPTION_INITIALIZED));
                }
            }

            // Client Message Channel Data (TS_UD_CS_MCS_MSGCHANNEL)
            if (Options.serverNegotiateFlags.HasFlag(NegotiationFlags.EXTENDED_CLIENT_DATA_SUPPORTED))
            {
                packet.WriteLittleEndian16((ushort)CLIENT.CS_MCS_MSGCHANNEL);
                packet.WriteLittleEndian16((short)8);
                packet.WriteLittleEndian32(0);
            }

            return(packet);
        }
Exemplo n.º 7
0
        public void channel_process(RdpPacket data)
        {
            byte[] buffer = new byte[2];
            data.Read(buffer, 0, 2);
            var num = (MsgType)BitConverter.ToUInt16(buffer, 0);

            Debug.WriteLine(num);

            // Проверка, загружен ли файл
            if (!IsFileLoaded)
            {
                return;
            }

            switch (num)
            {
            case MsgType.CB_MONITOR_READY:
                serverMonitorReady(data);
                clientClipboardCapabilities();
                //clientTemporaryDirectory();
                clientFormatList();
                break;

            case MsgType.CB_FORMAT_LIST:
                break;

            case MsgType.CB_FORMAT_LIST_RESPONSE:
                serverFormatListResponse(data);
                break;

            case MsgType.CB_FORMAT_DATA_REQUEST:
                serverFormatDataRequest(data);
                clientFormatDataResponse();
                break;

            case MsgType.CB_FORMAT_DATA_RESPONSE:
                break;

            case MsgType.CB_TEMP_DIRECTORY:
                break;

            case MsgType.CB_CLIP_CAPS:
                serverClipboardCapabilities(data);
                break;

            case MsgType.CB_FILECONTENTS_REQUEST:
                serverFileContentsRequest(data);
                clientFileContentsResponse();
                break;

            case MsgType.CB_FILECONTENTS_RESPONSE:
                break;

            case MsgType.CB_LOCK_CLIPDATA:
                break;

            case MsgType.CB_UNLOCK_CLIPDATA:
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
 public void Append(RdpPacket value)
 {
     byte[] buffer = new byte[value.Length - value.Position];
     value.Read(buffer, 0, buffer.Length);
     this.Write(buffer, 0, buffer.Length);
 }
Exemplo n.º 9
0
 public void channel_process(RdpPacket data)
 {
     Debug.WriteLine("Channel SOUND!");
 }
 public void channel_process(RdpPacket data)
 {
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
            public byte[] Serialise()
            {
                RdpPacket packet = new RdpPacket();

                if (this.NbDomainName.length > 0)
                {
                    packet.WriteLittleEndian16((short)2);
                    packet.WriteLittleEndian16((short)this.NbDomainName.length);
                    packet.Write(this.NbDomainName.value, 0, this.NbDomainName.length);
                }
                if (this.NbComputerName.length > 0)
                {
                    packet.WriteLittleEndian16((short)1);
                    packet.WriteLittleEndian16((short)this.NbComputerName.length);
                    packet.Write(this.NbComputerName.value, 0, this.NbComputerName.length);
                }
                if (this.DnsDomainName.length > 0)
                {
                    packet.WriteLittleEndian16((short)4);
                    packet.WriteLittleEndian16((short)this.DnsDomainName.length);
                    packet.Write(this.DnsDomainName.value, 0, this.DnsDomainName.length);
                }
                if (this.DnsComputerName.length > 0)
                {
                    packet.WriteLittleEndian16((short)3);
                    packet.WriteLittleEndian16((short)this.DnsComputerName.length);
                    packet.Write(this.DnsComputerName.value, 0, this.DnsComputerName.length);
                }
                if (this.DnsTreeName.length > 0)
                {
                    packet.WriteLittleEndian16((short)5);
                    packet.WriteLittleEndian16((short)this.DnsTreeName.length);
                    packet.Write(this.DnsTreeName.value, 0, this.DnsTreeName.length);
                }
                if (this.Timestamp.length > 0)
                {
                    packet.WriteLittleEndian16((short)7);
                    packet.WriteLittleEndian16((short)this.Timestamp.length);
                    packet.Write(this.Timestamp.value, 0, this.Timestamp.length);
                }
                if (this.Flags != 0)
                {
                    packet.WriteLittleEndian16((short)6);
                    packet.WriteLittleEndian16((short)4);
                    packet.WriteLittleEndian32(this.Flags);
                }
                if (this.Restrictions.length > 0)
                {
                    packet.WriteLittleEndian16((short)8);
                    packet.WriteLittleEndian16((short)this.Restrictions.length);
                    packet.Write(this.Restrictions.value, 0, this.Restrictions.length);
                }
                if (this.ChannelBindings.length > 0)
                {
                    packet.WriteLittleEndian16((short)10);
                    packet.WriteLittleEndian16((short)this.ChannelBindings.length);
                    packet.Write(this.ChannelBindings.value, 0, this.ChannelBindings.length);
                }
                if (this.TargetName.value != null)
                {
                    packet.WriteLittleEndian16((short)9);
                    packet.WriteLittleEndian16((short)this.TargetName.length);
                    packet.Write(this.TargetName.value, 0, this.TargetName.length);
                }
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WritePadding(8);
                byte[] buffer = new byte[packet.Length];
                packet.Position = 0L;
                packet.Read(buffer, 0, buffer.Length);
                return(buffer);
            }
Exemplo n.º 13
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);
            }
Exemplo n.º 14
0
        private byte[] Authenticate(byte[] lmChallengeResponse, byte[] ntChallengeResponse, string sDomainName, string sUser, string sWorkstation, byte[] EncryptedRandomSessionKey, byte[] ExportedSessionKey, bool bGenerateMIC)
        {
            RdpPacket packet = new RdpPacket();
            uint      flags  = (
                (((((0xe2800000 | NTLMSSP_NEGOTIATE_EXTENDED_SESSION_SECURITY) |
                    NTLMSSP_NEGOTIATE_ALWAYS_SIGN) | NTLMSSP_NEGOTIATE_NTLM) |
                  NTLMSSP_NEGOTIATE_SEAL) | NTLMSSP_NEGOTIATE_SIGN) |
                NTLMSSP_REQUEST_TARGET) | NTLMSSP_NEGOTIATE_UNICODE;

            DumpFlags(flags);
            int position = (int)packet.Position;

            packet.WriteString("NTLMSSP", false);
            packet.WriteByte(0);
            packet.WriteLittleEndian32(3);
            int num3 = ((int)packet.Position) - position;

            num3 += 8;
            num3 += 8;
            num3 += 8;
            num3 += 8;
            num3 += 8;
            num3 += 8;
            num3 += 4;

            if ((flags & 0x2000000) != 0)
            {
                num3 += 8;
            }

            if (bGenerateMIC)
            {
                num3 += 0x10;
            }

            byte[] bytes   = Encoding.Unicode.GetBytes(sDomainName);
            byte[] buffer  = Encoding.Unicode.GetBytes(sUser);
            byte[] buffer3 = Encoding.Unicode.GetBytes(sWorkstation);
            int    num4    = num3;
            int    num5    = num4 + bytes.Length;
            int    num6    = num5 + buffer.Length;
            int    num7    = num6 + buffer3.Length;
            int    num8    = num7 + lmChallengeResponse.Length;
            int    num9    = num8 + ntChallengeResponse.Length;

            packet.WriteLittleEndian16((ushort)lmChallengeResponse.Length);
            packet.WriteLittleEndian16((ushort)lmChallengeResponse.Length);
            packet.WriteLittleEndian32(num7);
            num3 += lmChallengeResponse.Length;
            packet.WriteLittleEndian16((ushort)ntChallengeResponse.Length);
            packet.WriteLittleEndian16((ushort)ntChallengeResponse.Length);
            packet.WriteLittleEndian32(num8);
            num3 += ntChallengeResponse.Length;
            packet.WriteLittleEndian16((ushort)bytes.Length);
            packet.WriteLittleEndian16((ushort)bytes.Length);
            packet.WriteLittleEndian32(num4);
            num3 += bytes.Length;
            packet.WriteLittleEndian16((ushort)buffer.Length);
            packet.WriteLittleEndian16((ushort)buffer.Length);
            packet.WriteLittleEndian32(num5);
            num3 += buffer.Length;
            packet.WriteLittleEndian16((ushort)buffer3.Length);
            packet.WriteLittleEndian16((ushort)buffer3.Length);
            packet.WriteLittleEndian32(num6);
            num3 += buffer3.Length;
            packet.WriteLittleEndian16((ushort)EncryptedRandomSessionKey.Length);
            packet.WriteLittleEndian16((ushort)EncryptedRandomSessionKey.Length);
            packet.WriteLittleEndian32(num9);
            num3 += EncryptedRandomSessionKey.Length;
            packet.WriteLittleEndian32(flags);

            if ((flags & 0x2000000) != 0)
            {
                this.WriteVersion(packet);
            }

            long num10 = packet.Position;

            if (bGenerateMIC)
            {
                packet.WritePadding(0x10);
            }

            packet.Write(bytes, 0, bytes.Length);
            packet.Write(buffer, 0, buffer.Length);
            packet.Write(buffer3, 0, buffer3.Length);
            packet.Write(lmChallengeResponse, 0, lmChallengeResponse.Length);
            packet.Write(ntChallengeResponse, 0, ntChallengeResponse.Length);
            packet.Write(EncryptedRandomSessionKey, 0, EncryptedRandomSessionKey.Length);

            if (bGenerateMIC)
            {
                packet.Position = 0L;
                byte[] buffer4 = new byte[packet.Length];
                packet.Read(buffer4, 0, buffer4.Length);
                HMACT64 hmact = new HMACT64(ExportedSessionKey);
                hmact.update(this.m_NegotiateMsg);
                hmact.update(this.m_ChallengeMsg);
                hmact.update(buffer4);
                byte[] buffer5 = hmact.digest();
                packet.Position = num10;
                packet.Write(buffer5, 0, buffer5.Length);
            }

            packet.Position = 0L;
            byte[] buffer6 = new byte[packet.Length];
            packet.Read(buffer6, 0, buffer6.Length);

            return(buffer6);
        }
Exemplo n.º 15
0
        private static void sendPersistKeyList()
        {
            int num   = 0;
            int num2  = 0;
            int num3  = 0;
            int num4  = 0;
            int num5  = 0;
            int num6  = 0;
            int num7  = 0;
            int num8  = 0;
            int num9  = 0;
            int num10 = 0;

            Cache.TotalBitmapCache(out num, out num2, out num3, out num4, out num5);
            int offset = 0;

            while ((((num6 < num) || (num7 < num2)) || ((num8 < num3) || (num9 < num4))) || (num10 < num5))
            {
                int          num12     = 0;
                int          num13     = 0;
                int          num14     = 0;
                int          num15     = 0;
                int          num16     = 0;
                bool         bMoreKeys = false;
                List <ulong> list      = Cache.GetBitmapCache(offset, 0xff, out num12, out num13, out num14, out num15, out num16, out bMoreKeys);
                RdpPacket    packet    = new RdpPacket();
                packet.WriteLittleEndian16((ushort)num12);
                packet.WriteLittleEndian16((ushort)num13);
                packet.WriteLittleEndian16((ushort)num14);
                packet.WriteLittleEndian16((ushort)num15);
                packet.WriteLittleEndian16((ushort)num16);
                packet.WriteLittleEndian16((ushort)num);
                packet.WriteLittleEndian16((ushort)num2);
                packet.WriteLittleEndian16((ushort)num3);
                packet.WriteLittleEndian16((ushort)num4);
                packet.WriteLittleEndian16((ushort)num5);
                byte num17 = 0;
                if (offset == 0)
                {
                    num17 = (byte)(num17 | 1);
                }
                if (!bMoreKeys)
                {
                    num17 = (byte)(num17 | 2);
                }
                packet.WriteByte(num17);
                packet.WriteByte(0);
                packet.WriteLittleEndian16((short)0);
                foreach (ulong num18 in list)
                {
                    packet.Write(BitConverter.GetBytes(num18), 0, 8);
                }
                IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
                offset += list.Count;
                num6   += num12;
                num7   += num13;
                num8   += num14;
                num9   += num15;
                num10  += num16;
            }
        }
Exemplo n.º 16
0
        internal static RdpPacket ReceiveTPKTOrFastPath(out int type)
        {
            int       num  = 0;
            int       num2 = 0;
            RdpPacket p    = Tcp_recv(null, 4);

            p.Position = 0L;

            if (p.Length == 0L)
            {
                type = -1;
                return(null);
            }

            num2 = p.ReadByte();

            if (num2 == 3)
            {
                p.ReadByte();
                num  = p.ReadBigEndian16();
                type = 0;
            }
            else
            {
                num = p.ReadByte();

                if ((num & Main.SecureValue5) != 0)
                {
                    num &= -129;
                    num  = (num << 8) + p.ReadByte();
                }

                var flags = (FastPath_EncryptionFlags)(num2 >> 6);

                if (flags.HasFlag(FastPath_EncryptionFlags.FASTPATH_OUTPUT_ENCRYPTED))
                {
                    type = 0xfe;
                }
                else
                {
                    type = 0xff;
                }
            }

            long position = p.Position;

            p.Position = 4L;
            p          = Tcp_recv(p, num - Main.SecureValue6);
            p.Position = position;

            if ((type != 0xff) && (type != 0xfe))
            {
                p.Position = 4L;
                p.ReadByte();
                type = p.ReadByte();

                if (type == 240)
                {
                    p.ReadByte();
                    return(p);
                }

                p.ReadBigEndian16();
                p.ReadBigEndian16();
                p.ReadByte();
            }

            return(p);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Negotiation Start
        /// </summary>
        /// <param name="loadBalanceToken">null</param>
        /// <param name="bAutoReconnect">false</param>
        internal static void sendСonnectionRequest(byte[] loadBalanceToken, bool bAutoReconnect)
        {
            int num;

            Secure.dec_count        = 0;
            Secure.enc_count        = 0;
            Network.ConnectionStage = Network.eConnectionStage.Negotiating;

            if (Options.enableNLA)
            {
                // Client X.224 Connection Request PDU
                sendConnectNegotiation(
                    NegotiationProtocol.PROTOCOL_RDP |
                    NegotiationProtocol.PROTOCOL_SSL |
                    NegotiationProtocol.PROTOCOL_HYBRID,
                    loadBalanceToken);

                // Server X.224 Connection Confirm PDU
                num = receiveConnectNegotiation();

                if (num == Main.SecureValue3) // SSL подключение запрещено настройками сервера
                {
                    Network.Close();
                    Network.Connect(Options.Host, Options.Port);

                    // Client X.224 Connection Request PDU
                    sendConnectNegotiation(NegotiationProtocol.PROTOCOL_RDP, loadBalanceToken);

                    // Server X.224 Connection Confirm PDU
                    num = receiveConnectNegotiation();

                    if (num != 0)
                    {
                        throw new RDFatalException("Security negotiation failed!");
                    }
                }
                else // SSL подключение разрешено
                {
                    if (((num & 1) != 0) || ((num & 2) != 0))
                    {
                        Network.ConnectionStage = Network.eConnectionStage.Securing;
                        Network.ConnectSSL();
                    }

                    if ((num & 2) != 0)
                    {
                        Network.ConnectionStage = Network.eConnectionStage.Authenticating;
                        CredSSP.Negotiate(Network.GetSSLPublicKey());
                    }
                }
            }
            else
            {
                // Client X.224 Connection Request PDU
                sendConnectNegotiation(NegotiationProtocol.PROTOCOL_RDP, loadBalanceToken);

                // Server X.224 Connection Confirm PDU
                num = receiveConnectNegotiation();

                if (num != 0)
                {
                    throw new RDFatalException("Security negotiation failed!");
                }
            }

            Network.ConnectionStage = Network.eConnectionStage.Establishing;

            // Client MCS Connect Initial PDU
            IsoLayer.SendTPKT(sendConnectInitial(sendMcsData(true, Channels.RegisteredChannels.Count, num)));

            // Server MCS Connect Response PDU with GCC Conference Create Response
            receiveConnectResponse();

            // Client MCS Erect Domain Request PDU
            send_ErectDomainRequest();

            // Client MCS Attach User Request PDU
            send_AttachUserRequest();

            // Server MCS Attach User Confirm PDU
            McsUserID = receive_AttachUserConfirm();

            // Open User channel
            send_ChannelJoinRequest(McsUserID + MCS_USERCHANNEL_BASE); // Client MCS Channel Join Request PDU
            receive_ChannelJoinConfirm();                              // Server MCS Channel Join Confirm PDU

            // Open Global channel
            send_ChannelJoinRequest(MSC_GLOBAL_CHANNEL);
            receive_ChannelJoinConfirm();

            // Open over channels
            foreach (var channel in Channels.RegisteredChannels)
            {
                if (serverSupportedChannels.Contains(channel.ChannelID))
                {
                    send_ChannelJoinRequest(channel.ChannelID);
                    receive_ChannelJoinConfirm();
                    Debug.WriteLine("Client open over channel: " + channel.ChannelID.ToString());
                }
            }

            int num2 = 0x40;

            if (Secure.RDPEncrypted())
            {
                Network.ConnectionStage = Network.eConnectionStage.SecureAndLogin;
                RdpPacket packet = Secure.establishKey();
                packet.Position = 0L;
                IsoLayer.SendMCS(packet, MSC_GLOBAL_CHANNEL);
                num2 |= 8;
            }
            else
            {
                Network.ConnectionStage = Network.eConnectionStage.Login;
            }

            // Client Info PDU
            IsoLayer.SendToGlobalChannel(getLoginInfo(Options.Domain, Options.Username, Options.Password, "", "", bAutoReconnect), num2);
        }
Exemplo n.º 18
0
 internal static void SendToGlobalChannel(RdpPacket sec_data, int sec_flags)
 {
     SendToCannel(sec_data, sec_flags, MCS.MSC_GLOBAL_CHANNEL);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Client Info PDU
        /// </summary>
        private static RdpPacket getLoginInfo(string domain, string username, string password, string command, string directory, bool bAutoReconnect)
        {
            int num1 = 2 * "127.0.0.1".Length;
            int num2 = 2 * @"C:\WINNT\System32\mstscax.dll".Length;
            int num3 = 2 * domain.Length;
            int num4 = 2 * username.Length;
            int num5 = 2 * password.Length;
            int num6 = 2 * command.Length;
            int num7 = 2 * directory.Length;

            //int num8 = 0x213b;

            int num8 = (int)(
                ClientInfoFlags.INFO_AUTOLOGON |
                ClientInfoFlags.INFO_DISABLECTRLALTDEL |
                ClientInfoFlags.INFO_LOGONERRORS |
                ClientInfoFlags.INFO_LOGONNOTIFY |
                ClientInfoFlags.INFO_ENABLEWINDOWSKEY |
                ClientInfoFlags.INFO_MOUSE |
                ClientInfoFlags.INFO_NOAUDIOPLAYBACK |
                ClientInfoFlags.INFO_UNICODE);

            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian32(0);
            packet.WriteLittleEndian32(num8);
            packet.WriteLittleEndian16((short)num3);
            packet.WriteLittleEndian16((short)num4);

            if ((num8 & 8) != 0)
            {
                packet.WriteLittleEndian16((short)num5);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteLittleEndian16((short)num6);
            packet.WriteLittleEndian16((short)num7);

            if (0 < num3)
            {
                packet.WriteUnicodeString(domain);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteUnicodeString(username);

            if ((num8 & 8) != 0)
            {
                packet.WriteUnicodeString(password);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            if (0 < num6)
            {
                packet.WriteUnicodeString(command);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            if (0 < num7)
            {
                packet.WriteUnicodeString(directory);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteLittleEndian16((short)2);
            packet.WriteLittleEndian16((short)(num1 + 2));
            packet.WriteUnicodeString("127.0.0.1");
            packet.WriteLittleEndian16((short)(num2 + 2));
            packet.WriteUnicodeString(@"C:\WINNT\System32\mstscax.dll");
            TimeZoneInfo info = TimeZoneInfo.Local;

            packet.WriteLittleEndian32((int)info.BaseUtcOffset.TotalMinutes);
            packet.WriteUnicodeString(info.StandardName);
            packet.Position += 0x3e - (2 * info.StandardName.Length);

            if (info.SupportsDaylightSavingTime)
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((ushort)10);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)30);
                packet.WriteLittleEndian16((short)2);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }

            packet.WriteUnicodeString(info.DaylightName);
            packet.Position += 0x3e - (2 * info.DaylightName.Length);

            if (info.SupportsDaylightSavingTime)
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((ushort)3);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0x1b);
                packet.WriteLittleEndian16((short)1);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32((int)(info.BaseUtcOffset.TotalMinutes + 1.0));
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }

            packet.WriteLittleEndianU32(0);
            PerformanceFlags flags = (PerformanceFlags)0;

            if (!Options.IsHostFlagSet(HostFlags.DesktopBackground))
            {
                flags |= PerformanceFlags.PERF_DISABLE_WALLPAPER;
            }

            if (Options.IsHostFlagSet(HostFlags.FontSmoothing))
            {
                flags |= PerformanceFlags.PERF_ENABLE_FONT_SMOOTHING;
            }

            if (Options.IsHostFlagSet(HostFlags.DesktopComposition))
            {
                flags |= PerformanceFlags.PERF_ENABLE_DESKTOP_COMPOSITION;
            }

            if (!Options.IsHostFlagSet(HostFlags.ShowWindowContents))
            {
                flags |= PerformanceFlags.PERF_DISABLE_FULLWINDOWDRAG;
            }

            if (!Options.IsHostFlagSet(HostFlags.MenuAnimation))
            {
                flags |= PerformanceFlags.PERF_DISABLE_MENUANIMATIONS;
            }

            if (!Options.IsHostFlagSet(HostFlags.VisualStyles))
            {
                flags |= PerformanceFlags.PERF_DISABLE_THEMING;
            }

            packet.WriteLittleEndian32((int)flags);

            if (bAutoReconnect)
            {
                packet.WriteLittleEndian32(0x1c);
                packet.WriteLittleEndian32(0x1c);
                packet.WriteLittleEndian32(1);
                packet.WriteLittleEndian32(Options.LogonID);
                HMACT64 hmact = new HMACT64(Options.ReconnectCookie);
                hmact.update(Secure.GetClentRandom());
                byte[] buffer = hmact.digest();
                packet.Write(buffer, 0, buffer.Length);
                return(packet);
            }

            packet.WriteLittleEndian32(0);

            return(packet);
        }
Exemplo n.º 20
0
        // Input
        internal static void FastSendInput(List <Rdp.InputInfo> InputToSend)
        {
            if (Options.use_fastpath_input)
            {
                RdpPacket packet = new RdpPacket();
                ushort    num    = 1;
                int       count  = InputToSend.Count;

                if (count < 0x10)
                {
                    packet.WriteByte((byte)(count << 2));
                }
                else
                {
                    packet.WriteByte(0);
                    num = (ushort)(num + 1);
                }

                foreach (Rdp.InputInfo info in InputToSend)
                {
                    switch (info.Message_Type)
                    {
                    case Rdp.InputType.INPUT_EVENT_SCANCODE:
                        num = (ushort)(num + 2);
                        break;

                    case Rdp.InputType.INPUT_EVENT_UNICODE:
                        num = (ushort)(num + 3);
                        break;

                    case Rdp.InputType.INPUT_EVENT_MOUSE:
                        num = (ushort)(num + 7);
                        break;

                    case Rdp.InputType.INPUT_EVENT_SYNC:
                        num = (ushort)(num + 1);
                        break;
                    }
                }

                num = (ushort)(num + 1);

                if (num > 0x7f)
                {
                    num = (ushort)(num + 1);
                }

                packet.WriteEncodedUnsigned16(num);

                if (count >= 0x10)
                {
                    packet.WriteByte((byte)count);
                }

                foreach (Rdp.InputInfo info2 in InputToSend)
                {
                    int num3 = 0;

                    switch (info2.Message_Type)
                    {
                    case Rdp.InputType.INPUT_EVENT_SCANCODE:

                        if ((info2.Device_Flags & 0x8000) != 0)
                        {
                            num3 |= 0x01;
                        }

                        if ((info2.Device_Flags & 0x0100) != 0)
                        {
                            num3 |= 0x02;
                        }

                        packet.WriteByte((byte)num3);
                        packet.WriteByte((byte)info2.Param1);
                        break;

                    case Rdp.InputType.INPUT_EVENT_UNICODE:

                        if ((info2.Device_Flags & 0x8000) != 0)
                        {
                            num3 |= 1;
                        }

                        packet.WriteByte((byte)(0x80 | num3));
                        packet.WriteLittleEndian16((ushort)info2.Param1);
                        break;

                    case Rdp.InputType.INPUT_EVENT_MOUSE:
                        packet.WriteByte(0x20);
                        packet.WriteLittleEndian16((ushort)info2.Device_Flags);
                        packet.WriteLittleEndian16((ushort)info2.Param1);
                        packet.WriteLittleEndian16((ushort)info2.Param2);
                        break;

                    case Rdp.InputType.INPUT_EVENT_SYNC:
                        packet.WriteByte(0x60);
                        break;
                    }
                }

                Write(packet);
            }
            else
            {
                foreach (Rdp.InputInfo info3 in InputToSend)
                {
                    SlowSendInput(info3.Time, (int)info3.Message_Type, info3.Device_Flags, info3.Param1, info3.Param2);
                }
            }
        }
Exemplo n.º 21
0
        public static void ProcessFastPathUpdate(RdpPacket packet)
        {
            while (packet.Length - packet.Position > 3L)
            {
                int num = packet.ReadByte();
                FastPathUpdate.UpdateCode    updateCode    = (FastPathUpdate.UpdateCode)(num & 15);
                FastPathUpdate.Fragmentation fragmentation = (FastPathUpdate.Fragmentation)(num >> 4 & 3);
                bool flag = (num & 128) != 0;

                if (flag)
                {
                    packet.ReadByte();
                }

                if (fragmentation != FastPathUpdate.Fragmentation.FASTPATH_FRAGMENT_SINGLE)
                {
                    throw new RDFatalException("Invalid fragmentation!");
                }

                int littleEndian = packet.ReadLittleEndian16();

                switch (updateCode)
                {
                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_ORDERS:
                {
                    int littleEndian2 = packet.ReadLittleEndian16();
                    Orders.processOrders(packet, (int)packet.Position + littleEndian - 2, littleEndian2);
                    break;
                }

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_BITMAP:
                {
                    int littleEndian3 = packet.ReadLittleEndian16();
                    if (littleEndian3 != 1)
                    {
                        throw new RDFatalException("Invalid fastpath bitmap update!");
                    }
                    Bitmaps.processBitmapUpdates(packet);
                    break;
                }

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_PALETTE:
                {
                    int littleEndian3 = packet.ReadLittleEndian16();

                    if (littleEndian3 != 2)
                    {
                        throw new RDFatalException("Invalid fastpath palette update!");
                    }

                    Palette.processPalette(packet);
                    break;
                }

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_SYNCHRONIZE:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_SURFCMDS:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_PTR_NULL:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_PTR_DEFAULT:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_PTR_POSITION:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_COLOR:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_CACHED:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;

                case FastPathUpdate.UpdateCode.FASTPATH_UPDATETYPE_POINTER:
                    packet.Position = packet.Position + (long)littleEndian;
                    break;
                }
            }
        }
Exemplo n.º 22
0
        public static byte[] decompress(int width, int height, int size, RdpPacket data, int Bpp)
        {
            byte[] buffer = new byte[size];
            data.Read(buffer, 0, size);
            int  startOffset   = 0;
            int  startlocation = 0;
            int  num3          = 0;
            int  num4          = 0;
            int  num5          = size;
            int  num6          = 0;
            int  num7          = 0;
            int  num8          = 0;
            int  offset        = width;
            int  num10         = -1;
            int  num11         = 0;
            int  num12         = 0;
            int  num13         = 0;
            int  num14         = 0;
            byte num15         = 0;
            int  num16         = 0;
            uint maxValue      = uint.MaxValue;
            bool flag          = false;
            bool flag2         = false;
            bool flag3         = false;

            byte[] input = new byte[width * height];
            while (num3 < num5)
            {
                num11 = 0;
                num12 = buffer[num3++] & 0xff;
                num6  = num12 >> 4;
                switch (num6)
                {
                case 12:
                case 13:
                case 14:
                    num6 -= 6;
                    num7  = num12 & 15;
                    num8  = 0x10;
                    goto Label_00F8;

                case 15:
                    num6 = num12 & 15;
                    if (num6 >= 9)
                    {
                        break;
                    }
                    num7  = buffer[num3++] & 0xff;
                    num7 |= (buffer[num3++] & 0xff) << 8;
                    goto Label_00F5;

                default:
                    num6 = num6 >> 1;
                    num7 = num12 & 0x1f;
                    num8 = 0x20;
                    goto Label_00F8;
                }
                num7 = (num6 < 11) ? 8 : 1;
Label_00F5:
                num8 = 0;
Label_00F8:
                if (num8 != 0)
                {
                    flag3 = (num6 == 2) || (num6 == 7);
                    if (num7 == 0)
                    {
                        if (flag3)
                        {
                            num7 = (buffer[num3++] & 0xff) + 1;
                        }
                        else
                        {
                            num7 = (buffer[num3++] & 0xff) + num8;
                        }
                    }
                    else if (flag3)
                    {
                        num7 = num7 << 3;
                    }
                }
                switch (num6)
                {
                case 0:
                    if ((num10 == num6) && ((offset != width) || (startOffset != 0)))
                    {
                        flag = true;
                    }
                    break;

                case 3:
                    num14 = buffer[num3++] & 0xff;
                    break;

                case 6:
                case 7:
                    maxValue = buffer[num3++];
                    num6    -= 5;
                    break;

                case 8:
                    num13 = buffer[num3++] & 0xff;
                    num14 = buffer[num3++] & 0xff;
                    break;

                case 9:
                    num16 = 3;
                    num6  = 2;
                    num11 = 3;
                    break;

                case 10:
                    num16 = 5;
                    num6  = 2;
                    num11 = 5;
                    break;
                }
                num10 = num6;
                num15 = 0;
                while (num7 > 0)
                {
                    int num18;
                    int num19;
                    int num20;
                    int num21;
                    int num22;
                    int num23;
                    int num24;
                    int num25;
                    int num26;
                    int num27;
                    int num28;
                    if (offset >= width)
                    {
                        if (height <= 0)
                        {
                            throw new RDFatalException("Decompressing bitmap failed! Height = " + height.ToString());
                        }
                        offset = 0;
                        height--;
                        startOffset   = startlocation;
                        startlocation = num4 + (height * width);
                    }
                    switch (num6)
                    {
                    case 0:
                        if (!flag)
                        {
                            goto Label_02CE;
                        }
                        if (startOffset != 0)
                        {
                            break;
                        }
                        input[startlocation + offset] = (byte)maxValue;
                        goto Label_02BF;

                    case 1:
                        if (startOffset == 0)
                        {
                            goto Label_03BC;
                        }
                        goto Label_0429;

                    case 2:
                        if (startOffset == 0)
                        {
                            goto Label_04C7;
                        }
                        goto Label_0596;

                    case 3:
                        goto Label_0634;

                    case 4:
                        goto Label_0696;

                    case 8:
                        goto Label_0714;

                    case 13:
                        goto Label_0790;

                    case 14:
                        goto Label_07E8;

                    default:
                        throw new RDFatalException("Incorrect decompress opcode " + num6.ToString());
                    }
                    input[startlocation + offset] = (byte)(input[startOffset + offset] ^ ((byte)maxValue));
Label_02BF:
                    flag = false;
                    num7--;
                    offset++;
Label_02CE:
                    if (startOffset == 0)
                    {
                        goto Label_02FA;
                    }
                    goto Label_035A;
Label_02D6:
                    num28 = 0;
                    while (num28 < 8)
                    {
                        input[startlocation + offset] = 0;
                        num7--;
                        offset++;
                        num28++;
                    }
Label_02FA:
                    if (((num7 & -8) != 0) && ((offset + 8) < width))
                    {
                        goto Label_02D6;
                    }
                    while ((num7 > 0) && (offset < width))
                    {
                        input[startlocation + offset] = 0;
                        num7--;
                        offset++;
                    }
                    continue;
Label_0330:
                    num18 = 0;
                    while (num18 < 8)
                    {
                        input[startlocation + offset] = input[startOffset + offset];
                        num7--;
                        offset++;
                        num18++;
                    }
Label_035A:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_0384;
                    }
                    goto Label_0330;
Label_036A:
                    input[startlocation + offset] = input[startOffset + offset];
                    num7--;
                    offset++;
Label_0384:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_036A;
                    }
                    continue;
Label_0396:
                    num19 = 0;
                    while (num19 < 8)
                    {
                        input[startlocation + offset] = (byte)maxValue;
                        num7--;
                        offset++;
                        num19++;
                    }
Label_03BC:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_03E2;
                    }
                    goto Label_0396;
Label_03CC:
                    input[startlocation + offset] = (byte)maxValue;
                    num7--;
                    offset++;
Label_03E2:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_03CC;
                    }
                    continue;
Label_03F4:
                    num20 = 0;
                    while (num20 < 8)
                    {
                        setli(input, startlocation, offset, getli(input, startOffset, offset, 1) ^ maxValue, 1);
                        num7--;
                        offset++;
                        num20++;
                    }
Label_0429:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_045E;
                    }
                    goto Label_03F4;
Label_0439:
                    setli(input, startlocation, offset, getli(input, startOffset, offset, 1) ^ maxValue, 1);
                    num7--;
                    offset++;
Label_045E:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_0439;
                    }
                    continue;
Label_0470:
                    num21 = 0;
                    while (num21 < 8)
                    {
                        num15 = (byte)(num15 << 1);
                        if (num15 == 0)
                        {
                            num16 = (num11 != 0) ? ((byte)num11) : buffer[num3++];
                            num15 = 1;
                        }
                        if ((num16 & num15) != 0)
                        {
                            input[startlocation + offset] = (byte)maxValue;
                        }
                        else
                        {
                            input[startlocation + offset] = 0;
                        }
                        num7--;
                        offset++;
                        num21++;
                    }
Label_04C7:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_051E;
                    }
                    goto Label_0470;
Label_04D7:
                    num15 = (byte)(num15 << 1);
                    if (num15 == 0)
                    {
                        num16 = (num11 != 0) ? ((byte)num11) : buffer[num3++];
                        num15 = 1;
                    }
                    if ((num16 & num15) != 0)
                    {
                        input[startlocation + offset] = (byte)maxValue;
                    }
                    else
                    {
                        input[startlocation + offset] = 0;
                    }
                    num7--;
                    offset++;
Label_051E:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_04D7;
                    }
                    continue;
Label_0530:
                    num22 = 0;
                    while (num22 < 8)
                    {
                        num15 = (byte)(num15 << 1);
                        if (num15 == 0)
                        {
                            num16 = (num11 != 0) ? ((byte)num11) : buffer[num3++];
                            num15 = 1;
                        }
                        if ((num16 & num15) != 0)
                        {
                            input[startlocation + offset] = (byte)(input[startOffset + offset] ^ ((byte)maxValue));
                        }
                        else
                        {
                            input[startlocation + offset] = input[startOffset + offset];
                        }
                        num7--;
                        offset++;
                        num22++;
                    }
Label_0596:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_05FC;
                    }
                    goto Label_0530;
Label_05A6:
                    num15 = (byte)(num15 << 1);
                    if (num15 == 0)
                    {
                        num16 = (num11 != 0) ? ((byte)num11) : buffer[num3++];
                        num15 = 1;
                    }
                    if ((num16 & num15) != 0)
                    {
                        input[startlocation + offset] = (byte)(input[startOffset + offset] ^ ((byte)maxValue));
                    }
                    else
                    {
                        input[startlocation + offset] = input[startOffset + offset];
                    }
                    num7--;
                    offset++;
Label_05FC:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_05A6;
                    }
                    continue;
Label_060E:
                    num23 = 0;
                    while (num23 < 8)
                    {
                        input[startlocation + offset] = (byte)num14;
                        num7--;
                        offset++;
                        num23++;
                    }
Label_0634:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_065A;
                    }
                    goto Label_060E;
Label_0644:
                    input[startlocation + offset] = (byte)num14;
                    num7--;
                    offset++;
Label_065A:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_0644;
                    }
                    continue;
Label_066C:
                    num24 = 0;
                    while (num24 < 8)
                    {
                        input[startlocation + offset] = buffer[num3++];
                        num7--;
                        offset++;
                        num24++;
                    }
Label_0696:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_06C0;
                    }
                    goto Label_066C;
Label_06A6:
                    input[startlocation + offset] = buffer[num3++];
                    num7--;
                    offset++;
Label_06C0:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_06A6;
                    }
                    continue;
Label_06D2:
                    num25 = 0;
                    while (num25 < 8)
                    {
                        if (flag2)
                        {
                            input[startlocation + offset] = (byte)num14;
                            flag2 = false;
                        }
                        else
                        {
                            input[startlocation + offset] = (byte)num13;
                            flag2 = true;
                            num7++;
                        }
                        num7--;
                        offset++;
                        num25++;
                    }
Label_0714:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_0756;
                    }
                    goto Label_06D2;
Label_0724:
                    if (flag2)
                    {
                        input[startlocation + offset] = (byte)num14;
                        flag2 = false;
                    }
                    else
                    {
                        input[startlocation + offset] = (byte)num13;
                        flag2 = true;
                        num7++;
                    }
                    num7--;
                    offset++;
Label_0756:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_0724;
                    }
                    continue;
Label_0768:
                    num26 = 0;
                    while (num26 < 8)
                    {
                        input[startlocation + offset] = 0xff;
                        num7--;
                        offset++;
                        num26++;
                    }
Label_0790:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_07B8;
                    }
                    goto Label_0768;
Label_07A0:
                    input[startlocation + offset] = 0xff;
                    num7--;
                    offset++;
Label_07B8:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_07A0;
                    }
                    continue;
Label_07C4:
                    num27 = 0;
                    while (num27 < 8)
                    {
                        input[startlocation + offset] = 0;
                        num7--;
                        offset++;
                        num27++;
                    }
Label_07E8:
                    if (((num7 & -8) == 0) || ((offset + 8) >= width))
                    {
                        goto Label_080C;
                    }
                    goto Label_07C4;
Label_07F8:
                    input[startlocation + offset] = 0;
                    num7--;
                    offset++;
Label_080C:
                    if ((num7 > 0) && (offset < width))
                    {
                        goto Label_07F8;
                    }
                }
            }
            _g++;
            return(input);
        }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
        public static uint[] decompressInt(int width, int height, int size, RdpPacket data, int Bpp)
        {
            byte[] buffer = new byte[size];
            data.Read(buffer, 0, size);
            int  num      = -1;
            int  num2     = 0;
            int  offset   = 0;
            int  num4     = 0;
            int  num5     = size;
            int  num6     = 0;
            uint num7     = 0;
            int  num8     = 0;
            int  num9     = width;
            int  num10    = -1;
            int  num11    = 0;
            int  num12    = 0;
            uint num13    = 0;
            uint num14    = 0;
            byte num15    = 0;
            int  num16    = 0;
            uint maxValue = uint.MaxValue;
            bool flag     = false;
            bool flag2    = false;
            bool flag3    = false;

            uint[] numArray = new uint[width * height];
            try
            {
                while (offset < num5)
                {
                    num11 = 0;
                    num12 = buffer[offset++] & 0xff;
                    num6  = num12 >> 4;
                    switch (num6)
                    {
                    case 12:
                    case 13:
                    case 14:
                        num6 -= 6;
                        num7  = (uint)(num12 & 15);
                        num8  = 0x10;
                        goto Label_00F8;

                    case 15:
                        num6 = num12 & 15;
                        if (num6 >= 9)
                        {
                            break;
                        }
                        num7  = (uint)(buffer[offset++] & 0xff);
                        num7 |= (uint)((buffer[offset++] & 0xff) << 8);
                        goto Label_00E2;

                    default:
                        num6 = num6 >> 1;
                        num7 = (uint)(num12 & 0x1f);
                        num8 = 0x20;
                        goto Label_00F8;
                    }
                    num7 = (uint)(num6 < 11 ? 8 : 1);
Label_00E2:
                    num8 = 0;
Label_00F8:
                    if (num8 != 0)
                    {
                        flag3 = (num6 == 2) || (num6 == 7);
                        if (num7 == 0)
                        {
                            if (flag3)
                            {
                                num7 = (uint)((buffer[offset++] & 0xff) + 1);
                            }
                            else
                            {
                                num7 = (uint)((buffer[offset++] & 0xff) + num8);
                            }
                        }
                        else if (flag3)
                        {
                            num7 = num7 << 3;
                        }
                    }
                    switch (num6)
                    {
                    case 0:
                        if ((num10 == num6) && ((num9 != width) || (num != -1)))
                        {
                            flag = true;
                        }
                        goto Label_01DF;

                    case 3:
                        break;

                    case 6:
                    case 7:
                        maxValue = cvalx(buffer, offset, Bpp);
                        offset  += Bpp;
                        num6    -= 5;
                        goto Label_01DF;

                    case 8:
                        num13   = cvalx(buffer, offset, Bpp);
                        offset += Bpp;
                        break;

                    case 9:
                        num16 = 3;
                        num6  = 2;
                        num11 = 3;
                        goto Label_01DF;

                    case 10:
                        num16 = 5;
                        num6  = 2;
                        num11 = 5;
                        goto Label_01DF;

                    default:
                        goto Label_01DF;
                    }
                    num14   = cvalx(buffer, offset, Bpp);
                    offset += Bpp;
Label_01DF:
                    num10 = num6;
                    num15 = 0;
                    while (num7 > 0)
                    {
                        int num19;
                        int num20;
                        int num21;
                        int num22;
                        int num23;
                        int num24;
                        int num25;
                        int num26;
                        int num27;
                        int num28;
                        if (num9 >= width)
                        {
                            if (height <= 0)
                            {
                                throw new RDFatalException("Illegal int bitmap height: " + height.ToString());
                            }
                            num9 = 0;
                            height--;
                            num  = num2;
                            num2 = num4 + (height * width);
                        }
                        switch (num6)
                        {
                        case 0:
                            if (!flag)
                            {
                                goto Label_029B;
                            }
                            if (num != -1)
                            {
                                break;
                            }
                            numArray[num2 + num9] = maxValue;
                            goto Label_028C;

                        case 1:
                            if (num != -1)
                            {
                                goto Label_0402;
                            }
                            goto Label_039A;

                        case 2:
                            if (num != -1)
                            {
                                goto Label_0571;
                            }
                            goto Label_04A3;

                        case 3:
                            goto Label_060F;

                        case 4:
                            goto Label_067B;

                        case 8:
                            goto Label_0702;

                        case 13:
                            goto Label_0780;

                        case 14:
                            goto Label_07DC;

                        default:
                            throw new RDFatalException("Illegal int bitmap opcode in " + num6.ToString());
                        }
                        numArray[num2 + num9] = numArray[num + num9] ^ maxValue;
Label_028C:
                        flag = false;
                        num7--;
                        num9++;
Label_029B:
                        if (num != -1)
                        {
                            goto Label_032C;
                        }
                        while (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            for (int i = 0; i < 8; i++)
                            {
                                numArray[num2 + num9] = 0;
                                num7--;
                                num9++;
                            }
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = 0;
                            num7--;
                            num9++;
                        }
                        continue;
Label_0302:
                        num19 = 0;
                        while (num19 < 8)
                        {
                            numArray[num2 + num9] = numArray[num + num9];
                            num7--;
                            num9++;
                            num19++;
                        }
Label_032C:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_0302;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = numArray[num + num9];
                            num7--;
                            num9++;
                        }
                        continue;
Label_0375:
                        num20 = 0;
                        while (num20 < 8)
                        {
                            numArray[num2 + num9] = maxValue;
                            num7--;
                            num9++;
                            num20++;
                        }
Label_039A:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_0375;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = maxValue;
                            num7--;
                            num9++;
                        }
                        continue;
Label_03D5:
                        num21 = 0;
                        while (num21 < 8)
                        {
                            numArray[num2 + num9] = numArray[num + num9] ^ maxValue;
                            num7--;
                            num9++;
                            num21++;
                        }
Label_0402:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_03D5;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = numArray[num + num9] ^ maxValue;
                            num7--;
                            num9++;
                        }
                        continue;
Label_044E:
                        num22 = 0;
                        while (num22 < 8)
                        {
                            num15 = (byte)(num15 << 1);
                            if (num15 == 0)
                            {
                                num16 = (num11 != 0) ? num11 : buffer[offset++];
                                num15 = 1;
                            }
                            if ((num16 & num15) != 0)
                            {
                                numArray[num2 + num9] = maxValue;
                            }
                            else
                            {
                                numArray[num2 + num9] = 0;
                            }
                            num7--;
                            num9++;
                            num22++;
                        }
Label_04A3:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_044E;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            num15 = (byte)(num15 << 1);
                            if (num15 == 0)
                            {
                                num16 = (num11 != 0) ? num11 : buffer[offset++];
                                num15 = 1;
                            }
                            if ((num16 & num15) != 0)
                            {
                                numArray[num2 + num9] = maxValue;
                            }
                            else
                            {
                                numArray[num2 + num9] = 0;
                            }
                            num7--;
                            num9++;
                        }
                        continue;
Label_050E:
                        num23 = 0;
                        while (num23 < 8)
                        {
                            num15 = (byte)(num15 << 1);
                            if (num15 == 0)
                            {
                                num16 = (num11 != 0) ? num11 : buffer[offset++];
                                num15 = 1;
                            }
                            if ((num16 & num15) != 0)
                            {
                                numArray[num2 + num9] = numArray[num + num9] ^ maxValue;
                            }
                            else
                            {
                                numArray[num2 + num9] = numArray[num + num9];
                            }
                            num7--;
                            num9++;
                            num23++;
                        }
Label_0571:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_050E;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            num15 = (byte)(num15 << 1);
                            if (num15 == 0)
                            {
                                num16 = (num11 != 0) ? num11 : buffer[offset++];
                                num15 = 1;
                            }
                            if ((num16 & num15) != 0)
                            {
                                numArray[num2 + num9] = numArray[num + num9] ^ maxValue;
                            }
                            else
                            {
                                numArray[num2 + num9] = numArray[num + num9];
                            }
                            num7--;
                            num9++;
                        }
                        continue;
Label_05EA:
                        num24 = 0;
                        while (num24 < 8)
                        {
                            numArray[num2 + num9] = num14;
                            num7--;
                            num9++;
                            num24++;
                        }
Label_060F:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_05EA;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = num14;
                            num7--;
                            num9++;
                        }
                        continue;
Label_064A:
                        num25 = 0;
                        while (num25 < 8)
                        {
                            numArray[num2 + num9] = cvalx(buffer, offset, Bpp);
                            offset += Bpp;
                            num7--;
                            num9++;
                            num25++;
                        }
Label_067B:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_064A;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = cvalx(buffer, offset, Bpp);
                            offset += Bpp;
                            num7--;
                            num9++;
                        }
                        continue;
Label_06C2:
                        num26 = 0;
                        while (num26 < 8)
                        {
                            if (flag2)
                            {
                                numArray[num2 + num9] = num14;
                                flag2 = false;
                            }
                            else
                            {
                                numArray[num2 + num9] = num13;
                                flag2 = true;
                                num7++;
                            }
                            num7--;
                            num9++;
                            num26++;
                        }
Label_0702:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_06C2;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            if (flag2)
                            {
                                numArray[num2 + num9] = num14;
                                flag2 = false;
                            }
                            else
                            {
                                numArray[num2 + num9] = num13;
                                flag2 = true;
                                num7++;
                            }
                            num7--;
                            num9++;
                        }
                        continue;
Label_0758:
                        num27 = 0;
                        while (num27 < 8)
                        {
                            numArray[num2 + num9] = 0xffffff;
                            num7--;
                            num9++;
                            num27++;
                        }
Label_0780:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_0758;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = 0xffffff;
                            num7--;
                            num9++;
                        }
                        continue;
Label_07B8:
                        num28 = 0;
                        while (num28 < 8)
                        {
                            numArray[num2 + num9] = 0;
                            num7--;
                            num9++;
                            num28++;
                        }
Label_07DC:
                        if (((num7 & 18446744073709551608L) != 0L) && ((num9 + 8) < width))
                        {
                            goto Label_07B8;
                        }
                        while ((num7 > 0) && (num9 < width))
                        {
                            numArray[num2 + num9] = 0;
                            num7--;
                            num9++;
                        }
                    }
                }
            }
            catch
            {
            }
            return(numArray);
        }
Exemplo n.º 25
0
        private static void process_bmpcache2(RdpPacket data, int flags, bool compressed)
        {
            RdpBitmap bitmap;
            int       num3;
            int       num4;

            byte[] buffer;
            ulong  key  = 0L;
            int    num2 = flags & 7;
            int    bpp  = ((flags & 0x38) >> 3) - 2;

            if ((flags & 0x800) != 0)
            {
                throw new RDFatalException("DO_NOT_CACHE flag not supported!");
            }

            if ((flags & 0x100) != 0)
            {
                byte[] buffer2 = new byte[8];
                data.Read(buffer2, 0, buffer2.Length);
                key = BitConverter.ToUInt64(buffer2, 0);
            }

            if ((flags & 0x80) != 0)
            {
                num3 = data.ReadEncodedUnsigned16();
                num4 = num3;
            }
            else
            {
                num3 = data.ReadEncodedUnsigned16();
                num4 = data.ReadEncodedUnsigned16();
            }

            int size = data.ReadEncoded32();
            int num6 = data.ReadEncodedUnsigned16();

            if (compressed)
            {
                if ((flags & 0x400) == 0)
                {
                    data.Position += 8L;
                    size          -= 8;
                }

                if (bpp == 1)
                {
                    buffer = RdpBitmap.decompress(num3, num4, size, data, bpp);

                    if (buffer == null)
                    {
                        return;
                    }

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

                    if (numArray == null)
                    {
                        return;
                    }

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

                for (int i = 0; i < num4; i++)
                {
                    data.Read(buffer, ((num4 - i) - 1) * (num3 * bpp), num3 * bpp);
                }
                if (bpp == 1)
                {
                    bitmap = new RdpBitmap(buffer, num3, num4, bpp, 0, 0);
                }
                else
                {
                    bitmap = new RdpBitmap(RdpBitmap.convertImage(buffer, bpp), num3, num4, bpp, 0, 0);
                }
            }

            if (bitmap != null)
            {
                Cache.putBitmap(num2, num6, bitmap, 0);

                if ((flags & 0x100) != 0)
                {
                    bitmap.PersistCache(key);
                    Cache.m_BitmapCaches++;
                }
            }
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
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);
                    }
                }
            }
        }
Exemplo n.º 28
0
        internal static void processServerCapabilities(RdpPacket data, int numCaps)
        {
            m_bServerSupportsCacheV2 = false;

            while (numCaps-- > 0)
            {
                int num  = data.ReadLittleEndian16();
                int num2 = data.ReadLittleEndian16();

                switch ((Capstype)num)
                {
                // RDP_CAPSET_GENERAL
                case Capstype.CAPSTYPE_GENERAL:
                {
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadByte();
                    num2--;
                    int num3 = data.ReadByte();
                    num2--;
                    Options.suppress_output_supported = num3 > 0;
                    break;
                }

                // RDP_CAPSET_BITMAP
                case Capstype.CAPSTYPE_BITMAP:
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    data.ReadLittleEndian16();
                    num2 -= 2;
                    break;

                // RDP_CAPSET_ORDER
                case Capstype.CAPSTYPE_ORDER:
                    break;

                // RDP_CAPSET_BMPCACHE
                case Capstype.CAPSTYPE_BITMAPCACHE:
                    break;

                // RDP_CAPSET_CONTROL
                case Capstype.CAPSTYPE_CONTROL:
                    break;

                // RDP_CAPSET_POINTER
                case Capstype.CAPSTYPE_POINTER:
                    break;

                // RDP_CAPSET_SHARE
                case Capstype.CAPSTYPE_SHARE:
                    break;

                // RDP_CAPSET_COLCACHE
                case Capstype.CAPSTYPE_COLCACHE:
                    break;

                // RDP_CAPSET_INPUT
                case Capstype.CAPSTYPE_INPUT:
                {
                    int num4 = data.ReadLittleEndian16();     // inputFlags
                    num2 -= 2;

                    //Options.use_fastpath_input = false; // Полностью отключаем FastPath Input
                    //if ((num4 & 0x20) != 0)
                    //{
                    //    Options.use_fastpath_input = true;
                    //}
                    //if ((num4 & 8) != 0)
                    //{
                    //    Options.use_fastpath_input = true;
                    //}
                    break;
                }

                // RDP_CAPSET_FONT
                case Capstype.CAPSTYPE_FONT:
                    break;

                // RDP_CAPSET_BMPCACHE_HOSTSUPPORT
                case Capstype.CAPSTYPE_BITMAPCACHE_HOSTSUPPORT:
                    m_bServerSupportsCacheV2 = true;
                    break;

                // RDP_CAPSET_VIRTUALCHANNEL
                case Capstype.CAPSTYPE_VIRTUALCHANNEL:
                    break;

                // RDP_CAPSET_COMPDESK
                case Capstype.CAPSETTYPE_COMPDESK:
                    break;

                // RDP_CAPSET_MULTIFRAGMENTUPDATE
                case Capstype.CAPSETTYPE_MULTIFRAGMENTUPDATE:
                    break;

                // RDP_CAPSET_LARGE_POINTER
                case Capstype.CAPSETTYPE_LARGE_POINTER:
                    break;

                // RDP_CAPSET_SURFACE_COMMANDS
                case Capstype.CAPSETTYPE_SURFACE_COMMANDS:
                    break;

                // RDP_CAPSET_BITMAP_CODECS
                case Capstype.CAPSETTYPE_BITMAP_CODECS:
                    break;

                // RDP_CAPSET unknown
                default:
                    break;
                }

                data.Position += num2 - 4;
            }

            if (!m_bServerSupportsCacheV2)
            {
                Options.persistentBmpCache = false;
            }
        }
Exemplo n.º 29
0
        public static void processOrders(RdpPacket data, int next_packet, int n_orders)
        {
            int  present  = 0;
            int  flags    = 0;
            int  size     = 0;
            long position = data.Position;

            for (int i = 0; i < n_orders; i++)
            {
                flags = data.ReadByte();

                if ((flags & 1) == 0)
                {
                    throw new RDFatalException("Bad order flags: " + flags.ToString() + "!");
                }

                if ((flags & 2) != 0)
                {
                    // processSecondaryOrders
                    processSecondaryOrders(data);
                    continue;
                }

                if ((flags & 8) != 0)
                {
                    m_OrderType = data.ReadByte();
                }

                switch (m_OrderType)
                {
                case 0x18:
                case 9:
                case 13:
                case 0x10:
                case 0x11:
                case 0x12:
                case 0x13:
                case 1:
                    size = 2;
                    break;

                case 0x1b:
                case 14:
                    size = 3;
                    break;

                default:
                    size = 1;
                    break;
                }
                present = inPresent(data, flags, size);

                if ((flags & 4) != 0)
                {
                    if ((flags & 0x20) == 0)
                    {
                        // parseBounds
                        parseBounds(data);
                    }

                    Options.BoundsLeft   = SurfaceClip.Left;
                    Options.BoundsRight  = SurfaceClip.Right;
                    Options.BoundsTop    = SurfaceClip.Top;
                    Options.BoundsBottom = SurfaceClip.Bottom;
                }

                bool delta = (flags & 0x10) != 0;

                switch (m_OrderType)
                {
                case 0:
                    // processDestBlt
                    processDestBlt(data, present, delta);
                    break;

                case 1:
                    // processPatBlt
                    processPatBlt(data, present, delta);
                    break;

                case 2:
                    // processScreenBlt
                    processScreenBlt(data, present, delta);
                    break;

                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 12:
                    return;

                case 9:
                    // processLine
                    processLine(data, present, delta);
                    break;

                case 10:
                    // processRect
                    processRectangle(data, present, delta);
                    break;

                case 11:
                    // processDeskSave
                    processDeskSave(data, present, delta);
                    break;

                case 13:
                    // processMemBlt
                    processMemBlt(data, present, delta);
                    break;

                case 14:
                    // processTriBlt
                    processTriBlt(data, present, delta);
                    break;

                case 15:
                    // processMultiDestBlt
                    processMultiDestBlt(data, present, delta);
                    break;

                case 0x10:
                    // processMultiPatBlt
                    processMultiPatBlt(data, present, delta);
                    break;

                case 0x11:
                    // processMultiScreenBlt
                    processMultiScreenBlt(data, present, delta);
                    break;

                case 0x12:
                    processMultiRectangle(data, present, delta);
                    break;

                case 0x16:
                    // processPolyLine
                    processPolyLine(data, present, delta);
                    break;

                case 0x1b:
                    // processGlyphIndex
                    processGlyphIndex(data, present, delta);
                    break;

                default:
                    // processOrders unknown type
                    return;
                }

                if ((flags & 4) != 0)
                {
                    Options.BoundsLeft   = 0;
                    Options.BoundsRight  = Options.width - 1;
                    Options.BoundsTop    = 0;
                    Options.BoundsBottom = Options.height - 1;
                }
            }

            if (data.Position != next_packet)
            {
                throw new RDFatalException("Bad order packet!");
            }
        }
Exemplo n.º 30
0
 protected static void WriteTag(RdpPacket packet, int Tag, string Identifier)
 {
     WriteByte(packet, Tag);
     WriteLength(packet, Identifier);
 }