QueryFSInfoVolume.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2014 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 System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_INFO_VOLUME
  15. /// </summary>
  16. public class QueryFSInfoVolume : QueryFSInformation
  17. {
  18. public uint VolumeSerialNumber;
  19. //byte CharCount;
  20. public string VolumeLabel; // SMB_STRING
  21. public QueryFSInfoVolume()
  22. {
  23. }
  24. public QueryFSInfoVolume(bool isUnicode, byte[] buffer, int offset)
  25. {
  26. VolumeSerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 0);
  27. byte charCount = ByteReader.ReadByte(buffer, offset + 4);
  28. VolumeLabel = SMB1Helper.ReadSMBString(buffer, offset + 5, isUnicode);
  29. }
  30. public override byte[] GetBytes(bool isUnicode)
  31. {
  32. byte charCount = (byte)VolumeLabel.Length;
  33. int length = GetLength(isUnicode);
  34. byte[] buffer = new byte[length];
  35. LittleEndianWriter.WriteUInt32(buffer, 0, VolumeSerialNumber);
  36. ByteWriter.WriteByte(buffer, 4, charCount);
  37. SMB1Helper.WriteSMBString(buffer, 5, isUnicode, VolumeLabel);
  38. return buffer;
  39. }
  40. public int GetLength(bool isUnicode)
  41. {
  42. int length = 5;
  43. if (isUnicode)
  44. {
  45. length += VolumeLabel.Length * 2;
  46. }
  47. else
  48. {
  49. length += VolumeLabel.Length;
  50. }
  51. return length;
  52. }
  53. }
  54. }