FullExtendedAttribute.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// [MS-CIFS] 2.2.1.2.2 - SMB_FEA
  15. /// </summary>
  16. public class FullExtendedAttribute
  17. {
  18. public ExtendedAttributeFlag ExtendedAttributeFlag;
  19. private byte AttributeNameLengthInBytes;
  20. private ushort AttributeValueLengthInBytes;
  21. public string AttributeName; // ANSI, AttributeNameLengthInBytes + 1 byte null termination
  22. public string AttributeValue; // ANSI
  23. public FullExtendedAttribute()
  24. {
  25. }
  26. public FullExtendedAttribute(byte[] buffer, int offset)
  27. {
  28. ExtendedAttributeFlag = (ExtendedAttributeFlag)ByteReader.ReadByte(buffer, offset);
  29. AttributeNameLengthInBytes = ByteReader.ReadByte(buffer, offset + 1);
  30. AttributeValueLengthInBytes = LittleEndianConverter.ToUInt16(buffer, offset + 2);
  31. AttributeName = ByteReader.ReadAnsiString(buffer, offset + 4, AttributeNameLengthInBytes);
  32. AttributeValue = ByteReader.ReadAnsiString(buffer, offset + 4 + AttributeNameLengthInBytes + 1, AttributeValueLengthInBytes);
  33. }
  34. public void WriteBytes(byte[] buffer, int offset)
  35. {
  36. AttributeNameLengthInBytes = (byte)AttributeName.Length;
  37. AttributeValueLengthInBytes = (ushort)AttributeValue.Length;
  38. ByteWriter.WriteByte(buffer, offset, (byte)ExtendedAttributeFlag);
  39. ByteWriter.WriteByte(buffer, offset + 1, AttributeNameLengthInBytes);
  40. LittleEndianWriter.WriteUInt16(buffer, offset + 2, AttributeValueLengthInBytes);
  41. ByteWriter.WriteAnsiString(buffer, offset + 4, AttributeName, AttributeName.Length);
  42. ByteWriter.WriteAnsiString(buffer, offset + 4 + AttributeNameLengthInBytes + 1, AttributeValue, AttributeValue.Length);
  43. }
  44. public int Length
  45. {
  46. get
  47. {
  48. return 4 + AttributeName.Length + 1 + AttributeValue.Length;
  49. }
  50. }
  51. }
  52. }