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