FileNameInformation.cs 1.7 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.1.7 - FILE_NAME_INFORMATION
  14. /// [MS-FSCC] 2.4.25 - FileNameInformation
  15. /// </summary>
  16. public class FileNameInformation : FileInformation
  17. {
  18. public const int FixedLength = 4;
  19. private uint FileNameLength;
  20. public string FileName = String.Empty;
  21. public FileNameInformation()
  22. {
  23. }
  24. public FileNameInformation(byte[] buffer, int offset)
  25. {
  26. FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 0);
  27. FileName = ByteReader.ReadUTF16String(buffer, offset + 4, (int)FileNameLength / 2);
  28. }
  29. public override void WriteBytes(byte[] buffer, int offset)
  30. {
  31. FileNameLength = (uint)(FileName.Length * 2);
  32. LittleEndianWriter.WriteUInt32(buffer, offset + 0, FileNameLength);
  33. ByteWriter.WriteUTF16String(buffer, offset + 4, FileName);
  34. }
  35. public override FileInformationClass FileInformationClass
  36. {
  37. get
  38. {
  39. return FileInformationClass.FileNameInformation;
  40. }
  41. }
  42. public override int Length
  43. {
  44. get
  45. {
  46. return FixedLength + FileName.Length * 2;
  47. }
  48. }
  49. }
  50. }