FullExtendedAttributeList.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.1 - SMB_FEA_LIST
  15. /// </summary>
  16. public class FullExtendedAttributeList : List<FullExtendedAttribute>
  17. {
  18. public FullExtendedAttributeList()
  19. {
  20. }
  21. public FullExtendedAttributeList(byte[] buffer) : this(buffer, 0)
  22. {
  23. }
  24. public FullExtendedAttributeList(byte[] buffer, ref int offset) : this(buffer, offset)
  25. {
  26. // [MS-CIFS] length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
  27. int length = (int)LittleEndianConverter.ToUInt32(buffer, offset + 0);
  28. offset += length;
  29. }
  30. public FullExtendedAttributeList(byte[] buffer, int offset)
  31. {
  32. // [MS-CIFS] length MUST contain the total size of the FEAList field, plus the size of the SizeOfListInBytes field
  33. int length = (int)LittleEndianConverter.ToUInt32(buffer, offset);
  34. int position = offset + 4;
  35. int eof = offset + length;
  36. while (position < eof)
  37. {
  38. FullExtendedAttribute attribute = new FullExtendedAttribute(buffer, position);
  39. this.Add(attribute);
  40. position += attribute.Length;
  41. }
  42. }
  43. public byte[] GetBytes()
  44. {
  45. byte[] buffer = new byte[this.Length];
  46. WriteBytes(buffer, 0);
  47. return buffer;
  48. }
  49. public void WriteBytes(byte[] buffer, ref int offset)
  50. {
  51. WriteBytes(buffer, offset);
  52. offset += this.Length;
  53. }
  54. public void WriteBytes(byte[] buffer, int offset)
  55. {
  56. LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)Length);
  57. foreach (FullExtendedAttribute entry in this)
  58. {
  59. entry.WriteBytes(buffer, offset);
  60. offset += entry.Length;
  61. }
  62. }
  63. public int Length
  64. {
  65. get
  66. {
  67. int length = 4;
  68. foreach (FullExtendedAttribute entry in this)
  69. {
  70. length += entry.Length;
  71. }
  72. return length;
  73. }
  74. }
  75. }
  76. }