Exemplo n.º 1
0
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);

            auth_verifier = RpceUtility.AuthVerifierFromBytes(
                binaryReader,
                auth_length);

            alloc_hint = binaryReader.ReadUInt32();
            p_cont_id  = binaryReader.ReadUInt16();
            opnum      = binaryReader.ReadUInt16();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                alloc_hint = EndianUtility.ReverseByteOrder(alloc_hint);
                p_cont_id  = EndianUtility.ReverseByteOrder(p_cont_id);
                opnum      = EndianUtility.ReverseByteOrder(opnum);
            }

            if ((pfc_flags & RpceCoPfcFlags.PFC_OBJECT_UUID) != 0)
            {
                @object = new Guid(binaryReader.ReadBytes(RpceUtility.GUID_SIZE));
            }

            int stubLength = frag_length;

            stubLength -= GetSize();
            if (auth_verifier != null)
            {
                stubLength -= auth_verifier.Value.auth_pad_length;
                stubLength -= RpceUtility.AUTH_VERIFIER_SIZE;
                stubLength -= auth_length;
            }
            stub = binaryReader.ReadBytes(stubLength);
        }
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);

            auth_verifier = RpceUtility.AuthVerifierFromBytes(
                binaryReader,
                auth_length);

            alloc_hint   = binaryReader.ReadUInt32();
            p_cont_id    = binaryReader.ReadUInt16();
            cancel_count = binaryReader.ReadByte();
            reserved     = binaryReader.ReadByte();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                alloc_hint = EndianUtility.ReverseByteOrder(alloc_hint);
                p_cont_id  = EndianUtility.ReverseByteOrder(p_cont_id);
            }

            // read stub.
            int stubLength = frag_length;

            stubLength -= GetSize();
            if (auth_verifier != null)
            {
                stubLength -= auth_verifier.Value.auth_pad_length;
                stubLength -= RpceUtility.AUTH_VERIFIER_SIZE;
                stubLength -= auth_length;
            }
            stub = binaryReader.ReadBytes(stubLength);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);
            auth_verifier = RpceUtility.AuthVerifierFromBytes(
                binaryReader,
                auth_length);
            pad = binaryReader.ReadUInt32();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                pad = EndianUtility.ReverseByteOrder(pad);
            }
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);

            if (packed_drep.dataRepFormat == RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                provider_reject_reason = (p_reject_reason_t)binaryReader.ReadUInt16();
            }
            else
            {
                provider_reject_reason = (p_reject_reason_t)EndianUtility.ReverseByteOrder(binaryReader.ReadUInt16());
            }

            versions             = new p_rt_versions_supported_t();
            versions.n_protocols = binaryReader.ReadByte();
            versions.p_protocols = new version_t[versions.n_protocols];
            for (int i = 0; i < versions.n_protocols; i++)
            {
                versions.p_protocols[i].major = binaryReader.ReadByte();
                versions.p_protocols[i].minor = binaryReader.ReadByte();
            }

            //Assume that the client calculates the length of the PDU
            //until the Signature field as L.
            //If the frag_length field is greater than or equal to L
            //plus the size of the Signature field,
            //the client SHOULD assume that the Signature field is present.
            //Otherwise, the client SHOULD assume that the Signature field is not present.
            //TD shows the signature is aligned at 4.
            int L = RpceUtility.Align((int)binaryReader.BaseStream.Position, 4);

            if (frag_length >= (L + RpceUtility.GUID_SIZE))
            {
                pad                 = binaryReader.ReadBytes(L - (int)binaryReader.BaseStream.Position);
                signature           = new Guid(binaryReader.ReadBytes(RpceUtility.GUID_SIZE));
                extended_error_info = binaryReader.ReadBytes(frag_length - L - RpceUtility.GUID_SIZE);

                if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
                {
                    signature = EndianUtility.ReverseByteOrder((Guid)signature);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">A binary reader.</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            rpc_vers                  = binaryReader.ReadByte();
            rpc_vers_minor            = binaryReader.ReadByte();
            PTYPE                     = (RpcePacketType)binaryReader.ReadByte();
            pfc_flags                 = (RpceCoPfcFlags)binaryReader.ReadByte();
            packed_drep               = new DataRepresentationFormatLabel();
            packed_drep.dataRepFormat = (RpceDataRepresentationFormat)binaryReader.ReadUInt16();
            packed_drep.reserved      = binaryReader.ReadUInt16();
            frag_length               = binaryReader.ReadUInt16();
            auth_length               = binaryReader.ReadUInt16();
            call_id                   = binaryReader.ReadUInt32();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                frag_length = EndianUtility.ReverseByteOrder(frag_length);
                auth_length = EndianUtility.ReverseByteOrder(auth_length);
                call_id     = EndianUtility.ReverseByteOrder(call_id);
            }
        }
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);

            auth_verifier = RpceUtility.AuthVerifierFromBytes(
                binaryReader,
                auth_length);

            max_xmit_frag  = binaryReader.ReadUInt16();
            max_recv_frag  = binaryReader.ReadUInt16();
            assoc_group_id = binaryReader.ReadUInt32();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                max_xmit_frag  = EndianUtility.ReverseByteOrder(max_xmit_frag);
                max_recv_frag  = EndianUtility.ReverseByteOrder(max_recv_frag);
                assoc_group_id = EndianUtility.ReverseByteOrder(assoc_group_id);
            }

            sec_addr        = new port_any_t();
            sec_addr.length = binaryReader.ReadUInt16();
            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                sec_addr.length = EndianUtility.ReverseByteOrder(sec_addr.length);
            }
            sec_addr.port_spec = binaryReader.ReadBytes(sec_addr.length);

            // restore 4-octet alignment
            int pad2Length = RpceUtility.Align((int)binaryReader.BaseStream.Position, 4)
                             - (int)binaryReader.BaseStream.Position;

            pad2 = binaryReader.ReadBytes(pad2Length);

            p_result_list           = new p_result_list_t();
            p_result_list.n_results = binaryReader.ReadByte();
            p_result_list.reserved  = binaryReader.ReadByte();
            p_result_list.reserved2 = binaryReader.ReadUInt16();

            p_result_list.p_results = new p_result_t[p_result_list.n_results];
            for (int i = 0; i < p_result_list.n_results; i++)
            {
                if (packed_drep.dataRepFormat == RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
                {
                    p_result_list.p_results[i].result = (p_cont_def_result_t)binaryReader.ReadUInt16();
                    p_result_list.p_results[i].reason = (p_provider_reason_t)binaryReader.ReadUInt16();
                }
                else
                {
                    p_result_list.p_results[i].result = (p_cont_def_result_t)EndianUtility.ReverseByteOrder(binaryReader.ReadUInt16());
                    p_result_list.p_results[i].reason = (p_provider_reason_t)EndianUtility.ReverseByteOrder(binaryReader.ReadUInt16());
                }

                p_result_list.p_results[i].transfer_syntax = new p_syntax_id_t();
                p_result_list.p_results[i].transfer_syntax.if_uuid
                    = new Guid(binaryReader.ReadBytes(RpceUtility.GUID_SIZE));
                p_result_list.p_results[i].transfer_syntax.if_version
                    = binaryReader.ReadUInt32();

                if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
                {
                    p_result_list.p_results[i].transfer_syntax.if_uuid    = EndianUtility.ReverseByteOrder(p_result_list.p_results[i].transfer_syntax.if_uuid);
                    p_result_list.p_results[i].transfer_syntax.if_version = EndianUtility.ReverseByteOrder(p_result_list.p_results[i].transfer_syntax.if_version);
                }
            }
        }
        /// <summary>
        /// Un-marshal a byte array to PDU struct.
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        internal override void FromBytes(BinaryReader binaryReader)
        {
            base.FromBytes(binaryReader);

            auth_verifier = RpceUtility.AuthVerifierFromBytes(
                binaryReader,
                auth_length);

            max_xmit_frag  = binaryReader.ReadUInt16();
            max_recv_frag  = binaryReader.ReadUInt16();
            assoc_group_id = binaryReader.ReadUInt32();

            if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
            {
                max_xmit_frag  = EndianUtility.ReverseByteOrder(max_xmit_frag);
                max_recv_frag  = EndianUtility.ReverseByteOrder(max_recv_frag);
                assoc_group_id = EndianUtility.ReverseByteOrder(assoc_group_id);
            }

            p_context_elem = new p_cont_list_t();

            p_context_elem.n_context_elem = binaryReader.ReadByte();
            p_context_elem.reserved       = binaryReader.ReadByte();
            p_context_elem.reserved2      = binaryReader.ReadUInt16();

            p_context_elem.p_cont_elem = new p_cont_elem_t[p_context_elem.n_context_elem];
            for (int i = 0; i < p_context_elem.n_context_elem; i++)
            {
                p_context_elem.p_cont_elem[i].p_cont_id      = binaryReader.ReadUInt16();
                p_context_elem.p_cont_elem[i].n_transfer_syn = binaryReader.ReadByte();
                p_context_elem.p_cont_elem[i].reserved       = binaryReader.ReadByte();

                p_context_elem.p_cont_elem[i].abstract_syntax = new p_syntax_id_t();
                p_context_elem.p_cont_elem[i].abstract_syntax.if_uuid
                    = new Guid(binaryReader.ReadBytes(RpceUtility.GUID_SIZE));
                p_context_elem.p_cont_elem[i].abstract_syntax.if_version
                    = binaryReader.ReadUInt32();

                if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
                {
                    p_context_elem.p_cont_elem[i].p_cont_id = EndianUtility.ReverseByteOrder(p_context_elem.p_cont_elem[i].p_cont_id);
                    p_context_elem.p_cont_elem[i].abstract_syntax.if_uuid    = EndianUtility.ReverseByteOrder(p_context_elem.p_cont_elem[i].abstract_syntax.if_uuid);
                    p_context_elem.p_cont_elem[i].abstract_syntax.if_version = EndianUtility.ReverseByteOrder(p_context_elem.p_cont_elem[i].abstract_syntax.if_version);
                }

                p_context_elem.p_cont_elem[i].transfer_syntaxes
                    = new p_syntax_id_t[p_context_elem.p_cont_elem[i].n_transfer_syn];
                for (int j = 0; j < p_context_elem.p_cont_elem[i].transfer_syntaxes.Length; j++)
                {
                    p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_uuid
                        = new Guid(binaryReader.ReadBytes(RpceUtility.GUID_SIZE));
                    p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_version
                        = binaryReader.ReadUInt32();

                    if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII)
                    {
                        p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_uuid    = EndianUtility.ReverseByteOrder(p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_uuid);
                        p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_version = EndianUtility.ReverseByteOrder(p_context_elem.p_cont_elem[i].transfer_syntaxes[j].if_version);
                    }
                }
            }
        }