TreeConnectResponse.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.SMB2
  11. {
  12. /// <summary>
  13. /// SMB2 TREE_CONNECT Response
  14. /// </summary>
  15. public class TreeConnectResponse : SMB2Command
  16. {
  17. public const int DeclaredSize = 16;
  18. private ushort StructureSize;
  19. public ShareType ShareType;
  20. public byte Reserved;
  21. public ShareFlags ShareFlags;
  22. public ShareCapabilities Capabilities;
  23. public AccessMask MaximalAccess;
  24. public TreeConnectResponse() : base(SMB2CommandName.TreeConnect)
  25. {
  26. Header.IsResponse = true;
  27. StructureSize = DeclaredSize;
  28. }
  29. public TreeConnectResponse(byte[] buffer, int offset) : base(buffer, offset)
  30. {
  31. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  32. ShareType = (ShareType)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2);
  33. Reserved = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
  34. ShareFlags = (ShareFlags)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  35. Capabilities = (ShareCapabilities)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 8);
  36. MaximalAccess = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 12);
  37. }
  38. public override void WriteCommandBytes(byte[] buffer, int offset)
  39. {
  40. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  41. ByteWriter.WriteByte(buffer, offset + 2, (byte)ShareType);
  42. ByteWriter.WriteByte(buffer, offset + 3, Reserved);
  43. LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)ShareFlags);
  44. LittleEndianWriter.WriteUInt32(buffer, offset + 8, (uint)Capabilities);
  45. LittleEndianWriter.WriteUInt32(buffer, offset + 12, (uint)MaximalAccess);
  46. }
  47. public override int CommandLength
  48. {
  49. get
  50. {
  51. return DeclaredSize;
  52. }
  53. }
  54. }
  55. }