FileStreamInformation.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Utilities;
  10. namespace SMBLibrary
  11. {
  12. /// <summary>
  13. /// [MS-FSCC] 2.4.40 - FileStreamInformation
  14. /// </summary>
  15. public class FileStreamInformation : FileInformation
  16. {
  17. List<FileStreamEntry> m_entries = new List<FileStreamEntry>();
  18. public FileStreamInformation()
  19. {
  20. }
  21. public FileStreamInformation(byte[] buffer, int offset)
  22. {
  23. if (offset < buffer.Length)
  24. {
  25. FileStreamEntry entry;
  26. do
  27. {
  28. entry = new FileStreamEntry(buffer, offset);
  29. m_entries.Add(entry);
  30. offset += (int)entry.NextEntryOffset;
  31. }
  32. while (entry.NextEntryOffset != 0);
  33. }
  34. }
  35. public override void WriteBytes(byte[] buffer, int offset)
  36. {
  37. for (int index = 0; index < m_entries.Count; index++)
  38. {
  39. FileStreamEntry entry = m_entries[index];
  40. entry.WriteBytes(buffer, offset);
  41. int entryLength = entry.Length;
  42. offset += entryLength;
  43. if (index < m_entries.Count - 1)
  44. {
  45. // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
  46. int padding = (8 - (entryLength % 8)) % 8;
  47. offset += padding;
  48. }
  49. }
  50. }
  51. public List<FileStreamEntry> Entries
  52. {
  53. get
  54. {
  55. return m_entries;
  56. }
  57. }
  58. public override FileInformationClass FileInformationClass
  59. {
  60. get
  61. {
  62. return FileInformationClass.FileStreamInformation;
  63. }
  64. }
  65. public override int Length
  66. {
  67. get
  68. {
  69. int length = 0;
  70. for (int index = 0; index < m_entries.Count; index++)
  71. {
  72. FileStreamEntry entry = m_entries[index];
  73. int entryLength = entry.Length;
  74. length += entryLength;
  75. if (index < m_entries.Count - 1)
  76. {
  77. // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
  78. int padding = (8 - (entryLength % 8)) % 8;
  79. length += padding;
  80. }
  81. }
  82. return length;
  83. }
  84. }
  85. }
  86. }