public TreeConnectAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset)
        {
            int parametersOffset = 4;

            Flags = (TreeConnectFlags)LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);
            ushort passwordLength = LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);

            int dataOffset = 0;

            Password = ByteReader.ReadBytes(SMBData, ref dataOffset, passwordLength);
            if (isUnicode)
            {
                // wordCount is 1 byte
                int padding = (1 + passwordLength) % 2;
                dataOffset += padding;
            }
            Path = SMB1Helper.ReadSMBString(SMBData, ref dataOffset, isUnicode);
            // Should be read as OEM string but it doesn't really matter
            string serviceString = ByteReader.ReadNullTerminatedAnsiString(SMBData, ref dataOffset);

            Service = ServiceNameHelper.GetServiceName(serviceString);
        }
 /// <summary>
 /// Create tree connect request for client to access share of server. This command match all device type, and 
 /// must following the session setup. 
 /// </summary>
 /// <param name = "messageId">the id of message, used to identity the request and the server response. </param>
 /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param>
 /// <param name = "flags">
 /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. 
 /// </param>
 /// <param name = "flags2">
 /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate   
 /// various client and server capabilities. 
 /// </param>
 /// <param name = "path">the share name to treeconnect to </param>
 /// <param name = "services">
 /// The type of resource that the client intends to access. This field MUST be a null-terminated array of OEM  
 /// characters even if the client and server have negotiated to use Unicode strings. 
 /// </param>
 /// <param name = "treeConnectFlags">
 /// A 16-bit field used to modify the SMB_COM_TREE_CONNECT_ANDX request. 
 /// </param>
 /// <returns>a tree connect request packet. </returns>
 private SmbTreeConnectAndxRequestPacket CreateTreeConnectRequest(
     ushort messageId,
     ushort sessionUid,
     SmbHeader_Flags_Values flags,
     SmbHeader_Flags2_Values flags2,
     string path,
     string services,
     TreeConnectFlags treeConnectFlags)
 {
     return new SmbTreeConnectAndxRequestPacket(
         this.cifsClient.CreateTreeConnectAndxRequest(
         messageId, sessionUid, (SmbFlags)flags, (SmbFlags2)flags2,
         (TreeConnectAndxFlags)treeConnectFlags, path, services, new byte[1], // null-terminated.
         null));
 }
 /// <summary>
 /// Create tree connect request for client to access share of server. This command match all device type, and 
 /// must follow the session setup. 
 /// </summary>
 /// <param name="sessionUid">the valid session id, must be same as that of the response to the session setup request. </param>
 /// <param name="path">the share name to treeconnect to server </param>
 /// <param name="treeConnectFlags">the option to modify the SMB_COM_TREE_CONNECT_ANDX request.</param>
 /// <returns>a tree connect request packet. </returns>
 public virtual SmbTreeConnectAndxRequestPacket CreateTreeConnectRequest(
     ushort sessionUid,
     string path,
     TreeConnectFlags treeConnectFlags)
 {
     return CreateTreeConnectRequest(
         this.MessageId, sessionUid, this.capability.Flag,
         this.capability.Flags2, path, TreeConnectService, treeConnectFlags);
 }
        /// <summary>
        /// Create tree connect request for client to access share of server. This command match all device type, and 
        /// must follow the session setup. 
        /// </summary>
        /// <param name="sessionUid">the valid session id, must be same as that of the response to the session setup request. </param>
        /// <param name="path">the share name to treeconnect to server </param>
        /// <returns>a tree connect request packet. </returns>
        public virtual SmbTreeConnectAndxRequestPacket CreateTreeConnectRequest(
            ushort sessionUid,
            string path
            )
        {
            TreeConnectFlags treeConnectFlags = new TreeConnectFlags();
            if (Capability.IsSupportsExtendedSecurity)
            {
                treeConnectFlags =
                    TreeConnectFlags.TREE_CONNECT_ANDX_EXTENDED_RESPONSE
                    | TreeConnectFlags.TREE_CONNECT_ANDX_EXTENDED_SIGNATURES;
            }

            return CreateTreeConnectRequest(
                this.MessageId, sessionUid, this.capability.Flag,
                this.capability.Flags2, path, TreeConnectService, treeConnectFlags);
        }