SessionSetupResponse.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 SESSION_SETUP Response
  14. /// </summary>
  15. public class SessionSetupResponse : SMB2Command
  16. {
  17. public const int FixedSize = 8;
  18. public const int DeclaredSize = 9;
  19. private ushort StructureSize;
  20. public SessionFlags SessionFlags;
  21. private ushort SecurityBufferOffset;
  22. private ushort SecurityBufferLength;
  23. public byte[] SecurityBuffer = new byte[0];
  24. public SessionSetupResponse() : base(SMB2CommandName.SessionSetup)
  25. {
  26. Header.IsResponse = true;
  27. StructureSize = DeclaredSize;
  28. }
  29. public SessionSetupResponse(byte[] buffer, int offset) : base(buffer, offset)
  30. {
  31. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  32. SessionFlags = (SessionFlags)LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  33. SecurityBufferOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 4);
  34. SecurityBufferLength = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 6);
  35. SecurityBuffer = ByteReader.ReadBytes(buffer, offset + SecurityBufferOffset, SecurityBufferLength);
  36. }
  37. public override void WriteCommandBytes(byte[] buffer, int offset)
  38. {
  39. SecurityBufferOffset = 0;
  40. SecurityBufferLength = (ushort)SecurityBuffer.Length;
  41. if (SecurityBuffer.Length > 0)
  42. {
  43. SecurityBufferOffset = SMB2Header.Length + FixedSize;
  44. }
  45. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  46. LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)SessionFlags);
  47. LittleEndianWriter.WriteUInt16(buffer, offset + 4, SecurityBufferOffset);
  48. LittleEndianWriter.WriteUInt16(buffer, offset + 6, SecurityBufferLength);
  49. ByteWriter.WriteBytes(buffer, offset + 8, SecurityBuffer);
  50. }
  51. public override int CommandLength
  52. {
  53. get
  54. {
  55. return FixedSize + SecurityBuffer.Length;
  56. }
  57. }
  58. }
  59. }