/// <summary>
        /// to decode stack packet from the received message bytes. 
        /// </summary>
        /// <param name = "endPointIdentity">the endPointIdentity from which the message bytes are received. </param>
        /// <param name = "messageBytes">the received message bytes to be decoded. </param>
        /// <param name = "consumedLength">the length of message bytes consumed by decoder. </param>
        /// <param name = "expectedLength">the length of message bytes the decoder expects to receive. </param>
        /// <returns>the stack packets decoded from the received message bytes. </returns>
        internal new SmbPacket[] DecodePacket(
            object endPointIdentity, byte[] messageBytes, out int consumedLength, out int expectedLength)
        {
            // initialize the default values
            expectedLength = 0;
            consumedLength = 0;
            SmbPacket[] packets = null;

            switch (this.smbClient.Capability.TransportType)
            {
                case TransportType.TCP:
                    // direct tcp transport management instance
                    SmbDirectTcpPacket directTcp = new SmbDirectTcpPacket(null);

                    // get the endpoint for direct tcp transport
                    int endpoint = smbClient.Context.GetConnectionID(endPointIdentity as IPEndPoint);

                    // message bytes is invalid
                    if (directTcp.IsPacketInvalid(messageBytes))
                    {
                        return null;
                    }

                    // if the packet has continue packet, do not parse it.
                    if (directTcp.HasContinuousPacket(messageBytes))
                    {
                        return null;
                    }

                    // decode the data of packet
                    byte[] packetBytes = directTcp.GetTcpData(messageBytes);
                    packets = DecodePacketFromBytesWithoutTransport(endpoint, packetBytes, out consumedLength, out expectedLength);

                    // decode the header of packet
                    if (packets != null && packets.Length > 0)
                    {
                        packets[0].TransportHeader = CifsMessageUtils.ToStuct<TransportHeader>(messageBytes);
                    }

                    // to consume the additional data
                    consumedLength = Math.Max(consumedLength, directTcp.GetTcpPacketLength(messageBytes));

                    // update the consumed length with transport
                    consumedLength += directTcp.TcpTransportHeaderSize;

                    break;

                case TransportType.NetBIOS:
                    // decode packet
                    packets = DecodePacketFromBytesWithoutTransport(
                        Convert.ToInt32(endPointIdentity), messageBytes, out consumedLength, out expectedLength);

                    break;

                default:
                    break;
            }

            return packets;
        }
        /// <summary>
        /// to decode stack packet from the received message bytes.
        /// </summary>
        /// <param name = "endPointIdentity">the endPointIdentity from which the message bytes are received. </param>
        /// <param name = "messageBytes">the received message bytes to be decoded. </param>
        /// <param name = "consumedLength">the length of message bytes consumed by decoder. </param>
        /// <param name = "expectedLength">the length of message bytes the decoder expects to receive. </param>
        /// <returns>the stack packets decoded from the received message bytes. </returns>
        internal new SmbPacket[] DecodePacket(
            object endPointIdentity, byte[] messageBytes, out int consumedLength, out int expectedLength)
        {
            // initialize the default values
            expectedLength = 0;
            consumedLength = 0;
            SmbPacket[] packets = null;

            switch (this.smbClient.Capability.TransportType)
            {
            case TransportType.TCP:
                // direct tcp transport management instance
                SmbDirectTcpPacket directTcp = new SmbDirectTcpPacket(null);

                // get the endpoint for direct tcp transport
                int endpoint = smbClient.Context.GetConnectionID(endPointIdentity as IPEndPoint);

                // message bytes is invalid
                if (directTcp.IsPacketInvalid(messageBytes))
                {
                    return(null);
                }

                // if the packet has continue packet, do not parse it.
                if (directTcp.HasContinuousPacket(messageBytes))
                {
                    return(null);
                }

                // decode the data of packet
                byte[] packetBytes = directTcp.GetTcpData(messageBytes);
                packets = DecodePacketFromBytesWithoutTransport(endpoint, packetBytes, out consumedLength, out expectedLength);

                // decode the header of packet
                if (packets != null && packets.Length > 0)
                {
                    packets[0].TransportHeader = CifsMessageUtils.ToStuct <TransportHeader>(messageBytes);
                }

                // to consume the additional data
                consumedLength = Math.Max(consumedLength, directTcp.GetTcpPacketLength(messageBytes));

                // update the consumed length with transport
                consumedLength += directTcp.TcpTransportHeaderSize;

                break;

            case TransportType.NetBIOS:
                // decode packet
                packets = DecodePacketFromBytesWithoutTransport(
                    Convert.ToInt32(endPointIdentity), messageBytes, out consumedLength, out expectedLength);

                break;

            default:
                break;
            }

            return(packets);
        }
