예제 #1
0
        public NTStatus ExecuteCall <I, O>(ushort OpNum, I inputArgs, out O outputData) where I : IRPCRequest
        {
            byte[]   output;
            NTStatus status;

            outputData = default(O);

            RequestPDU requestPDU = new RequestPDU();

            requestPDU.Flags = PacketFlags.FirstFragment | PacketFlags.LastFragment;
            requestPDU.DataRepresentation.CharacterFormat             = CharacterFormat.ASCII;
            requestPDU.DataRepresentation.ByteOrder                   = ByteOrder.LittleEndian;
            requestPDU.DataRepresentation.FloatingPointRepresentation = FloatingPointRepresentation.IEEE;
            requestPDU.OpNum          = OpNum;
            requestPDU.Data           = inputArgs.GetBytes();
            requestPDU.AllocationHint = (uint)requestPDU.Data.Length;
            byte[] input = requestPDU.GetBytes();
            status = NamedPipeShare.DeviceIOControl(pipeHandle, (uint)IoControlCode.FSCTL_PIPE_TRANSCEIVE, input, out output, maxTransmitFragmentSize);
            if (status != NTStatus.STATUS_SUCCESS)
            {
                return(status);
            }
            ResponsePDU responsePDU = RPCPDU.GetPDU(output, 0) as ResponsePDU;

            if (responsePDU == null)
            {
                status = NTStatus.STATUS_NOT_SUPPORTED;
                return(status);
            }

            byte[] responseData = responsePDU.Data;
            while ((responsePDU.Flags & PacketFlags.LastFragment) == 0)
            {
                status = NamedPipeShare.ReadFile(out output, pipeHandle, 0, maxTransmitFragmentSize);
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(status);
                }
                responsePDU = RPCPDU.GetPDU(output, 0) as ResponsePDU;
                if (responsePDU == null)
                {
                    status = NTStatus.STATUS_NOT_SUPPORTED;
                    return(status);
                }
                responseData = ByteUtils.Concatenate(responseData, responsePDU.Data);
            }
            outputData = (O)Activator.CreateInstance(typeof(O), new object[] { responseData });
            return(NTStatus.STATUS_SUCCESS);
        }