FileStreamInformation.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. public const int FixedLength = 24;
  18. public uint NextEntryOffset;
  19. private uint StreamNameLength;
  20. public ulong StreamSize;
  21. public ulong StreamAllocationSize;
  22. public string StreamName = String.Empty;
  23. public FileStreamInformation()
  24. {
  25. }
  26. public FileStreamInformation(byte[] buffer, int offset)
  27. {
  28. NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0);
  29. StreamNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4);
  30. StreamSize = LittleEndianConverter.ToUInt64(buffer, offset + 8);
  31. StreamAllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 16);
  32. ByteReader.ReadUTF16String(buffer, offset + 24, (int)StreamNameLength / 2);
  33. }
  34. public override 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.WriteUInt64(buffer, offset + 8, StreamSize);
  40. LittleEndianWriter.WriteUInt64(buffer, offset + 16, StreamAllocationSize);
  41. ByteWriter.WriteUTF16String(buffer, offset + 24, StreamName);
  42. }
  43. public override FileInformationClass FileInformationClass
  44. {
  45. get
  46. {
  47. return FileInformationClass.FileStreamInformation;
  48. }
  49. }
  50. public override int Length
  51. {
  52. get
  53. {
  54. return FixedLength + StreamName.Length * 2;
  55. }
  56. }
  57. }
  58. }