FileFullEAInformationList.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace SMBLibrary
  11. {
  12. /// <summary>
  13. /// [MS-FSCC] FILE_FULL_EA_INFORMATION buffer
  14. /// </summary>
  15. public class FileFullEAInformationList : List<FileFullEAInformation>
  16. {
  17. public FileFullEAInformationList()
  18. {
  19. }
  20. public FileFullEAInformationList(byte[] buffer, int offset)
  21. {
  22. FileFullEAInformation entry = new FileFullEAInformation(buffer, offset);
  23. this.Add(entry);
  24. while (entry.NextEntryOffset != 0)
  25. {
  26. entry = new FileFullEAInformation(buffer, (int)entry.NextEntryOffset);
  27. this.Add(entry);
  28. }
  29. }
  30. public void WriteBytes(byte[] buffer, int offset)
  31. {
  32. // When multiple FILE_FULL_EA_INFORMATION data elements are present in the buffer, each MUST be aligned on a 4-byte boundary
  33. for (int index = 0; index < this.Count; index++)
  34. {
  35. this[index].WriteBytes(buffer, offset);
  36. offset += this[index].Length;
  37. if (index < this.Count - 1)
  38. {
  39. int padding = (4 - (offset % 4)) % 4;
  40. offset += padding;
  41. }
  42. }
  43. }
  44. public int Length
  45. {
  46. get
  47. {
  48. // When multiple FILE_FULL_EA_INFORMATION data elements are present in the buffer, each MUST be aligned on a 4-byte boundary
  49. int length = 0;
  50. for(int index = 0; index < this.Count; index++)
  51. {
  52. length += this[index].Length;
  53. if (index < this.Count - 1)
  54. {
  55. int padding = (4 - (length % 4)) % 4;
  56. length += padding;
  57. }
  58. }
  59. return length;
  60. }
  61. }
  62. }
  63. }