FullExtendedAttributeList.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /// 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. // 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);
  28. offset += length;
  29. }
  30. public FullExtendedAttributeList(byte[] buffer, int offset)
  31. {
  32. // 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. foreach (FullExtendedAttribute entry in this)
  57. {
  58. entry.WriteBytes(buffer, offset);
  59. offset += entry.Length;
  60. }
  61. }
  62. public int Length
  63. {
  64. get
  65. {
  66. int length = 0;
  67. foreach (FullExtendedAttribute entry in this)
  68. {
  69. length += entry.Length;
  70. }
  71. return length;
  72. }
  73. }
  74. }
  75. }