コード例 #1
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbIoctlRequestPacket(SmbIoctlRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.Category = packet.SmbParameters.Category;
            this.smbParameters.Function = packet.SmbParameters.Function;
            this.smbParameters.TotalParameterCount = packet.SmbParameters.TotalParameterCount;
            this.smbParameters.TotalDataCount = packet.SmbParameters.TotalDataCount;
            this.smbParameters.MaxParameterCount = packet.SmbParameters.MaxParameterCount;
            this.smbParameters.MaxDataCount = packet.SmbParameters.MaxDataCount;
            this.smbParameters.Timeout = packet.SmbParameters.Timeout;
            this.smbParameters.Reserved = packet.SmbParameters.Reserved;
            this.smbParameters.ParameterCount = packet.SmbParameters.ParameterCount;
            this.smbParameters.ParameterOffset = packet.SmbParameters.ParameterOffset;
            this.smbParameters.DataCount = packet.SmbParameters.DataCount;
            this.smbParameters.DataOffset = packet.SmbParameters.DataOffset;
            this.smbData.ByteCount = packet.SmbData.ByteCount;

            if (packet.smbData.Pad1 != null)
            {
                this.smbData.Pad1 = new byte[packet.smbData.Pad1.Length];
                Array.Copy(packet.smbData.Pad1, this.smbData.Pad1, packet.smbData.Pad1.Length);
            }
            if (packet.smbData.Parameters != null)
            {
                this.smbData.Parameters = new byte[packet.smbData.Parameters.Length];
                Array.Copy(packet.smbData.Parameters, this.smbData.Parameters, packet.smbData.Parameters.Length);
            }
            if (packet.smbData.Pad2 != null)
            {
                this.smbData.Pad2 = new byte[packet.smbData.Pad2.Length];
                Array.Copy(packet.smbData.Pad2, this.smbData.Pad2, packet.smbData.Pad2.Length);
            }
            if (packet.smbData.Data != null)
            {
                this.smbData.Data = new byte[packet.smbData.Data.Length];
                Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length);
            }
        }
コード例 #2
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbIoctlRequestPacket(SmbIoctlRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount           = packet.SmbParameters.WordCount;
            this.smbParameters.FID                 = packet.SmbParameters.FID;
            this.smbParameters.Category            = packet.SmbParameters.Category;
            this.smbParameters.Function            = packet.SmbParameters.Function;
            this.smbParameters.TotalParameterCount = packet.SmbParameters.TotalParameterCount;
            this.smbParameters.TotalDataCount      = packet.SmbParameters.TotalDataCount;
            this.smbParameters.MaxParameterCount   = packet.SmbParameters.MaxParameterCount;
            this.smbParameters.MaxDataCount        = packet.SmbParameters.MaxDataCount;
            this.smbParameters.Timeout             = packet.SmbParameters.Timeout;
            this.smbParameters.Reserved            = packet.SmbParameters.Reserved;
            this.smbParameters.ParameterCount      = packet.SmbParameters.ParameterCount;
            this.smbParameters.ParameterOffset     = packet.SmbParameters.ParameterOffset;
            this.smbParameters.DataCount           = packet.SmbParameters.DataCount;
            this.smbParameters.DataOffset          = packet.SmbParameters.DataOffset;
            this.smbData.ByteCount                 = packet.SmbData.ByteCount;

            if (packet.smbData.Pad1 != null)
            {
                this.smbData.Pad1 = new byte[packet.smbData.Pad1.Length];
                Array.Copy(packet.smbData.Pad1, this.smbData.Pad1, packet.smbData.Pad1.Length);
            }
            if (packet.smbData.Parameters != null)
            {
                this.smbData.Parameters = new byte[packet.smbData.Parameters.Length];
                Array.Copy(packet.smbData.Parameters, this.smbData.Parameters, packet.smbData.Parameters.Length);
            }
            if (packet.smbData.Pad2 != null)
            {
                this.smbData.Pad2 = new byte[packet.smbData.Pad2.Length];
                Array.Copy(packet.smbData.Pad2, this.smbData.Pad2, packet.smbData.Pad2.Length);
            }
            if (packet.smbData.Data != null)
            {
                this.smbData.Data = new byte[packet.smbData.Data.Length];
                Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length);
            }
        }
