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)); }
/// <summary> /// Send and receive an RPC message. /// </summary> /// <param name="proc_num">The procedure number.</param> /// <param name="objuuid">The object UUID for the call.</param> /// <param name="data_representation">NDR data representation.</param> /// <param name="ndr_buffer">Marshal NDR buffer for the call.</param> /// <param name="handles">List of handles marshaled into the buffer.</param> /// <returns>Client response from the send.</returns> public RpcClientResponse SendReceive(int proc_num, Guid objuuid, NdrDataRepresentation data_representation, byte[] ndr_buffer, IReadOnlyCollection <NtObject> handles) { NdrUnmarshalBuffer.CheckDataRepresentation(data_representation); PDURequest request = new PDURequest { OpNum = (short)proc_num, ObjectUUID = objuuid, StubData = ndr_buffer }; var recv_pdu = SendReceivePDU(request); if (recv_pdu is PDUResponse pdu_respose) { return(new RpcClientResponse(pdu_respose.StubData, new NtObject[0])); } else { throw new RpcTransportException("Unexpected PDU from server."); } }
/// <summary> /// Send and receive an RPC message. /// </summary> /// <param name="proc_num">The procedure number.</param> /// <param name="objuuid">The object UUID for the call.</param> /// <param name="data_representation">NDR data representation.</param> /// <param name="ndr_buffer">Marshal NDR buffer for the call.</param> /// <param name="handles">List of handles marshaled into the buffer.</param> /// <returns>Client response from the send.</returns> public RpcClientResponse SendReceive(int proc_num, Guid objuuid, NdrDataRepresentation data_representation, byte[] ndr_buffer, IReadOnlyCollection <NtObject> handles) { NdrUnmarshalBuffer.CheckDataRepresentation(data_representation); return(new RpcClientResponse(SendReceiveRequestPDU(proc_num, objuuid, ndr_buffer), new NtObject[0])); }