FileStreamEntry.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 data element
  14. /// </summary>
  15. public class FileStreamEntry
  16. {
  17. public const int FixedLength = 24;
  18. public uint NextEntryOffset;
  19. private uint StreamNameLength;
  20. public long StreamSize;
  21. public long StreamAllocationSize;
  22. public string StreamName = String.Empty;
  23. public FileStreamEntry()
  24. {
  25. }
  26. public FileStreamEntry(byte[] buffer, int offset)
  27. {
  28. NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0);
  29. StreamNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4);
  30. StreamSize = LittleEndianConverter.ToInt64(buffer, offset + 8);
  31. StreamAllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 16);
  32. StreamName = ByteReader.ReadUTF16String(buffer, offset + 24, (int)StreamNameLength / 2);
  33. }
  34. public void WriteBytes(byte[] buffer, int offset)
  35. {
  36. StreamNameLength = (uint)(StreamName.Length * 2);
  37. LittleEndianWriter.WriteUInt32(buffer, offset + 0, NextEntryOffset);
  38. LittleEndianWriter.WriteUInt32(buffer, offset + 4, StreamNameLength);
  39. LittleEndianWriter.WriteInt64(buffer, offset + 8, StreamSize);
  40. LittleEndianWriter.WriteInt64(buffer, offset + 16, StreamAllocationSize);
  41. ByteWriter.WriteUTF16String(buffer, offset + 24, StreamName);
  42. }
  43. public int Length
  44. {
  45. get
  46. {
  47. return FixedLength + StreamName.Length * 2;
  48. }
  49. }
  50. }
  51. }