/// <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); }