public bool Unpack(MemoryStream stream) { HostNamePosition = LittleEndianUtilities.ReadUShort(stream); HostNameLength = LittleEndianUtilities.ReadUShort(stream); UserNamePosition = LittleEndianUtilities.ReadUShort(stream); UserNameLength = LittleEndianUtilities.ReadUShort(stream); PasswordPosition = LittleEndianUtilities.ReadUShort(stream); PasswordLength = LittleEndianUtilities.ReadUShort(stream); AppNamePosition = LittleEndianUtilities.ReadUShort(stream); AppNameLength = LittleEndianUtilities.ReadUShort(stream); ServerNamePosition = LittleEndianUtilities.ReadUShort(stream); ServerNameLength = LittleEndianUtilities.ReadUShort(stream); ExtensionPosition = LittleEndianUtilities.ReadUShort(stream); ExtensionLength = LittleEndianUtilities.ReadUShort(stream); CltIntNamePosition = LittleEndianUtilities.ReadUShort(stream); CltIntNameLength = LittleEndianUtilities.ReadUShort(stream); LanguagePosition = LittleEndianUtilities.ReadUShort(stream); LanguageLength = LittleEndianUtilities.ReadUShort(stream); DatabasePosition = LittleEndianUtilities.ReadUShort(stream); DatabaseLength = LittleEndianUtilities.ReadUShort(stream); stream.Read(ClientID, 0, 6); SSPIPosition = LittleEndianUtilities.ReadUShort(stream); SSPILength = LittleEndianUtilities.ReadUShort(stream); AtchDBFilePosition = LittleEndianUtilities.ReadUShort(stream); AtchDBFileLength = LittleEndianUtilities.ReadUShort(stream); ChangePasswordPosition = LittleEndianUtilities.ReadUShort(stream); ChangePasswordLength = LittleEndianUtilities.ReadUShort(stream); SSPILengthLong = LittleEndianUtilities.ReadUInt(stream); return(true); }
/// <summary> /// Used to unpack IPackageable from a stream. /// </summary> /// <param name="stream">MemoryStream from which to unpack IPackageable.</param> /// <returns>Returns true if successful.</returns> public override bool Unpack(MemoryStream stream) { LittleEndianUtilities.ReadUShort(stream); this.Number = (int)LittleEndianUtilities.ReadUInt(stream); this.State = Convert.ToByte(stream.ReadByte()); this.Class = Convert.ToByte(stream.ReadByte()); int length = LittleEndianUtilities.ReadUShort(stream) * 2; var buffer = new byte[length]; stream.Read(buffer, 0, length); this.MsgText = Encoding.Unicode.GetString(buffer); length = stream.ReadByte() * 2; buffer = new byte[length]; stream.Read(buffer, 0, length); this.ServerName = Encoding.Unicode.GetString(buffer); length = stream.ReadByte() * 2; buffer = new byte[length]; stream.Read(buffer, 0, length); this.ProcName = Encoding.Unicode.GetString(buffer); this.LineNumber = LittleEndianUtilities.ReadUInt(stream); return(true); }
/// <summary> /// Used to unpack IPackageable from a stream. /// </summary> /// <param name="stream">MemoryStream from which to unpack IPackageable.</param> /// <returns>Returns true if successful.</returns> public bool Unpack(MemoryStream stream) { stream.Read(this.TraceID, 0, 16); stream.Read(this.ActivityID, 0, 16); this.ActivitySequence = LittleEndianUtilities.ReadUInt(stream); return(true); }
public void ReadUIntFromMemoryStream() { var stream = new MemoryStream(); stream.Write(new byte[] { 0x01, 0x23, 0x45, 0x67 }); stream.Seek(0, SeekOrigin.Begin); var res = LittleEndianUtilities.ReadUInt(stream); Assert.AreEqual((uint)0x67452301, res); }
public bool Unpack(MemoryStream stream) { LittleEndianUtilities.ReadUInt(stream); TDSVersion = LittleEndianUtilities.ReadUInt(stream); PacketSize = LittleEndianUtilities.ReadUInt(stream); ClientProgVer = LittleEndianUtilities.ReadUInt(stream); ClientPID = LittleEndianUtilities.ReadUInt(stream); ConnectionID = LittleEndianUtilities.ReadUInt(stream); OptionFlags1.Unpack(stream); OptionFlags2.Unpack(stream); TypeFlags.Unpack(stream); OptionFlags3.Unpack(stream); ClientTimeZone = Convert.ToInt32(LittleEndianUtilities.ReadUInt(stream)); ClientLCID = LittleEndianUtilities.ReadUInt(stream); OffsetLength.Unpack(stream); stream.Read(Data, 0, (int)OffsetLength.TotalLength()); // Extensions not supported return(true); }
/// <summary> /// Used to unpack IPackageable from a stream. /// </summary> /// <param name="stream">MemoryStream from which to unpack IPackageable.</param> /// <returns>Returns true if successful.</returns> public bool Unpack(MemoryStream stream) { LittleEndianUtilities.ReadUInt(stream); this.TDSVersion = LittleEndianUtilities.ReadUInt(stream); this.PacketSize = LittleEndianUtilities.ReadUInt(stream); this.ClientProgVer = LittleEndianUtilities.ReadUInt(stream); this.ClientPID = LittleEndianUtilities.ReadUInt(stream); this.ConnectionID = LittleEndianUtilities.ReadUInt(stream); this.OptionFlags1.Unpack(stream); this.OptionFlags2.Unpack(stream); this.TypeFlags.Unpack(stream); this.OptionFlags3.Unpack(stream); this.ClientTimeZone = Convert.ToUInt32(LittleEndianUtilities.ReadUInt(stream)); this.ClientLCID = LittleEndianUtilities.ReadUInt(stream); var result = TDSLogin7OptionFactory.ReadOptionsFromStream(stream); this.ClientID = result.Item2; this.Options = result.Item1; return(true); }
/// <summary> /// Reads TDS Login7 options from a stream /// </summary> /// <param name="stream">Stream containing the Login7 packet</param> /// <returns>ClientID, TDS Login7 options pair</returns> public static Tuple <List <TDSLogin7Option>, byte[]> ReadOptionsFromStream(MemoryStream stream) { var options = new List <TDSLogin7Option>(); var clientID = new byte[6]; foreach (var option in OptionOrder) { ushort position = 0; ushort length = 0; switch (option) { case "HostName": case "UserName": case "AppName": case "ServerName": case "CltIntName": case "Language": case "Database": { position = LittleEndianUtilities.ReadUShort(stream); length = LittleEndianUtilities.ReadUShort(stream); if (length != 0) { options.Add(new TDSLogin7TextOption(option, position, length)); } break; } case "ClientID": { stream.Read(clientID, 0, 6); break; } case "Password": case "ChangePassword": { position = LittleEndianUtilities.ReadUShort(stream); length = LittleEndianUtilities.ReadUShort(stream); if (length != 0) { options.Add(new TDSLogin7PasswordOption(option, position, length)); } break; } default: { position = LittleEndianUtilities.ReadUShort(stream); length = LittleEndianUtilities.ReadUShort(stream); if (length != 0) { throw new NotSupportedException(); } break; } } } // Ignore LongSSPI, not supported LittleEndianUtilities.ReadUInt(stream); options = options.OrderBy(opt => opt.Position).ToList(); foreach (var option in options) { option.Unpack(stream); } return(new Tuple <List <TDSLogin7Option>, byte[]>(options, clientID)); }