예제 #1
0
 private void ProcessRPCRequest(RPCPDU rpcRequest)
 {
     if (rpcRequest is BindPDU)
     {
         BindAckPDU bindAckPDU = RemoteServiceHelper.GetRPCBindResponse((BindPDU)rpcRequest, m_service);
         m_maxTransmitFragmentSize = bindAckPDU.MaxTransmitFragmentSize;
         Append(bindAckPDU.GetBytes());
     }
     else if (m_maxTransmitFragmentSize.HasValue && rpcRequest is RequestPDU) // if BindPDU was not received, we treat as protocol error
     {
         List <RPCPDU> responsePDUs = RemoteServiceHelper.GetRPCResponse((RequestPDU)rpcRequest, m_service, m_maxTransmitFragmentSize.Value);
         foreach (RPCPDU responsePDU in responsePDUs)
         {
             Append(responsePDU.GetBytes());
         }
     }
     else
     {
         FaultPDU faultPDU = new FaultPDU();
         faultPDU.Flags = PacketFlags.FirstFragment | PacketFlags.LastFragment;
         faultPDU.DataRepresentation = new DataRepresentationFormat(CharacterFormat.ASCII, ByteOrder.LittleEndian, FloatingPointRepresentation.IEEE);
         faultPDU.CallID             = 0;
         faultPDU.AllocationHint     = RPCPDU.CommonFieldsLength + FaultPDU.FaultFieldsLength;
         faultPDU.Status             = FaultStatus.ProtocolError;
         Append(faultPDU.GetBytes());
     }
 }
예제 #2
0
        public static List <RPCPDU> GetRPCResponse(RequestPDU requestPDU, RemoteService service, int maxTransmitFragmentSize)
        {
            List <RPCPDU> result = new List <RPCPDU>();

            byte[] responseBytes;
            try
            {
                responseBytes = service.GetResponseBytes(requestPDU.OpNum, requestPDU.Data);
            }
            catch (UnsupportedOpNumException)
            {
                FaultPDU faultPDU = new FaultPDU
                {
                    Flags = PacketFlags.FirstFragment | PacketFlags.LastFragment | PacketFlags.DidNotExecute,
                    DataRepresentation = requestPDU.DataRepresentation,
                    CallID             = requestPDU.CallID,
                    AllocationHint     = RPCPDU.CommonFieldsLength + FaultPDU.FaultFieldsLength,
                    // Windows will return either nca_s_fault_ndr or nca_op_rng_error.
                    Status = FaultStatus.OpRangeError
                };
                result.Add(faultPDU);
                return(result);
            }

            int offset           = 0;
            int maxPDUDataLength = maxTransmitFragmentSize - RPCPDU.CommonFieldsLength - ResponsePDU.ResponseFieldsLength;

            do
            {
                ResponsePDU responsePDU   = new ResponsePDU();
                int         pduDataLength = Math.Min(responseBytes.Length - offset, maxPDUDataLength);
                responsePDU.DataRepresentation = requestPDU.DataRepresentation;
                responsePDU.CallID             = requestPDU.CallID;
                responsePDU.AllocationHint     = (uint)(responseBytes.Length - offset);
                responsePDU.Data = ByteReader.ReadBytes(responseBytes, offset, pduDataLength);
                if (offset == 0)
                {
                    responsePDU.Flags |= PacketFlags.FirstFragment;
                }
                if (offset + pduDataLength == responseBytes.Length)
                {
                    responsePDU.Flags |= PacketFlags.LastFragment;
                }
                result.Add(responsePDU);
                offset += pduDataLength;
            }while (offset < responseBytes.Length);

            return(result);
        }