Exemplo n.º 1
0
        /// <summary>
        /// Decode CO PDU.
        /// </summary>
        /// <param name="context">The context that received data.</param>
        /// <param name="messageBytes">bytes received</param>
        /// <param name="consumedLength">num of bytes consumed in processing</param>
        /// <param name="expectedLength">num of bytes expected if the bytes is not enough</param>
        /// <returns>pdus</returns>
        internal static RpceCoPdu[] DecodeCoPdu(
            RpceContext context,
            byte[] messageBytes,
            out int consumedLength,
            out int expectedLength)
        {
            List <RpceCoPdu> pduList = new List <RpceCoPdu>();

            consumedLength = 0;
            expectedLength = 0;

            while (consumedLength < messageBytes.Length)
            {
                if ((messageBytes.Length - consumedLength) < RpceUtility.CO_PDU_HEADER_SIZE)
                {
                    expectedLength = RpceUtility.CO_PDU_HEADER_SIZE;
                    break;
                }

                //#4 byte is drep
                uint dataRepresentation = BitConverter.ToUInt32(
                    messageBytes,
                    consumedLength + RpceUtility.DREP_FIELD_OFFSET);
                //#8 byte is frag_length
                ushort fragmentLength = BitConverter.ToUInt16(
                    messageBytes,
                    consumedLength + RpceUtility.FRAG_LENGTH_FIELD_OFFSET);
                if ((dataRepresentation & 0x0000FFFFU) != NativeMethods.NDR_LOCAL_DATA_REPRESENTATION)
                {
                    fragmentLength = EndianUtility.ReverseByteOrder(fragmentLength);
                }

                if ((messageBytes.Length - consumedLength) < fragmentLength)
                {
                    expectedLength = fragmentLength;
                    break;
                }

                byte[] pduBytes = new byte[fragmentLength];
                Buffer.BlockCopy(messageBytes, consumedLength, pduBytes, 0, fragmentLength);

                RpceCoPdu pdu = RpceUtility.DecodeCoPdu(context, pduBytes);

                pduList.Add(pdu);
                consumedLength += fragmentLength;
            }

            return(pduList.ToArray());
        }
        /// <summary>
        /// Decode CO PDU.
        /// </summary>
        /// <param name="context">The context that received data.</param>
        /// <param name="messageBytes">bytes received</param>
        /// <param name="consumedLength">num of bytes consumed in processing</param>
        /// <param name="expectedLength">num of bytes expected if the bytes is not enough</param>
        /// <returns>pdus</returns>
        internal static RpceCoPdu[] DecodeCoPdu(
            RpceContext context,
            byte[] messageBytes,
            out int consumedLength,
            out int expectedLength)
        {
            List <RpceCoPdu> pduList = new List <RpceCoPdu>();

            consumedLength = 0;
            expectedLength = 0;

            while (consumedLength < messageBytes.Length)
            {
                if ((messageBytes.Length - consumedLength) < RpceUtility.CO_PDU_HEADER_SIZE)
                {
                    expectedLength = RpceUtility.CO_PDU_HEADER_SIZE;
                    break;
                }

                //#8 byte is frag_length
                ushort fragmentLength = BitConverter.ToUInt16(
                    messageBytes,
                    consumedLength + RpceUtility.FRAG_LENGTH_FIELD_OFFSET);
                if ((messageBytes.Length - consumedLength) < fragmentLength)
                {
                    expectedLength = fragmentLength;
                    break;
                }

                byte[] pduBytes = new byte[fragmentLength];
                Buffer.BlockCopy(messageBytes, consumedLength, pduBytes, 0, fragmentLength);

                RpceCoPdu pdu = RpceUtility.DecodeCoPdu(context, pduBytes);

                pduList.Add(pdu);
                consumedLength += fragmentLength;
            }

            return(pduList.ToArray());
        }