Beispiel #1
0
        /// <summary>
        /// Read the next fragment from the transport.
        /// </summary>
        /// <param name="max_recv_fragment">The maximum receive fragment length.</param>
        /// <returns>The read fragment.</returns>
        protected override byte[] ReadFragment(int max_recv_fragment)
        {
            var header = PDUHeader.Read(_reader);

            byte[]       remaining = _reader.ReadAllBytes(header.FragmentLength - PDUHeader.PDU_HEADER_SIZE);
            MemoryStream stm       = new MemoryStream();
            BinaryWriter writer    = new BinaryWriter(stm);

            header.Write(writer);
            writer.Write(remaining);
            return(stm.ToArray());
        }
Beispiel #2
0
        private Tuple <PDUHeader, byte[]> ReadPDU(int frag_count)
        {
            byte[] buffer = _pipe.Read(_max_recv_fragment);
            RpcUtils.DumpBuffer(true, $"RPC Named Pipe Receive Buffer - Fragment {frag_count}", buffer);
            MemoryStream stm    = new MemoryStream(buffer);
            BinaryReader reader = new BinaryReader(stm);
            PDUHeader    header = PDUHeader.Read(reader);

            NdrUnmarshalBuffer.CheckDataRepresentation(header.DataRep);
            if (header.AuthLength != 0)
            {
                throw new NotSupportedException("Named pipe transport doesn't support authentication data.");
            }
            return(Tuple.Create(header, reader.ReadAllBytes(header.FragmentLength - PDUHeader.PDU_HEADER_SIZE)));
        }
        private Tuple <PDUHeader, byte[], AuthData> ReadPDU(int frag_count)
        {
            byte[] buffer = ReadFragment(_max_recv_fragment);
            RpcUtils.DumpBuffer(true, $"{GetType().Name} Receive Buffer - Fragment {frag_count}", buffer);
            MemoryStream stm    = new MemoryStream(buffer);
            BinaryReader reader = new BinaryReader(stm);
            PDUHeader    header = PDUHeader.Read(reader);

            NdrUnmarshalBuffer.CheckDataRepresentation(header.DataRep);
            AuthData auth_data            = new AuthData();
            int      auth_trailing_length = header.AuthLength > 0 ? header.AuthLength + AuthData.PDU_AUTH_DATA_HEADER_SIZE : 0;

            byte[] data = reader.ReadAllBytes(header.FragmentLength - PDUHeader.PDU_HEADER_SIZE - auth_trailing_length);
            if (auth_trailing_length > 0)
            {
                stm.Seek(header.FragmentLength - auth_trailing_length, SeekOrigin.Begin);
                auth_data = AuthData.Read(reader, header.AuthLength);
            }
            return(Tuple.Create(header, data, auth_data));
        }