SMB2: Improved LockRequest implementation

This commit is contained in:
Tal Aloni 2017-08-31 13:59:51 +03:00
parent 4e4a416fd5
commit f96e6fe404

View file

@ -18,7 +18,7 @@ namespace SMBLibrary.SMB2
public const int DeclaredSize = 48;
private ushort StructureSize;
public ushort LockCount;
// ushort LockCount;
public byte LSN; // 4 bits
public uint LockSequenceIndex; // 28 bits
public FileID FileId;
@ -32,18 +32,18 @@ namespace SMBLibrary.SMB2
public LockRequest(byte[] buffer, int offset) : base(buffer, offset)
{
StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
LockCount = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
ushort lockCount = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
uint temp = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
LSN = (byte)(temp >> 28);
LockSequenceIndex = (temp & 0x0FFFFFFF);
FileId = new FileID(buffer, offset + SMB2Header.Length + 8);
Locks = LockElement.ReadLockList(buffer, offset + SMB2Header.Length + 24, (int)LockCount);
Locks = LockElement.ReadLockList(buffer, offset + SMB2Header.Length + 24, (int)lockCount);
}
public override void WriteCommandBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
LittleEndianWriter.WriteUInt16(buffer, offset + 2, LockCount);
LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Locks.Count);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)(LSN & 0x0F) << 28 | (uint)(LockSequenceIndex & 0x0FFFFFFF));
FileId.WriteBytes(buffer, offset + 8);
LockElement.WriteLockList(buffer, offset + 24, Locks);