Example #1
0
 public NtStatus SmbdWriteRegisteredBuffer(byte[] data, SmbdBufferDescriptorV1 bufferDescriptor)
 {
     return(smbdClient.WriteRegisteredBuffer(data, bufferDescriptor));
 }
        public void SMBDWrite(uint treeId, FILEID fileId, Channel_Values channel, byte[] buffer, uint offset, RDMAEndian endian)
        {
            NtStatus status;
            SmbdBufferDescriptorV1 descriptor;

            status = smbdClient.RegisterBuffer(
                (uint)buffer.Length,
                SmbdBufferReadWrite.RDMA_READ_PERMISSION_FOR_WRITE_FILE,
                endianMap[endian],
                out descriptor
                );

            if (status != NtStatus.STATUS_SUCCESS)
            {
                throw new InvalidOperationException("SMBD register buffer failed!");
            }

            status = smbdClient.WriteRegisteredBuffer(buffer, descriptor);
            if (status != NtStatus.STATUS_SUCCESS)
            {
                throw new InvalidOperationException("SMBD write buffer failed!");
            }

            byte[] channelInfo = TypeMarshal.ToBytes(descriptor);

            Packet_Header  packetHeader;
            WRITE_Response response;

            // Pack WRITE request manually since the DataOffset and RemainingBytes need to be fixed.
            var request = new Smb2WriteRequestPacket();

            request.Header.CreditCharge          = 0;
            request.Header.CreditRequestResponse = RequestAndConsumeCredit();
            request.Header.Flags     = signingRequired ? Packet_Header_Flags_Values.FLAGS_SIGNED : Packet_Header_Flags_Values.NONE;
            request.Header.MessageId = GetMessageId();
            request.Header.SessionId = sessionId;
            request.Header.TreeId    = treeId;
            request.Header.Command   = Smb2Command.WRITE;

            request.PayLoad.Offset                 = 0;
            request.PayLoad.FileId                 = fileId;
            request.PayLoad.Channel                = channel;
            request.PayLoad.Flags                  = WRITE_Request_Flags_Values.None;
            request.PayLoad.Length                 = 0;
            request.PayLoad.RemainingBytes         = (uint)buffer.Length;
            request.PayLoad.DataOffset             = 0;
            request.PayLoad.WriteChannelInfoLength = (ushort)channelInfo.Length;
            request.PayLoad.WriteChannelInfoOffset = request.BufferOffset;

            request.Buffer = channelInfo;

            SendPacket(request);

            status = (NtStatus)WriteResponse(messageId, out packetHeader, out response);

            UpdateCredit(packetHeader);

            if (status != NtStatus.STATUS_SUCCESS)
            {
                throw new InvalidOperationException("Write through SMBD failed!");
            }
        }