WriteResponse.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 WRITE Response
  14. /// </summary>
  15. public class WriteResponse : SMB2Command
  16. {
  17. public const int FixedSize = 16;
  18. public const int DeclaredSize = 17;
  19. private ushort StructureSize;
  20. public ushort Reserved;
  21. public uint Count;
  22. public uint Remaining;
  23. private ushort WriteChannelInfoOffset;
  24. private ushort WriteChannelInfoLength;
  25. public byte[] WriteChannelInfo = new byte[0];
  26. public WriteResponse() : base(SMB2CommandName.Write)
  27. {
  28. Header.IsResponse = true;
  29. StructureSize = DeclaredSize;
  30. }
  31. public WriteResponse(byte[] buffer, int offset) : base(buffer, offset)
  32. {
  33. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  34. Reserved = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  35. Count = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  36. Remaining = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 8);
  37. WriteChannelInfoOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 12);
  38. WriteChannelInfoLength = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 14);
  39. WriteChannelInfo = ByteReader.ReadBytes(buffer, offset + WriteChannelInfoOffset, WriteChannelInfoLength);
  40. }
  41. public override void WriteCommandBytes(byte[] buffer, int offset)
  42. {
  43. WriteChannelInfoOffset = 0;
  44. WriteChannelInfoLength = (ushort)WriteChannelInfo.Length;
  45. if (WriteChannelInfo.Length > 0)
  46. {
  47. WriteChannelInfoOffset = SMB2Header.Length + FixedSize;
  48. }
  49. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  50. LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved);
  51. LittleEndianWriter.WriteUInt32(buffer, offset + 4, Count);
  52. LittleEndianWriter.WriteUInt32(buffer, offset + 8, Remaining);
  53. LittleEndianWriter.WriteUInt16(buffer, offset + 12, WriteChannelInfoOffset);
  54. LittleEndianWriter.WriteUInt16(buffer, offset + 14, WriteChannelInfoLength);
  55. if (WriteChannelInfo.Length > 0)
  56. {
  57. ByteWriter.WriteBytes(buffer, offset + FixedSize, WriteChannelInfo);
  58. }
  59. }
  60. public override int CommandLength
  61. {
  62. get
  63. {
  64. return FixedSize + WriteChannelInfo.Length;
  65. }
  66. }
  67. }
  68. }