protected static int ReadInteger(RdpPacket packet) { if (packet.ReadByte() != 2) { throw new Exception("Data Error!"); } int num2 = packet.ReadByte(); byte[] buffer = new byte[4]; switch (num2) { case 4: packet.Read(buffer, 0, 4); return(BitConverter.ToInt32(buffer, 0)); case 3: packet.Read(buffer, 0, 3); return(BitConverter.ToInt32(buffer, 0)); case 2: packet.Read(buffer, 0, 2); return(BitConverter.ToInt32(buffer, 0)); } packet.Read(buffer, 0, 1); return(BitConverter.ToInt32(buffer, 0)); }
/// <summary> /// Server X.224 Connection Confirm PDU /// </summary> private static int receiveConnectNegotiation() { RdpPacket packet = ISO.Receive(); packet.Position += 7L; if (packet.Position >= packet.Length) { return(0); } switch (packet.ReadByte()) { // TYPE_RDP_NEG_RSP case 0x02: Options.serverNegotiateFlags = (NegotiationFlags)packet.ReadByte(); packet.ReadLittleEndian16(); return(packet.ReadLittleEndian32()); // TYPE_RDP_NEG_FAILURE case 0x03: packet.ReadByte(); packet.ReadLittleEndian16(); switch ((NegotiationFailureCodes)packet.ReadLittleEndian32()) { case NegotiationFailureCodes.SSL_REQUIRED_BY_SERVER: throw new RDFatalException("The server requires that the client support Enhanced RDP Security with TLS 1.0"); case NegotiationFailureCodes.SSL_NOT_ALLOWED_BY_SERVER: return(0x10000000); case NegotiationFailureCodes.SSL_CERT_NOT_ON_SERVER: throw new RDFatalException("The server does not possess a valid authentication certificate and cannot initialize the External Security Protocol Provider"); case NegotiationFailureCodes.INCONSISTENT_FLAGS: throw new RDFatalException("The list of requested security protocols is not consistent with the current security protocol in effect."); case NegotiationFailureCodes.HYBRID_REQUIRED_BY_SERVER: throw new RDFatalException("The server requires that the client support Enhanced RDP Security with CredSSP"); case NegotiationFailureCodes.SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER: throw new RDFatalException("The server requires that the client support Enhanced RDP Security and certificate-based client authentication"); } throw new RDFatalException("Unknown Negotiation failure!"); } throw new RDFatalException("Negotiation failed, requested security level not supported by server."); }
protected static int ReadTag(RdpPacket packet, string Identifier) { int num = packet.ReadByte(); ReadLength(packet, Identifier); return(num); }
protected static int ReadTag(RdpPacket packet, int ExpectedTag, string Identifier) { int num = packet.ReadByte(); if (num != ExpectedTag) { throw new Exception(string.Concat(new object[] { "Expected DER tag ", ExpectedTag, " but got ", num })); } return(ReadLength(packet, Identifier)); }
internal static RdpPacket Receive() { byte[] buffer = new byte[0x3000]; int count = Network.Receive(buffer); RdpPacket packet = new RdpPacket(); packet.Write(buffer, 0, count); packet.Position = 0L; int num2 = 0; if (packet.ReadByte() == 3) { packet.ReadByte(); num2 = packet.ReadBigEndian16(); long position = packet.Position; while (num2 > count) { int num4 = Network.Receive(buffer); packet.Position = count; packet.Write(buffer, 0, num4); count += num4; } packet.Position = position; return(packet); } num2 = packet.ReadByte(); if ((num2 & 0x80) != 0) { num2 &= -129; num2 = num2 << (8 + packet.ReadByte()); } return(packet); }
protected static int ReadLength(RdpPacket packet, string Identifier) { int num; byte[] buffer = new byte[4]; int num2 = packet.ReadByte(); switch (num2) { case 0x84: buffer[3] = (byte)packet.ReadByte(); buffer[2] = (byte)packet.ReadByte(); buffer[1] = (byte)packet.ReadByte(); buffer[0] = (byte)packet.ReadByte(); num = BitConverter.ToInt32(buffer, 0); break; case 0x83: buffer[2] = (byte)packet.ReadByte(); buffer[1] = (byte)packet.ReadByte(); buffer[0] = (byte)packet.ReadByte(); num = BitConverter.ToInt32(buffer, 0); break; case 130: buffer[1] = (byte)packet.ReadByte(); buffer[0] = (byte)packet.ReadByte(); num = BitConverter.ToInt32(buffer, 0); break; case 0x81: num = packet.ReadByte(); break; default: num = num2; break; } m_Fixup.Add(Identifier, new Fixup(Identifier, packet.Position, num)); return(num); }