FileStreamEntry.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 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. /// <summary>
  51. /// [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
  52. /// </summary>
  53. public int PaddedLength
  54. {
  55. get
  56. {
  57. int length = this.Length;
  58. int padding = (8 - (length % 8)) % 8;
  59. return length + padding;
  60. }
  61. }
  62. }
  63. }