FileFsVolumeInformation.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.5.9 - FileFsVolumeInformation
  14. /// </summary>
  15. public class FileFsVolumeInformation : FileSystemInformation
  16. {
  17. public const int FixedLength = 18;
  18. public DateTime? VolumeCreationTime;
  19. public uint VolumeSerialNumber;
  20. private uint VolumeLabelLength;
  21. public bool SupportsObjects;
  22. public byte Reserved;
  23. public string VolumeLabel = String.Empty;
  24. public FileFsVolumeInformation()
  25. {
  26. }
  27. public FileFsVolumeInformation(byte[] buffer, int offset)
  28. {
  29. VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
  30. VolumeSerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
  31. VolumeLabelLength = LittleEndianConverter.ToUInt32(buffer, offset + 12);
  32. SupportsObjects = Convert.ToBoolean(ByteReader.ReadByte(buffer, offset + 16));
  33. Reserved = ByteReader.ReadByte(buffer, offset + 17);
  34. if (VolumeLabelLength > 0)
  35. {
  36. VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)VolumeLabelLength / 2);
  37. }
  38. }
  39. public override void WriteBytes(byte[] buffer, int offset)
  40. {
  41. VolumeLabelLength = (uint)(VolumeLabel.Length * 2);
  42. FileTimeHelper.WriteFileTime(buffer, offset + 0, VolumeCreationTime);
  43. LittleEndianWriter.WriteUInt32(buffer, offset + 8, VolumeSerialNumber);
  44. LittleEndianWriter.WriteUInt32(buffer, offset + 12, VolumeLabelLength);
  45. ByteWriter.WriteByte(buffer, offset + 16, Convert.ToByte(SupportsObjects));
  46. ByteWriter.WriteByte(buffer, offset + 17, Reserved);
  47. ByteWriter.WriteUTF16String(buffer, offset + 18, VolumeLabel);
  48. }
  49. public override FileSystemInformationClass FileSystemInformationClass
  50. {
  51. get
  52. {
  53. return FileSystemInformationClass.FileFsVolumeInformation;
  54. }
  55. }
  56. public override int Length
  57. {
  58. get
  59. {
  60. return FixedLength + VolumeLabel.Length * 2;
  61. }
  62. }
  63. }
  64. }