/// <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(); }
/// <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> /// Generate PFC_*** based on context and package type. /// </summary> /// <param name="context">Context of the session.</param> /// <param name="packageType">package type.</param> /// <returns>RFC_*** flag.</returns> internal static RpceCoPfcFlags GeneratePfcFlags(RpceContext context, RpcePacketType packageType) { RpceServerSessionContext sessionContext = context as RpceServerSessionContext; RpceCoPfcFlags flags = RpceCoPfcFlags.PFC_FIRST_FRAG | RpceCoPfcFlags.PFC_LAST_FRAG; if (sessionContext == null) //client-side { if (context.SupportsConcurrentMultiplexing) { flags |= RpceCoPfcFlags.PFC_CONC_MPX; } } else if ( //server-side (packageType == RpcePacketType.BindAck && sessionContext.ServerContext.SupportsConcurrentMultiplexing) || // first response, read server context sessionContext.SupportsConcurrentMultiplexing) // if it's not first response, we can read session context { flags |= RpceCoPfcFlags.PFC_CONC_MPX; } if ((packageType == RpcePacketType.Bind || packageType == RpcePacketType.BindAck || packageType == RpcePacketType.AlterContext || packageType == RpcePacketType.AlterContextResp) && context.SupportsHeaderSign) { if (sessionContext == null || //client-side sessionContext.ServerContext.SupportsHeaderSign) //server-side { flags |= RpceCoPfcFlags.PFC_SUPPORT_HEADER_SIGN; } } return(flags); }
public static RpceCoPdu DecodeCoPdu( RpceContext context, byte[] pduBytes) { if (context == null) { throw new ArgumentNullException("context"); } if (pduBytes == null) { throw new ArgumentNullException("pduBytes"); } RpceCoPdu pdu; //#2 byte is PTYPE RpcePacketType packageType = (RpcePacketType)pduBytes[2]; //#3 byte is PFC_*** flags RpceCoPfcFlags pfcFlags = (RpceCoPfcFlags)pduBytes[3]; RpceCoPfcFlags pfcFlagsNoFragment = RpceCoPfcFlags.PFC_FIRST_FRAG | RpceCoPfcFlags.PFC_LAST_FRAG; if (((pfcFlags & pfcFlagsNoFragment) != pfcFlagsNoFragment) && (packageType == RpcePacketType.Bind || packageType == RpcePacketType.BindAck || packageType == RpcePacketType.AlterContext || packageType == RpcePacketType.AlterContextResp || packageType == RpcePacketType.Auth3)) { //If it's a fragment and PTYPE is bind/bind_ack/alter_context/alter_context_resp //Windows RPC support version 5.0 only. //Bind fragment requires RPC ver 5.1. //We don't support it. throw new NotSupportedException("bind/bind_ack/alt_context/alt_context_resp/auth3 PDU fragment are not supported."); } else { switch (packageType) { case RpcePacketType.Bind: pdu = new RpceCoBindPdu(context, pduBytes); break; case RpcePacketType.BindAck: pdu = new RpceCoBindAckPdu(context, pduBytes); break; case RpcePacketType.BindNak: pdu = new RpceCoBindNakPdu(context, pduBytes); break; case RpcePacketType.AlterContext: pdu = new RpceCoAlterContextPdu(context, pduBytes); break; case RpcePacketType.AlterContextResp: pdu = new RpceCoAlterContextRespPdu(context, pduBytes); break; case RpcePacketType.Auth3: pdu = new RpceCoAuth3Pdu(context, pduBytes); break; case RpcePacketType.Request: pdu = new RpceCoRequestPdu(context, pduBytes); break; case RpcePacketType.Response: pdu = new RpceCoResponsePdu(context, pduBytes); break; case RpcePacketType.Fault: pdu = new RpceCoFaultPdu(context, pduBytes); break; case RpcePacketType.CoCancel: pdu = new RpceCoCancelPdu(context, pduBytes); break; case RpcePacketType.Orphaned: pdu = new RpceCoOrphanedPdu(context, pduBytes); break; case RpcePacketType.Shutdown: pdu = new RpceCoShutdownPdu(context, pduBytes); break; default: throw new InvalidOperationException( string.Format("Receive invalid packet - {0}.", packageType)); } } return(pdu); }
/// <summary> /// Create an RpceCoBindPdu. /// </summary> /// <param name="rpcVersionMinor"> /// RPC version minor. /// </param> /// <param name="pfcFlags"> /// PFC_*** flags. /// </param> /// <param name="callId"> /// Call Id. /// </param> /// <param name="maxTransmitFragmentSize"> /// Max transmit fragment size, in bytes. /// </param> /// <param name="maxReceiveFragmentSize"> /// Max receive fragment size, in bytes. /// </param> /// <param name="associateGroupId"> /// Associated group id. /// </param> /// <param name="interfaceId"> /// A Guid of interface_id that is binding to. /// </param> /// <param name="interfaceMajorVersion"> /// interface_major_ver that is binding to. /// </param> /// <param name="interfaceMinorVersion"> /// interface_minor_ver that is binding to. /// </param> /// <param name="ndrVersion"> /// NDR version to be used to marshal/un-marshal stub. /// </param> /// <param name="bindTimeFeatureNegotiationBitmask"> /// BindTimeFeatureNegotiationBitmask to sent. /// Set the value to null if client donot support the feature. /// </param> /// <returns> /// Created RpceCoBindPdu, it's ok to be sent out if there's /// no modification to any field of the PDU. /// </returns> public RpceCoBindPdu CreateCoBindPdu( byte rpcVersionMinor, RpceCoPfcFlags pfcFlags, uint callId, ushort maxTransmitFragmentSize, ushort maxReceiveFragmentSize, uint associateGroupId, Guid interfaceId, ushort interfaceMajorVersion, ushort interfaceMinorVersion, RpceNdrVersion ndrVersion, RpceBindTimeFeatureNegotiationBitmask? bindTimeFeatureNegotiationBitmask) { RpceCoBindPdu bindPdu = new RpceCoBindPdu(context); bindPdu.rpc_vers = 5; bindPdu.rpc_vers_minor = rpcVersionMinor; bindPdu.PTYPE = RpcePacketType.Bind; bindPdu.pfc_flags = pfcFlags | RpceCoPfcFlags.PFC_FIRST_FRAG | RpceCoPfcFlags.PFC_LAST_FRAG; bindPdu.packed_drep.dataRepFormat = RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII; bindPdu.packed_drep.reserved = 0; bindPdu.call_id = callId; bindPdu.max_xmit_frag = maxTransmitFragmentSize; bindPdu.max_recv_frag = maxReceiveFragmentSize; bindPdu.assoc_group_id = associateGroupId; List<p_cont_elem_t> p_cont_elem_list = new List<p_cont_elem_t>(); if ((ndrVersion & RpceNdrVersion.NDR) == RpceNdrVersion.NDR) { p_cont_elem_t p_cont_elem; p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count); p_cont_elem.n_transfer_syn = 1; p_cont_elem.reserved = 0; p_cont_elem.abstract_syntax.if_uuid = interfaceId; p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion; p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion; p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1]; p_cont_elem.transfer_syntaxes[0].if_uuid = RpceUtility.NDR_INTERFACE_UUID; p_cont_elem.transfer_syntaxes[0].if_vers_major = RpceUtility.NDR_INTERFACE_MAJOR_VERSION; p_cont_elem.transfer_syntaxes[0].if_vers_minor = RpceUtility.NDR_INTERFACE_MINOR_VERSION; p_cont_elem_list.Add(p_cont_elem); } if ((ndrVersion & RpceNdrVersion.NDR64) == RpceNdrVersion.NDR64) { p_cont_elem_t p_cont_elem; p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count); p_cont_elem.n_transfer_syn = 1; p_cont_elem.reserved = 0; p_cont_elem.abstract_syntax.if_uuid = interfaceId; p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion; p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion; p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1]; p_cont_elem.transfer_syntaxes[0].if_uuid = RpceUtility.NDR64_INTERFACE_UUID; p_cont_elem.transfer_syntaxes[0].if_vers_major = RpceUtility.NDR64_INTERFACE_MAJOR_VERSION; p_cont_elem.transfer_syntaxes[0].if_vers_minor = RpceUtility.NDR64_INTERFACE_MINOR_VERSION; p_cont_elem_list.Add(p_cont_elem); } if (bindTimeFeatureNegotiationBitmask != null) { p_cont_elem_t p_cont_elem; p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count); p_cont_elem.n_transfer_syn = 1; p_cont_elem.reserved = 0; p_cont_elem.abstract_syntax.if_uuid = interfaceId; p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion; p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion; p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1]; byte[] guidBytes = new byte[RpceUtility.GUID_SIZE]; // length of a Guid Buffer.BlockCopy( RpceUtility.BIND_TIME_FEATURE_NEGOTIATION_BITMASK_GUID_BYTES, 0, guidBytes, 0, RpceUtility.GUID_SIZE); guidBytes[RpceUtility.BIND_TIME_FEATURE_NEGOTIATION_BITMASK_PREFIX_LENGTH] = (byte)bindTimeFeatureNegotiationBitmask.Value; p_cont_elem.transfer_syntaxes[0].if_uuid = new Guid(guidBytes); p_cont_elem.transfer_syntaxes[0].if_vers_major = 1; p_cont_elem.transfer_syntaxes[0].if_vers_minor = 0; p_cont_elem_list.Add(p_cont_elem); } bindPdu.p_context_elem.n_context_elem = (byte)p_cont_elem_list.Count; bindPdu.p_context_elem.reserved = 0; bindPdu.p_context_elem.reserved2 = 0; bindPdu.p_context_elem.p_cont_elem = p_cont_elem_list.ToArray(); bindPdu.AppendAuthenticationVerifier(); bindPdu.SetLength(); return bindPdu; }