FileFullEAInformation.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (C) 2014-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
  12. {
  13. /// <summary>
  14. /// [MS-FSCC] 2.4.15 - FileFullEaInformation
  15. /// </summary>
  16. public class FileFullEAInformation : FileInformation
  17. {
  18. List<FileFullEAEntry> m_entries = new List<FileFullEAEntry>();
  19. public FileFullEAInformation()
  20. {
  21. }
  22. public FileFullEAInformation(byte[] buffer, int offset)
  23. {
  24. m_entries = ReadList(buffer, offset);
  25. }
  26. public override void WriteBytes(byte[] buffer, int offset)
  27. {
  28. WriteList(buffer, offset, m_entries);
  29. }
  30. public List<FileFullEAEntry> Entries
  31. {
  32. get
  33. {
  34. return m_entries;
  35. }
  36. }
  37. public override FileInformationClass FileInformationClass
  38. {
  39. get
  40. {
  41. return FileInformationClass.FileFullEaInformation;
  42. }
  43. }
  44. public override int Length
  45. {
  46. get
  47. {
  48. int length = 0;
  49. for (int index = 0; index < m_entries.Count; index++)
  50. {
  51. length += m_entries[index].Length;
  52. if (index < m_entries.Count - 1)
  53. {
  54. // When multiple FILE_FULL_EA_INFORMATION data elements are present in the buffer, each MUST be aligned on a 4-byte boundary
  55. int padding = (4 - (length % 4)) % 4;
  56. length += padding;
  57. }
  58. }
  59. return length;
  60. }
  61. }
  62. public static List<FileFullEAEntry> ReadList(byte[] buffer, int offset)
  63. {
  64. List<FileFullEAEntry> result = new List<FileFullEAEntry>();
  65. if (offset < buffer.Length)
  66. {
  67. FileFullEAEntry entry;
  68. do
  69. {
  70. entry = new FileFullEAEntry(buffer, offset);
  71. result.Add(entry);
  72. offset += (int)entry.NextEntryOffset;
  73. }
  74. while (entry.NextEntryOffset != 0);
  75. }
  76. return result;
  77. }
  78. public static void WriteList(byte[] buffer, int offset, List<FileFullEAEntry> list)
  79. {
  80. for (int index = 0; index < list.Count; index++)
  81. {
  82. FileFullEAEntry entry = list[index];
  83. entry.WriteBytes(buffer, offset);
  84. int entryLength = entry.Length;
  85. offset += entryLength;
  86. if (index < list.Count - 1)
  87. {
  88. // When multiple FILE_FULL_EA_INFORMATION data elements are present in the buffer, each MUST be aligned on a 4-byte boundary
  89. int padding = (4 - (entryLength % 4)) % 4;
  90. offset += padding;
  91. }
  92. }
  93. }
  94. }
  95. }