public override byte[] GetBytes(bool isUnicode) { ushort securityBlobLength = (ushort)SecurityBlob.Length; this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, (ushort)Action); LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, securityBlobLength); int padding = 0; if (isUnicode) { // wordCount is 1 byte padding = (1 + securityBlobLength) % 2; this.SMBData = new byte[SecurityBlob.Length + padding + NativeOS.Length * 2 + NativeLanMan.Length * 2 + 4]; } else { this.SMBData = new byte[SecurityBlob.Length + NativeOS.Length + NativeLanMan.Length + 2]; } int offset = 0; ByteWriter.WriteBytes(this.SMBData, ref offset, SecurityBlob); offset += padding; SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS); SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan); return(base.GetBytes(isUnicode)); }
public override byte[] GetBytes(bool isUnicode) { this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)SearchAttributes); if (isUnicode) { int padding = 1; this.SMBData = new byte[2 + OldFileName.Length * 2 + NewFileName.Length * 2 + 4 + padding]; } else { this.SMBData = new byte[2 + OldFileName.Length + NewFileName.Length + 2]; } int dataOffset = 0; ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat1); SMBHelper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, OldFileName); ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat2); if (isUnicode) { dataOffset++; // padding } SMBHelper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, NewFileName); return(base.GetBytes(isUnicode)); }
public override byte[] GetBytes(bool isUnicode) { this.SMBParameters = new byte[ParametersLength]; int parametersOffset = 4; LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)OptionalSupport); MaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset); GuestMaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset); // Should be written as OEM string but it doesn't really matter string serviceString = TreeConnectHelper.GetServiceString(Service); if (isUnicode) { this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length * 2 + 3]; } else { this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length + 2]; } int offset = 0; ByteWriter.WriteNullTerminatedAnsiString(this.SMBData, ref offset, serviceString); SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeFileSystem); return(base.GetBytes(isUnicode)); }
public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode) { uint fileNameLength = (uint)(isUnicode ? FileName.Length * 2 : FileName.Length); LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset); LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex); LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength); SMBHelper.WriteSMBString(buffer, ref offset, isUnicode, FileName); }
public override byte[] GetParameters(bool isUnicode) { int length = 4; length += isUnicode ? DirectoryName.Length * 2 + 2 : DirectoryName.Length + 1 + 1; byte[] parameters = new byte[length]; LittleEndianWriter.WriteUInt32(parameters, 0, Reserved); SMBHelper.WriteSMBString(parameters, 4, isUnicode, DirectoryName); return(parameters); }
public override byte[] GetBytes(bool isUnicode) { byte charCount = (byte)VolumeLabel.Length; int length = GetLength(isUnicode); byte[] buffer = new byte[length]; LittleEndianWriter.WriteUInt32(buffer, 0, VolumeSerialNumber); ByteWriter.WriteByte(buffer, 4, charCount); SMBHelper.WriteSMBString(buffer, 5, isUnicode, VolumeLabel); return(buffer); }
public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode) { uint fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length); LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset); LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex); SMBHelper.WriteFileTime(buffer, ref offset, CreationTime); SMBHelper.WriteFileTime(buffer, ref offset, LastAccessTime); SMBHelper.WriteFileTime(buffer, ref offset, LastWriteTime); SMBHelper.WriteFileTime(buffer, ref offset, LastAttrChangeTime); LittleEndianWriter.WriteUInt64(buffer, ref offset, EndOfFile); LittleEndianWriter.WriteUInt64(buffer, ref offset, AllocationSize); LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)ExtFileAttributes); LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength); SMBHelper.WriteSMBString(buffer, ref offset, isUnicode, FileName); }
public override byte[] GetBytes(bool isUnicode) { int length = 1; if (isUnicode) { length += DirectoryName.Length * 2 + 2; } else { length += DirectoryName.Length + 1; } this.SMBData = new byte[length]; ByteWriter.WriteByte(this.SMBData, 0, BufferFormat); SMBHelper.WriteSMBString(this.SMBData, 1, isUnicode, DirectoryName); return(base.GetBytes(isUnicode)); }
public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode) { byte fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length); if (ReturnResumeKeys) { LittleEndianWriter.WriteUInt32(buffer, ref offset, ResumeKey); } SMBHelper.WriteSMBDateTime(buffer, ref offset, CreationDateTime); SMBHelper.WriteSMBDateTime(buffer, ref offset, LastAccessDateTime); SMBHelper.WriteSMBDateTime(buffer, ref offset, LastWriteDateTime); LittleEndianWriter.WriteUInt32(buffer, ref offset, FileDataSize); LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationSize); LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Attributes); ByteWriter.WriteByte(buffer, ref offset, fileNameLength); SMBHelper.WriteSMBString(buffer, ref offset, isUnicode, FileName); }
public override byte[] GetParameters(bool isUnicode) { int length = 6; if (isUnicode) { length += FileName.Length * 2 + 2; } else { length += FileName.Length + 1; } byte[] parameters = new byte[length]; LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)InformationLevel); LittleEndianWriter.WriteUInt32(parameters, 2, Reserved); SMBHelper.WriteSMBString(parameters, 6, isUnicode, FileName); return(parameters); }
public override byte[] GetParameters(bool isUnicode) { int length = 8; if (isUnicode) { length += PipeName.Length * 2 + 2; } else { length += PipeName.Length + 1; } byte[] parameters = new byte[length]; LittleEndianWriter.WriteUInt16(parameters, 0, OutputBufferSize); LittleEndianWriter.WriteUInt16(parameters, 2, InputBufferSize); ByteWriter.WriteByte(parameters, 4, MaximumInstances); ByteWriter.WriteByte(parameters, 5, CurrentInstances); ByteWriter.WriteByte(parameters, 6, PipeNameLength); SMBHelper.WriteSMBString(parameters, 8, isUnicode, PipeName); return(parameters);; }
public override byte[] GetBytes(bool isUnicode) { this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, (ushort)Action); int offset = 0; if (isUnicode) { int padding = 1; // 1 byte padding for 2 byte alignment this.SMBData = new byte[padding + NativeOS.Length * 2 + NativeLanMan.Length * 2 + PrimaryDomain.Length * 2 + 6]; offset = padding; } else { this.SMBData = new byte[NativeOS.Length + NativeLanMan.Length + PrimaryDomain.Length + 3]; } SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS); SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan); SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain); return(base.GetBytes(isUnicode)); }
public override byte[] GetParameters(bool isUnicode) { int length = 12; if (isUnicode) { length += FileName.Length * 2 + 2; } else { length += FileName.Length + 1; } byte[] parameters = new byte[length]; LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)SearchAttributes); LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount); LittleEndianWriter.WriteUInt16(parameters, 4, (ushort)Flags); LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)InformationLevel); LittleEndianWriter.WriteUInt32(parameters, 8, (uint)SearchStorageType); SMBHelper.WriteSMBString(parameters, 12, isUnicode, FileName); return(parameters); }
public override byte[] GetBytes(bool isUnicode) { this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)FileAttributes); SMBHelper.WriteUTime(this.SMBParameters, 2, LastWriteTime); ByteWriter.WriteBytes(this.SMBParameters, 6, Reserved, 10); int length = 1; if (isUnicode) { length += FileName.Length * 2 + 2; } else { length += FileName.Length + 1; } this.SMBData = new byte[length]; ByteWriter.WriteByte(this.SMBData, 0, BufferFormat); SMBHelper.WriteSMBString(this.SMBData, 1, isUnicode, FileName); return(base.GetBytes(isUnicode)); }
public override byte[] GetBytes(bool isUnicode) { byte challengeLength = (byte)this.Challenge.Length; this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, DialectIndex); ByteWriter.WriteByte(this.SMBParameters, 2, (byte)SecurityMode); LittleEndianWriter.WriteUInt16(this.SMBParameters, 3, MaxMpxCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 5, MaxNumberVcs); LittleEndianWriter.WriteUInt32(this.SMBParameters, 7, MaxBufferSize); LittleEndianWriter.WriteUInt32(this.SMBParameters, 11, MaxRawSize); LittleEndianWriter.WriteUInt32(this.SMBParameters, 15, SessionKey); LittleEndianWriter.WriteUInt32(this.SMBParameters, 19, (uint)Capabilities); LittleEndianWriter.WriteInt64(this.SMBParameters, 23, SystemTime.ToFileTimeUtc()); LittleEndianWriter.WriteInt16(this.SMBParameters, 31, ServerTimeZone); ByteWriter.WriteByte(this.SMBParameters, 33, challengeLength); int padding = 0; if (isUnicode) { padding = Challenge.Length % 2; this.SMBData = new byte[Challenge.Length + padding + DomainName.Length * 2 + ServerName.Length * 2 + 4]; } else { this.SMBData = new byte[Challenge.Length + DomainName.Length + ServerName.Length + 2]; } int offset = 0; ByteWriter.WriteBytes(this.SMBData, ref offset, Challenge); offset += padding; SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, DomainName); SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, ServerName); return(base.GetBytes(isUnicode)); }
public override byte[] GetBytes(bool isUnicode) { ushort passwordLength = (ushort)Password.Length; this.SMBParameters = new byte[ParametersLength]; int parametersOffset = 4; LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)Flags); LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, passwordLength); string serviceString = TreeConnectHelper.GetServiceString(Service); int dataLength = Password.Length + serviceString.Length; if (isUnicode) { int padding = (1 + passwordLength) % 2; dataLength += Path.Length * 2 + 2 + padding; } else { dataLength += Path.Length + 1; } this.SMBData = new byte[dataLength]; int dataOffset = 0; ByteWriter.WriteBytes(this.SMBData, ref dataOffset, Password); if (isUnicode) { // wordCount is 1 byte int padding = (1 + passwordLength) % 2; dataOffset += padding; } SMBHelper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, Path); ByteWriter.WriteNullTerminatedAnsiString(this.SMBData, ref dataOffset, serviceString); return(base.GetBytes(isUnicode)); }
public override byte[] GetParameters(bool isUnicode) { int length = 28; if (isUnicode) { length += FileName.Length * 2 + 2; } else { length += FileName.Length + 1; } byte[] parameters = new byte[length]; LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)Flags); AccessMode.WriteBytes(parameters, 2); LittleEndianWriter.WriteUInt16(parameters, 4, Reserved1); LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)FileAttributes); SMBHelper.WriteUTime(parameters, 8, CreationTime); OpenMode.WriteBytes(parameters, 12); LittleEndianWriter.WriteUInt32(parameters, 14, AllocationSize); ByteWriter.WriteBytes(parameters, 18, Reserved, 10); SMBHelper.WriteSMBString(parameters, 28, isUnicode, FileName); return parameters; }
public override byte[] GetBytes(bool isUnicode) { byte SetupCount = (byte)(Setup.Length / 2); ushort ParameterCount = (ushort)TransParameters.Length; ushort DataCount = (ushort)TransData.Length; // WordCount + ByteCount are additional 3 bytes ushort ParameterOffset = (ushort)(SMBHeader.Length + 3 + (FixedSMBParametersLength + Setup.Length)); if (this is Transaction2Request) { ParameterOffset += 1; } else { if (isUnicode) { ParameterOffset += (ushort)(Name.Length * 2 + 2); } else { ParameterOffset += (ushort)(Name.Length + 1); } } int padding1 = (4 - (ParameterOffset % 4)) % 4; ParameterOffset += (ushort)padding1; ushort DataOffset = (ushort)(ParameterOffset + ParameterCount); int padding2 = (4 - (DataOffset % 4)) % 4; DataOffset += (ushort)padding2; this.SMBParameters = new byte[FixedSMBParametersLength + Setup.Length]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, TotalParameterCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, TotalDataCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxParameterCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxDataCount); ByteWriter.WriteByte(this.SMBParameters, 8, MaxSetupCount); ByteWriter.WriteByte(this.SMBParameters, 9, Reserved1); LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, (ushort)Flags); LittleEndianWriter.WriteUInt32(this.SMBParameters, 12, Timeout); LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, Reserved2); LittleEndianWriter.WriteUInt16(this.SMBParameters, 18, ParameterCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 20, ParameterOffset); LittleEndianWriter.WriteUInt16(this.SMBParameters, 22, DataCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 24, DataOffset); ByteWriter.WriteByte(this.SMBParameters, 26, SetupCount); ByteWriter.WriteByte(this.SMBParameters, 27, Reserved3); ByteWriter.WriteBytes(this.SMBParameters, 28, Setup); int offset; if (this is Transaction2Request) { offset = 0; this.SMBData = new byte[1 + ParameterCount + DataCount + padding1 + padding2]; } else { if (isUnicode) { int namePadding = 1; offset = namePadding; this.SMBData = new byte[namePadding + Name.Length * 2 + 2 + ParameterCount + DataCount + padding1 + padding2]; } else { offset = 0; this.SMBData = new byte[Name.Length + 1 + ParameterCount + DataCount + padding1 + padding2]; } } SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, Name); ByteWriter.WriteBytes(this.SMBData, offset + padding1, TransParameters); ByteWriter.WriteBytes(this.SMBData, offset + padding1 + ParameterCount + padding2, TransData); return(base.GetBytes(isUnicode)); }