FileStreamInformation.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2017-2018 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. int entryLength = entry.PaddedLength;
  41. entry.NextEntryOffset = (index < m_entries.Count - 1) ? (uint)entryLength : 0;
  42. entry.WriteBytes(buffer, offset);
  43. offset += entryLength;
  44. }
  45. }
  46. public List<FileStreamEntry> Entries
  47. {
  48. get
  49. {
  50. return m_entries;
  51. }
  52. }
  53. public override FileInformationClass FileInformationClass
  54. {
  55. get
  56. {
  57. return FileInformationClass.FileStreamInformation;
  58. }
  59. }
  60. public override int Length
  61. {
  62. get
  63. {
  64. int length = 0;
  65. for (int index = 0; index < m_entries.Count; index++)
  66. {
  67. FileStreamEntry entry = m_entries[index];
  68. int entryLength = (index < m_entries.Count - 1) ? entry.PaddedLength : entry.Length;
  69. length += entryLength;
  70. }
  71. return length;
  72. }
  73. }
  74. }
  75. }