diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeName.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeName.cs new file mode 100644 index 0000000..94efe22 --- /dev/null +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeName.cs @@ -0,0 +1,47 @@ +/* Copyright (C) 2017 Tal Aloni . All rights reserved. + * + * You can redistribute this program and/or modify it under the terms of + * the GNU Lesser Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + */ +using System; +using System.Collections.Generic; +using System.Text; +using Utilities; + +namespace SMBLibrary.SMB1 +{ + /// + /// [MS-CIFS] 2.2.1.2.1 - SMB_GEA + /// + public class ExtendedAttributeName + { + private byte AttributeNameLengthInBytes; + public string AttributeName; // ANSI, AttributeNameLengthInBytes + 1 byte null termination + + public ExtendedAttributeName() + { + } + + public ExtendedAttributeName(byte[] buffer, int offset) + { + AttributeNameLengthInBytes = ByteReader.ReadByte(buffer, offset + 0); + AttributeName = ByteReader.ReadAnsiString(buffer, offset + 1, AttributeNameLengthInBytes); + } + + public void WriteBytes(byte[] buffer, int offset) + { + AttributeNameLengthInBytes = (byte)AttributeName.Length; + ByteWriter.WriteByte(buffer, offset + 0, AttributeNameLengthInBytes); + ByteWriter.WriteAnsiString(buffer, offset + 1, AttributeName, AttributeName.Length); + } + + public int Length + { + get + { + return 1 + AttributeName.Length + 1; + } + } + } +} diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeNameList.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeNameList.cs new file mode 100644 index 0000000..47424c7 --- /dev/null +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/ExtendedAttributeNameList.cs @@ -0,0 +1,67 @@ +/* Copyright (C) 2017 Tal Aloni . All rights reserved. + * + * You can redistribute this program and/or modify it under the terms of + * the GNU Lesser Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + */ +using System; +using System.Collections.Generic; +using System.Text; +using Utilities; + +namespace SMBLibrary.SMB1 +{ + /// + /// [MS-CIFS] 2.2.1.2.1.1 - SMB_GEA_LIST + /// + public class ExtendedAttributeNameList : List + { + public ExtendedAttributeNameList() + { + } + + public ExtendedAttributeNameList(byte[] buffer, int offset) + { + // [MS-CIFS] length MUST contain the total size of the GEAList field, plus the size of the SizeOfListInBytes field + int length = (int)LittleEndianConverter.ToUInt32(buffer, offset + 0); + int position = offset + 4; + int eof = offset + length; + while (position < eof) + { + ExtendedAttributeName attribute = new ExtendedAttributeName(buffer, position); + this.Add(attribute); + position += attribute.Length; + } + } + + public byte[] GetBytes() + { + byte[] buffer = new byte[this.Length]; + WriteBytes(buffer, 0); + return buffer; + } + + public void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)Length); + foreach (ExtendedAttributeName entry in this) + { + entry.WriteBytes(buffer, offset); + offset += entry.Length; + } + } + + public int Length + { + get + { + int length = 4; + foreach (ExtendedAttributeName entry in this) + { + length += entry.Length; + } + return length; + } + } + } +} diff --git a/SMBLibrary/SMBLibrary.csproj b/SMBLibrary/SMBLibrary.csproj index e782437..0b39e34 100644 --- a/SMBLibrary/SMBLibrary.csproj +++ b/SMBLibrary/SMBLibrary.csproj @@ -328,6 +328,8 @@ + +