QueryFSAttibuteInfo.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 2014-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 System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_QUERY_FS_ATTRIBUTE_INFO
  15. /// </summary>
  16. public class QueryFSAttibuteInfo : QueryFSInformation
  17. {
  18. public const int FixedLength = 12;
  19. public FileSystemAttributes FileSystemAttributes;
  20. public uint MaxFileNameLengthInBytes;
  21. //uint LengthOfFileSystemName; // In bytes
  22. public string FileSystemName; // Unicode
  23. public QueryFSAttibuteInfo()
  24. {
  25. }
  26. public QueryFSAttibuteInfo(byte[] buffer, int offset)
  27. {
  28. FileSystemAttributes = (FileSystemAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 0);
  29. MaxFileNameLengthInBytes = LittleEndianConverter.ToUInt32(buffer, offset + 4);
  30. uint lengthOfFileSystemName = LittleEndianConverter.ToUInt32(buffer, offset + 8);
  31. FileSystemName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)(lengthOfFileSystemName / 2));
  32. }
  33. public override byte[] GetBytes(bool isUnicode)
  34. {
  35. uint lengthOfFileSystemName = (uint)(FileSystemName.Length * 2);
  36. byte[] buffer = new byte[this.Length];
  37. LittleEndianWriter.WriteUInt32(buffer, 0, (uint)FileSystemAttributes);
  38. LittleEndianWriter.WriteUInt32(buffer, 4, MaxFileNameLengthInBytes);
  39. LittleEndianWriter.WriteUInt32(buffer, 8, lengthOfFileSystemName);
  40. ByteWriter.WriteUTF16String(buffer, 12, FileSystemName);
  41. return buffer;
  42. }
  43. public override int Length
  44. {
  45. get
  46. {
  47. return FixedLength + FileSystemName.Length * 2;
  48. }
  49. }
  50. public override QueryFSInformationLevel InformationLevel
  51. {
  52. get
  53. {
  54. return QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO;
  55. }
  56. }
  57. }
  58. }