private static CAPABILITY_HEADER DecodeCapabilityHeader(byte[] data, ref int index, bool isBigEndian) { CAPABILITY_HEADER header = new CAPABILITY_HEADER(); header.CapabilityType = (CapabilityType_Values)ParseUInt16(data, ref index, isBigEndian); header.CapabilityLength = ParseUInt16(data, ref index, isBigEndian); header.Version = (CAPABILITY_VERSION)ParseUInt32(data, ref index, isBigEndian); return(header); }
/// <summary> /// Decode Client Core Capability Response packet /// </summary> /// <param name="data">Packet data</param> /// <returns>Client Core Capability Response packet</returns> public static DR_CORE_CAPABILITY_RSP DecodeClientCoreCapabilityRSP(byte[] data) { int index = 0; DR_CORE_CAPABILITY_RSP packet = new DR_CORE_CAPABILITY_RSP(); packet.Header = DecodeRdpdrHeader(data, ref index, false); packet.numCapabilities = ParseUInt16(data, ref index, false); packet.Padding = ParseUInt16(data, ref index, false); List <CAPABILITY_SET> capbilityList = new List <CAPABILITY_SET>(); while (index + 8 <= data.Length) { CAPABILITY_HEADER header = DecodeCapabilityHeader(data, ref index, false); if (header.CapabilityType == CapabilityType_Values.CAP_GENERAL_TYPE) { int originalIndex = index; GENERAL_CAPS_SET capSet = new GENERAL_CAPS_SET(); capSet.Header = header; capSet.osType = (osType_Values)ParseUInt32(data, ref index, false); capSet.osVersion = (osVersion_Values)ParseUInt32(data, ref index, false); capSet.protocolMajorVersion = (protocolMajorVersion_Values)ParseUInt16(data, ref index, false); capSet.protocolMinorVersion = ParseUInt16(data, ref index, false); capSet.ioCode1 = (ioCode1_Values)ParseUInt32(data, ref index, false); capSet.ioCode2 = (ioCode2_Values)ParseUInt32(data, ref index, false); capSet.extendedPDU = (extendedPDU_Values)ParseUInt32(data, ref index, false); capSet.extraFlags1 = (extraFlags1_Values)ParseUInt32(data, ref index, false); capSet.extraFlags2 = (extraFlags2_Values)ParseUInt32(data, ref index, false); capSet.SpecialTypeDeviceCap = ParseUInt32(data, ref index, false); index = originalIndex + header.CapabilityLength; capbilityList.Add(capSet); } else if (header.CapabilityType == CapabilityType_Values.CAP_PRINTER_TYPE) { PRINTER_CAPS_SET capSet = new PRINTER_CAPS_SET(); capSet.Header = header; capbilityList.Add(capSet); } else if (header.CapabilityType == CapabilityType_Values.CAP_DRIVE_TYPE) { DRIVE_CAPS_SET capSet = new DRIVE_CAPS_SET(); capSet.Header = header; capbilityList.Add(capSet); } else if (header.CapabilityType == CapabilityType_Values.CAP_PORT_TYPE) { PORT_CAPS_SET capSet = new PORT_CAPS_SET(); capSet.Header = header; capbilityList.Add(capSet); } else if (header.CapabilityType == CapabilityType_Values.CAP_SMARTCARD_TYPE) { SMARTCARD_CAPS_SET capSet = new SMARTCARD_CAPS_SET(); capSet.Header = header; capbilityList.Add(capSet); } else { return(null); } } packet.CapabilityMessage = capbilityList.ToArray(); return(packet); }