ExtendedAttributeNameList.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2017 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.1.1 - SMB_GEA_LIST
  15. /// </summary>
  16. public class ExtendedAttributeNameList : List<ExtendedAttributeName>
  17. {
  18. public ExtendedAttributeNameList()
  19. {
  20. }
  21. public ExtendedAttributeNameList(byte[] buffer, int offset)
  22. {
  23. // [MS-CIFS] length MUST contain the total size of the GEAList field, plus the size of the SizeOfListInBytes field
  24. int length = (int)LittleEndianConverter.ToUInt32(buffer, offset + 0);
  25. int position = offset + 4;
  26. int eof = offset + length;
  27. while (position < eof)
  28. {
  29. ExtendedAttributeName attribute = new ExtendedAttributeName(buffer, position);
  30. this.Add(attribute);
  31. position += attribute.Length;
  32. }
  33. }
  34. public byte[] GetBytes()
  35. {
  36. byte[] buffer = new byte[this.Length];
  37. WriteBytes(buffer, 0);
  38. return buffer;
  39. }
  40. public void WriteBytes(byte[] buffer, int offset)
  41. {
  42. LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)Length);
  43. foreach (ExtendedAttributeName entry in this)
  44. {
  45. entry.WriteBytes(buffer, offset);
  46. offset += entry.Length;
  47. }
  48. }
  49. public int Length
  50. {
  51. get
  52. {
  53. int length = 4;
  54. foreach (ExtendedAttributeName entry in this)
  55. {
  56. length += entry.Length;
  57. }
  58. return length;
  59. }
  60. }
  61. }
  62. }