private void OnDataReceived(byte[] data, uint channelId)
 {
     lock (receivedList)
     {
         RdpefsPDU pdu      = new RdpefsPDU();
         bool      fSucceed = false;
         bool      fResult  = PduMarshaler.Unmarshal(data, pdu);
         if (fResult)
         {
             if (pdu.Header.PacketId == PacketId_Values.PAKID_CORE_CLIENTID_CONFIRM)
             {
                 // Header(4) + VersionMajor(2) + VersionMinor(2) + ClientId(4) = 12
                 DR_CORE_CLIENT_ANNOUNCE_RSP response = new DR_CORE_CLIENT_ANNOUNCE_RSP();
                 if (PduMarshaler.Unmarshal(data, response))
                 {
                     receivedList.Add(response);
                 }
             }
             else if (pdu.Header.PacketId == PacketId_Values.PAKID_CORE_CLIENT_NAME)
             {
                 // Header(4) + UnicodeFlag(4) + CodePage(4) + ComputerNameLen(4) + ComputerNmae(ComputerNameLen)
                 DR_CORE_CLIENT_NAME_REQ request = new DR_CORE_CLIENT_NAME_REQ();
                 if (PduMarshaler.Unmarshal(data, request))
                 {
                     receivedList.Add(request);
                 }
             }
             else if (pdu.Header.PacketId == PacketId_Values.PAKID_CORE_CLIENT_CAPABILITY)
             {
                 // Header(4) + numCapabilities(2) + Padding(2) + CapabilityMessage(numCapabilities * CAPABILITE_SET)
                 DR_CORE_CAPABILITY_RSP response = new DR_CORE_CAPABILITY_RSP();
                 if (PduMarshaler.Unmarshal(data, response))
                 {
                     receivedList.Add(response);
                 }
             }
             else if (pdu.Header.PacketId == PacketId_Values.PAKID_CORE_DEVICELIST_ANNOUNCE)
             {
                 // Header(4) + DeviceCount(4) + DeviceList(DeviceCount * DEVICE_ANNONUNCE)
                 DR_CORE_DEVICELIST_ANNOUNCE_REQ request = new DR_CORE_DEVICELIST_ANNOUNCE_REQ();
                 if (PduMarshaler.Unmarshal(data, request))
                 {
                     receivedList.Add(request);
                 }
             }
         }
         if (!fSucceed || !fResult)
         {
             RdpefsUnknownPdu unknown = new RdpefsUnknownPdu();
             if (PduMarshaler.Unmarshal(data, unknown))
             {
                 receivedList.Add(unknown);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Send and receive MS-RDPEFS data over DVC.
        /// </summary>
        public void EfsInitializationSequenceOverDVC()
        {
            //Sending Server Announce Request.
            SendServerPDUOverDVC(PacketId_Values.PAKID_CORE_SERVER_ANNOUNCE);

            //Expecting  Client Announce Reply.
            DR_CORE_CLIENT_ANNOUNCE_RSP AnnounceRsp = ExpectClientPduOverDVC <DR_CORE_CLIENT_ANNOUNCE_RSP>();
            uint clientId = AnnounceRsp.ClientId;

            //Expecting Client Name Request.
            DR_CORE_CLIENT_NAME_REQ NameReq = ExpectClientPduOverDVC <DR_CORE_CLIENT_NAME_REQ>();

            //Sending Server Core Capability Request.
            SendServerPDUOverDVC(PacketId_Values.PAKID_CORE_SERVER_CAPABILITY);

            //Sending Server Client ID Confirm.
            SendServerPDUOverDVC(PacketId_Values.PAKID_CORE_CLIENTID_CONFIRM, clientId);

            //Expecting Client Core Capability Response.
            DR_CORE_CAPABILITY_RSP capRsp = ExpectClientPduOverDVC <DR_CORE_CAPABILITY_RSP>();
        }
        /// <summary>
        /// Generate static virtual channel data messages for test.
        /// MS-RDPEFS is used to generated virtual channel traffics.
        /// </summary>
        /// <param name="invalidType">Invalid Type</param>
        public void GenerateStaticVirtualChannelTraffics(StaticVirtualChannel_InvalidType invalidType)
        {
            /*
             * MS-RDPEFS protocol Initialization.
             */

            byte[] receivedData = null;
            uint   clientId     = 0;

            if (invalidType == StaticVirtualChannel_InvalidType.None)
            {
                //Sending Server Announce Request.
                byte[] data = RdpefsUtility.EncodeServerAnnounceRequest(RdpefsUtility.CreateServerAnnounceRequest());
                SendVirtualChannelPDU(RDPDR_ChannelId, data, StaticVirtualChannel_InvalidType.None);

                //Expecting  Client Announce Reply.
                WaitForVirtualChannelPdu(RDPDR_ChannelId, out receivedData, pduWaitTimeSpan);
                DR_CORE_SERVER_ANNOUNCE_RSP reply = RdpefsUtility.DecodeClientAnnounceReply(receivedData);
                clientId = reply.ClientId;

                //Expecting Client Name Request.
                WaitForVirtualChannelPdu(RDPDR_ChannelId, out receivedData, pduWaitTimeSpan);

                //Sending Server Core Capability Request.
                data = RdpefsUtility.EncodeServerCoreCapabilityRequest(RdpefsUtility.CreateServerCoreCapabilityRequest());
                SendVirtualChannelPDU(RDPDR_ChannelId, data, StaticVirtualChannel_InvalidType.None);

                //Sending Server Client ID Confirm.
                data = RdpefsUtility.EncodeServerClientIDConfirm(RdpefsUtility.CreateServerClientIDConfirm(clientId));
                SendVirtualChannelPDU(RDPDR_ChannelId, data, StaticVirtualChannel_InvalidType.None);

                //Expecting Client Core Capability Response.
                WaitForVirtualChannelPdu(RDPDR_ChannelId, out receivedData, pduWaitTimeSpan);

                DR_CORE_CAPABILITY_RSP capRsp = RdpefsUtility.DecodeClientCoreCapabilityRSP(receivedData);
                bool supportUserLogonPacket   = false;
                foreach (CAPABILITY_SET capSet in capRsp.CapabilityMessage)
                {
                    if (capSet is GENERAL_CAPS_SET)
                    {
                        if (((GENERAL_CAPS_SET)capSet).extendedPDU.HasFlag(extendedPDU_Values.RDPDR_USER_LOGGEDON_PDU))
                        {
                            supportUserLogonPacket = true;
                        }
                    }
                }

                if (supportUserLogonPacket)
                {
                    // Send Server User logged on packet
                    data = RdpefsUtility.EncodeServerUserLoggedOn(RdpefsUtility.CreateServerUserLoggedOn());
                    SendVirtualChannelPDU(RDPDR_ChannelId, data, StaticVirtualChannel_InvalidType.None);
                }

                //Expecting Client Device List.
                WaitForVirtualChannelPdu(RDPDR_ChannelId, out receivedData, pduWaitTimeSpan);
            }
            else
            {
                //Sending Server Announce Request.
                byte[] data = RdpefsUtility.EncodeServerAnnounceRequest(RdpefsUtility.CreateServerAnnounceRequest());
                SendVirtualChannelPDU(RDPDR_ChannelId, data, invalidType);
                //WaitForVirtualChannelPdu(RDPDR_ChannelId, out receivedData, timeout);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generate static virtual channel data messages for test.
        /// MS-RDPEFS is used to generated virtual channel traffics.
        /// </summary>
        /// <param name="RDPDR_ChannelId">Static Channel Id for RDPDR</param>
        /// <param name="invalidType">Invalid Type</param>
        public void GenerateStaticVirtualChannelTraffics(StaticVirtualChannel_InvalidType invalidType = StaticVirtualChannel_InvalidType.None)
        {
            /*
             * MS-RDPEFS protocol Initialization.
             */

            byte[] receivedData = null;
            uint   clientId     = 0;

            UInt16 channelId = this.rdpbcgrAdapter.RDPDRChannelId;

            if (invalidType == StaticVirtualChannel_InvalidType.None)
            {
                //Sending Server Announce Request.
                byte[] data = rdpefsServer.EncodeServerPdu <DR_CORE_SERVER_ANNOUNCE_REQ>(CreateServerAnnounceReqest());
                this.rdpbcgrAdapter.SendVirtualChannelPDU(channelId, data, StaticVirtualChannel_InvalidType.None);

                //Expecting  Client Announce Reply.
                this.rdpbcgrAdapter.WaitForVirtualChannelPdu(channelId, out receivedData, waitTime);
                DR_CORE_CLIENT_ANNOUNCE_RSP reply = new DR_CORE_CLIENT_ANNOUNCE_RSP();
                bool fsuccess = rdpefsServer.DecodeClientPdu <DR_CORE_CLIENT_ANNOUNCE_RSP>(receivedData, reply);
                clientId = reply.ClientId;

                //Expecting Client Name Request.
                this.rdpbcgrAdapter.WaitForVirtualChannelPdu(channelId, out receivedData, waitTime);
                DR_CORE_CLIENT_NAME_REQ req = new DR_CORE_CLIENT_NAME_REQ();
                fsuccess = rdpefsServer.DecodeClientPdu <DR_CORE_CLIENT_NAME_REQ>(receivedData, req);

                //Sending Server Core Capability Request.
                data = rdpefsServer.EncodeServerPdu <DR_CORE_CAPABILITY_REQ>(CreateServerCoreCapabilityRequest());
                this.rdpbcgrAdapter.SendVirtualChannelPDU(channelId, data, StaticVirtualChannel_InvalidType.None);

                //Sending Server Client ID Confirm.
                data = rdpefsServer.EncodeServerPdu <DR_CORE_SERVER_CLIENTID_CONFIRM>(CreateServerClientIdConfirm(clientId));
                this.rdpbcgrAdapter.SendVirtualChannelPDU(channelId, data, StaticVirtualChannel_InvalidType.None);

                //Expecting Client Core Capability Response.
                this.rdpbcgrAdapter.WaitForVirtualChannelPdu(channelId, out receivedData, waitTime);
                DR_CORE_CAPABILITY_RSP capRsp = new DR_CORE_CAPABILITY_RSP();
                fsuccess = rdpefsServer.DecodeClientPdu <DR_CORE_CAPABILITY_RSP>(receivedData, capRsp);

                bool supportUserLogonPacket = false;
                foreach (CAPABILITY_SET capSet in capRsp.CapabilityMessage)
                {
                    if (capSet is GENERAL_CAPS_SET)
                    {
                        if (((GENERAL_CAPS_SET)capSet).extendedPDU.HasFlag(extendedPDU_Values.RDPDR_USER_LOGGEDON_PDU))
                        {
                            supportUserLogonPacket = true;
                        }
                    }
                }

                if (supportUserLogonPacket)
                {
                    // Send Server User logged on packet
                    data = rdpefsServer.EncodeServerPdu <DR_CORE_USER_LOGGEDON>(new DR_CORE_USER_LOGGEDON());
                    this.rdpbcgrAdapter.SendVirtualChannelPDU(channelId, data, StaticVirtualChannel_InvalidType.None);
                }

                //Expecting Client Device List.
                this.rdpbcgrAdapter.WaitForVirtualChannelPdu(channelId, out receivedData, waitTime);
                DR_CORE_DEVICELIST_ANNOUNCE_REQ announceReq = new DR_CORE_DEVICELIST_ANNOUNCE_REQ();
                fsuccess = rdpefsServer.DecodeClientPdu <DR_CORE_DEVICELIST_ANNOUNCE_REQ>(receivedData, announceReq);
            }
            else
            {
                //Sending Server Announce Request.
                byte[] data = rdpefsServer.EncodeServerPdu <DR_CORE_SERVER_ANNOUNCE_REQ>(CreateServerAnnounceReqest());
                this.rdpbcgrAdapter.SendVirtualChannelPDU(channelId, data, invalidType);
                //this.rdpbcgrAdapter.WaitForVirtualChannelPdu(channelId, out receivedData, timeout);
            }
        }
        /// <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);
        }