public void Pack(MemoryStream stream) { LittleEndianUtilities.WriteUShort(stream, HostNamePosition); LittleEndianUtilities.WriteUShort(stream, HostNameLength); LittleEndianUtilities.WriteUShort(stream, UserNamePosition); LittleEndianUtilities.WriteUShort(stream, UserNameLength); LittleEndianUtilities.WriteUShort(stream, PasswordPosition); LittleEndianUtilities.WriteUShort(stream, PasswordLength); LittleEndianUtilities.WriteUShort(stream, AppNamePosition); LittleEndianUtilities.WriteUShort(stream, AppNameLength); LittleEndianUtilities.WriteUShort(stream, ServerNamePosition); LittleEndianUtilities.WriteUShort(stream, ServerNameLength); LittleEndianUtilities.WriteUShort(stream, 0); // Extension unsupported LittleEndianUtilities.WriteUShort(stream, 0); // Extension unsupported LittleEndianUtilities.WriteUShort(stream, CltIntNamePosition); LittleEndianUtilities.WriteUShort(stream, CltIntNameLength); LittleEndianUtilities.WriteUShort(stream, LanguagePosition); LittleEndianUtilities.WriteUShort(stream, LanguageLength); LittleEndianUtilities.WriteUShort(stream, DatabasePosition); LittleEndianUtilities.WriteUShort(stream, DatabaseLength); stream.Write(ClientID, 0, 6); LittleEndianUtilities.WriteUShort(stream, SSPIPosition); LittleEndianUtilities.WriteUShort(stream, SSPILength); LittleEndianUtilities.WriteUShort(stream, AtchDBFilePosition); LittleEndianUtilities.WriteUShort(stream, AtchDBFileLength); LittleEndianUtilities.WriteUShort(stream, ChangePasswordPosition); LittleEndianUtilities.WriteUShort(stream, ChangePasswordLength); LittleEndianUtilities.WriteUInt(stream, 0); // Long SSPI not supported }
public void WriteUIntToMemoryStream() { var stream = new MemoryStream(); LittleEndianUtilities.WriteUInt(stream, 0x01234567); CollectionAssert.AreEqual(new byte[] { 0x67, 0x45, 0x23, 0x01 }, stream.ToArray()); }
/// <summary> /// Used to pack IPackageable to a stream. /// </summary> /// <param name="stream">MemoryStream in which IPackageable is packet into.</param> public void Pack(MemoryStream stream) { LittleEndianUtilities.WriteUInt(stream, this.Length); LittleEndianUtilities.WriteUInt(stream, this.TDSVersion); LittleEndianUtilities.WriteUInt(stream, this.PacketSize); LittleEndianUtilities.WriteUInt(stream, this.ClientProgVer); LittleEndianUtilities.WriteUInt(stream, this.ClientPID); LittleEndianUtilities.WriteUInt(stream, this.ConnectionID); this.OptionFlags1.Pack(stream); this.OptionFlags2.Pack(stream); this.TypeFlags.Pack(stream); this.OptionFlags3.Pack(stream); LittleEndianUtilities.WriteUInt(stream, this.ClientTimeZone); LittleEndianUtilities.WriteUInt(stream, this.ClientLCID); TDSLogin7OptionFactory.WriteOptionsToStream(stream, this.Options, this.ClientID); }
public void Pack(MemoryStream stream) { LittleEndianUtilities.WriteUInt(stream, Length); LittleEndianUtilities.WriteUInt(stream, 1946157060); // 7.4 TDS Version LittleEndianUtilities.WriteUInt(stream, 4096); // PacketSize LittleEndianUtilities.WriteUInt(stream, 117440512); // ClientProgramVersion LittleEndianUtilities.WriteUInt(stream, (uint)Process.GetCurrentProcess().Id); // Client Process ID LittleEndianUtilities.WriteUInt(stream, 0); // Connection ID OptionFlags1.Pack(stream); OptionFlags2.Pack(stream); TypeFlags.Pack(stream); OptionFlags3.Pack(stream); LittleEndianUtilities.WriteUInt(stream, 480); // Client time zone LittleEndianUtilities.WriteUInt(stream, 1033); // Client LCID OffsetLength.Pack(stream); stream.Write(Data, 0, Data.Length); // Extensions extensions not supported }
/// <summary> /// Writes TDS Login7 options to a stream /// </summary> /// <param name="stream">MemoryStream to write to</param> /// <param name="options">Options to write to the stream</param> /// <param name="clientID">ClientID to write to the stream</param> public static void WriteOptionsToStream(MemoryStream stream, List <TDSLogin7Option> options, byte[] clientID) { ushort currentPos = 94; foreach (var option in OptionOrder) { if (option != "ClientID") { LittleEndianUtilities.WriteUShort(stream, currentPos); var tmp = options.Where(o => o.Name == option); if (tmp.Any()) { var opt = tmp.First(); LittleEndianUtilities.WriteUShort(stream, opt.Length); opt.Position = currentPos; currentPos += opt.TrueLength; } else { LittleEndianUtilities.WriteUShort(stream, 0); } } else { stream.Write(clientID, 0, 6); } } // Ignore LongSSPI, not supported LittleEndianUtilities.WriteUInt(stream, 0); options = options.OrderBy(opt => opt.Position).ToList(); foreach (var option in options) { option.Pack(stream); } }
/// <summary> /// Used to pack IPackageable to a stream. /// </summary> /// <param name="stream">MemoryStream in which IPackageable is packet into.</param> public void Pack(MemoryStream stream) { stream.Write(this.TraceID, 0, this.TraceID.Length); stream.Write(this.ActivityID, 0, this.ActivityID.Length); LittleEndianUtilities.WriteUInt(stream, this.ActivitySequence); }