Exemplo n.º 3
0
        public SmbPacket[] DecodePacket(
            object endPointIdentity, byte[] messageBytes, out int consumedLength, out int expectedLength)
        {
            // initialize the default values
            expectedLength = 0;
            consumedLength = 0;
            SmbPacket[] packets = null;

            byte[] packetBytes = null;
            // direct tcp transport management instance
            SmbDirectTcpPacket directTcp = new SmbDirectTcpPacket(null);

            // Netbios over Tcp
            if (endPointIdentity is int)
            {
                packetBytes = messageBytes;
            }
            // Direct Tcp
            else
            {
                // message bytes is invalid
                if (directTcp.IsPacketInvalid(messageBytes))
                {
                    return(null);
                }

                // if the packet has continue packet, do not parse it.
                if (directTcp.HasContinuousPacket(messageBytes))
                {
                    return(null);
                }

                // decode the data of packet
                packetBytes = directTcp.GetTcpData(messageBytes);
            }

            packets = DecodePacketFromBytesWithoutTransport(
                this.context.GetConnection(endPointIdentity), packetBytes, out consumedLength, out expectedLength);

            // decode the header of packet
            if (packets != null && packets.Length > 0)
            {
                packets[0].TransportHeader = CifsMessageUtils.ToStuct <TransportHeader>(messageBytes);
            }

            // for Direct Tcp, calculate the cosumedlength and plus the Tcp header length.
            if (!(endPointIdentity is int))
            {
                // to consume the additional data
                consumedLength = Math.Max(consumedLength, directTcp.GetTcpPacketLength(messageBytes));

                // update the consumed length with transport
                consumedLength += directTcp.TcpTransportHeaderSize;
            }

            return(packets);
        }
        public SmbPacket[] DecodePacket(
            object endPointIdentity, byte[] messageBytes, out int consumedLength, out int expectedLength)
        {
            // initialize the default values
            expectedLength = 0;
            consumedLength = 0;
            SmbPacket[] packets = null;

            byte[] packetBytes = null;
            // direct tcp transport management instance
            SmbDirectTcpPacket directTcp = new SmbDirectTcpPacket(null);

            // Netbios over Tcp
            if (endPointIdentity is int)
            {
                packetBytes = messageBytes;
            }
            // Direct Tcp
            else
            {
                // message bytes is invalid
                if (directTcp.IsPacketInvalid(messageBytes))
                {
                    return null;
                }

                // if the packet has continue packet, do not parse it.
                if (directTcp.HasContinuousPacket(messageBytes))
                {
                    return null;
                }

                // decode the data of packet
                packetBytes = directTcp.GetTcpData(messageBytes);
            }

            packets = DecodePacketFromBytesWithoutTransport(
                this.context.GetConnection(endPointIdentity), packetBytes, out consumedLength, out expectedLength);

            // decode the header of packet
            if (packets != null && packets.Length > 0)
            {
                packets[0].TransportHeader = CifsMessageUtils.ToStuct<TransportHeader>(messageBytes);
            }

            // for Direct Tcp, calculate the cosumedlength and plus the Tcp header length.
            if (!(endPointIdentity is int))
            {
                // to consume the additional data
                consumedLength = Math.Max(consumedLength, directTcp.GetTcpPacketLength(messageBytes));

                // update the consumed length with transport
                consumedLength += directTcp.TcpTransportHeaderSize;
            }

            return packets;
        }