コード例 #3
0
        /// <summary>
        /// to create an Ioctl request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="fid">The Fid of the device or file to which the IOCTL is to be sent.</param>
        /// <param name="category">The implementation dependent device category for the request.</param>
        /// <param name="function">The implementation dependent device function for the request.</param>
        /// <param name="maxParameterCount">The maximum number of SMB_Data.Parameters bytes that the client accepts in
        /// the IOCTL response. The server MUST NOT return more than this number of bytes in the SMB_Data.Parameter
        /// field of the response.</param>
        /// <param name="maxDataCount">The maximum number of SMB_Data.Data bytes that the client accepts in the IOCTL
        /// response. The server MUST NOT return more than this number of bytes in the SMB_Data.Data field.</param>
        /// <param name="timeout"> the maximum number of milliseconds the server SHOULD wait for completion of the 
        /// transaction before generating a timeout and returning a response to the client. The client SHOULD set 
        /// this to 0 to indicate that no time-out is expected.</param>
        /// <param name="parameters">IOCTL parameter bytes. The contents are implementation dependent.</param>
        /// <param name="data">Transaction data bytes. The contents are implementation dependent.</param>
        /// <returns>a Ioctl request packet</returns>
        public SmbIoctlRequestPacket CreateIoctlRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            IoctlCategory category,
            IoctlFunction function,
            ushort maxParameterCount,
            ushort maxDataCount,
            uint timeout,
            byte[] parameters,
            byte[] data)
        {
            if (parameters == null)
            {
                parameters = new byte[0];
            }
            if (data == null)
            {
                data = new byte[0];
            }

            SmbIoctlRequestPacket packet = new SmbIoctlRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_IOCTL,
                messageId, uid, treeId, flags, flags2);

            SMB_COM_IOCTL_Request_SMB_Parameters smbParameters = new SMB_COM_IOCTL_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.Category = category;
            smbParameters.Function = function;
            smbParameters.MaxParameterCount = maxParameterCount;
            smbParameters.TotalParameterCount = (ushort)parameters.Length;
            smbParameters.ParameterCount = (ushort)parameters.Length;
            smbParameters.ParameterOffset = 0;
            smbParameters.MaxDataCount = maxDataCount;
            smbParameters.TotalDataCount = (ushort)data.Length;
            smbParameters.DataCount = (ushort)data.Length;
            smbParameters.DataOffset = 0;
            smbParameters.Timeout = timeout;
            smbParameters.Reserved = 0;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_IOCTL_Request_SMB_Data smbData = new SMB_COM_IOCTL_Request_SMB_Data();

            // The size of the preceding SmbParameters part plus Header part is an odd number for all cifs messages
            // If the format is Unicode, needs to add one 16 bits align pad
            if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
            {
                // pad 1 byte for 16-bits align:
                smbData.Pad1 = new byte[1];
            }
            else
            {
                smbData.Pad1 = new byte[0];
            }
            smbData.Parameters = parameters;
            // pad 1 byte for 16-bits align if need:
            smbData.Pad2 = new byte[smbData.Parameters.Length % twoBytesAlign];
            smbData.Data = data;
            smbData.ByteCount = (ushort)(smbData.Pad1.Length + smbData.Parameters.Length
                + smbData.Pad2.Length + smbData.Data.Length);

            smbParameters.ParameterOffset = (ushort)(Marshal.SizeOf(packet.SmbHeader) + Marshal.SizeOf(smbParameters)
                + Marshal.SizeOf(smbData.ByteCount) + smbData.Pad1.Length);
            smbParameters.DataOffset = (ushort)(smbParameters.ParameterOffset + smbData.Parameters.Length
                + smbData.Pad2.Length);

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
コード例 #4
0
        public SmbIoctlResponsePacket CreateIoctlResponse(
            CifsServerPerConnection connection,
            SmbIoctlRequestPacket request,
            byte[] parameters,
            byte[] data)
        {
            parameters = parameters ?? new byte[0];
            data = data ?? new byte[0];

            SmbIoctlResponsePacket response = new SmbIoctlResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            int pad1Offset = response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                    + Marshal.SizeOf(response.SmbData.ByteCount);
            SMB_COM_IOCTL_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.TotalParameterCount = (ushort)parameters.Length;
            smbParameters.ParameterCount = (ushort)parameters.Length;
            smbParameters.TotalDataCount = (ushort)data.Length;
            smbParameters.DataCount = (ushort)data.Length;
            smbParameters.ParameterOffset = (ushort)((pad1Offset + 3) & ~3);
            smbParameters.DataOffset = (ushort)((smbParameters.ParameterOffset + parameters.Length + 3) & ~3);
            smbParameters.DataDisplacement = 0x0000;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            SMB_COM_IOCTL_Response_SMB_Data smbData = response.SmbData;
            smbData.Pad1 = new byte[response.SmbParameters.ParameterOffset - pad1Offset];
            smbData.Parameters = parameters;
            smbData.Pad2 = new byte[response.SmbParameters.DataOffset - response.SmbParameters.ParameterOffset
                - parameters.Length];
            smbData.Data = data;
            smbData.ByteCount = (ushort)(response.SmbParameters.DataOffset - pad1Offset + data.Length);
            response.SmbData = smbData;

            return response;
        }