Corrected SMB_FEA / SMB_FEA_LIST implementation

This commit is contained in:
Tal Aloni 2017-02-07 13:55:56 +02:00
parent 9f79f939b6
commit dfb8822a4f
2 changed files with 23 additions and 18 deletions

View file

@ -12,34 +12,38 @@ using Utilities;
namespace SMBLibrary.SMB1
{
/// <summary>
/// SMB_FEA
/// [MS-CIFS] 2.2.1.2.2 - SMB_FEA
/// </summary>
public class FullExtendedAttribute
{
public ExtendedAttributeFlag ExtendedAttributeFlag;
//byte AttributeNameLengthInBytes;
//ushort AttributeValueLengthInBytes;
private byte AttributeNameLengthInBytes;
private ushort AttributeValueLengthInBytes;
public string AttributeName; // ANSI, AttributeNameLengthInBytes + 1 byte null termination
public string AttributeValue; // ANSI
public FullExtendedAttribute()
{
}
public FullExtendedAttribute(byte[] buffer, int offset)
{
ExtendedAttributeFlag = (ExtendedAttributeFlag)ByteReader.ReadByte(buffer, offset);
byte attributeNameLengthInBytes = ByteReader.ReadByte(buffer, offset + 1);
ushort attributeValueLengthInBytes = LittleEndianConverter.ToUInt16(buffer, offset + 2);
AttributeName = ByteReader.ReadAnsiString(buffer, offset + 4, attributeNameLengthInBytes);
AttributeValue = ByteReader.ReadAnsiString(buffer, offset + 4 + attributeNameLengthInBytes + 1, attributeValueLengthInBytes);
AttributeNameLengthInBytes = ByteReader.ReadByte(buffer, offset + 1);
AttributeValueLengthInBytes = LittleEndianConverter.ToUInt16(buffer, offset + 2);
AttributeName = ByteReader.ReadAnsiString(buffer, offset + 4, AttributeNameLengthInBytes);
AttributeValue = ByteReader.ReadAnsiString(buffer, offset + 4 + AttributeNameLengthInBytes + 1, AttributeValueLengthInBytes);
}
public void WriteBytes(byte[] buffer, int offset)
{
byte attributeNameLengthInBytes = (byte)AttributeName.Length;
ushort attributeValueLengthInBytes = (ushort)AttributeValue.Length;
AttributeNameLengthInBytes = (byte)AttributeName.Length;
AttributeValueLengthInBytes = (ushort)AttributeValue.Length;
ByteWriter.WriteByte(buffer, offset, (byte)ExtendedAttributeFlag);
ByteWriter.WriteByte(buffer, offset + 1, attributeNameLengthInBytes);
LittleEndianWriter.WriteUInt16(buffer, offset + 2, attributeValueLengthInBytes);
ByteWriter.WriteAnsiString(buffer, offset + 4, AttributeName, AttributeValue.Length);
ByteWriter.WriteAnsiString(buffer, offset + 4 + attributeNameLengthInBytes + 1, AttributeValue, AttributeValue.Length);
ByteWriter.WriteByte(buffer, offset + 1, AttributeNameLengthInBytes);
LittleEndianWriter.WriteUInt16(buffer, offset + 2, AttributeValueLengthInBytes);
ByteWriter.WriteAnsiString(buffer, offset + 4, AttributeName, AttributeName.Length);
ByteWriter.WriteAnsiString(buffer, offset + 4 + AttributeNameLengthInBytes + 1, AttributeValue, AttributeValue.Length);
}
public int Length

View file

@ -12,7 +12,7 @@ using Utilities;
namespace SMBLibrary.SMB1
{
/// <summary>
/// SMB_FEA_LIST
/// [MS-CIFS] 2.2.1.2.2.1 - SMB_FEA_LIST
/// </summary>
public class FullExtendedAttributeList : List<FullExtendedAttribute>
{
@ -26,14 +26,14 @@ namespace SMBLibrary.SMB1
public FullExtendedAttributeList(byte[] buffer, ref int offset) : this(buffer, offset)
{
// length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
int length = (int)LittleEndianConverter.ToUInt32(buffer, offset);
// [MS-CIFS] length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
int length = (int)LittleEndianConverter.ToUInt32(buffer, offset + 0);
offset += length;
}
public FullExtendedAttributeList(byte[] buffer, int offset)
{
// length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
// [MS-CIFS] length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
int length = (int)LittleEndianConverter.ToUInt32(buffer, offset);
int position = offset + 4;
int eof = offset + length;
@ -60,6 +60,7 @@ namespace SMBLibrary.SMB1
public void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)Length);
foreach (FullExtendedAttribute entry in this)
{
entry.WriteBytes(buffer, offset);
@ -71,7 +72,7 @@ namespace SMBLibrary.SMB1
{
get
{
int length = 0;
int length = 4;
foreach (FullExtendedAttribute entry in this)
{
length += entry.Length;