WriteAndXResponse.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_COM_WRITE_ANDX Response
  15. /// SMB 1.0: The 2 reserved bytes at offset 8 become CountHigh (used when the CAP_LARGE_WRITEX capability has been negotiated)
  16. /// </summary>
  17. public class WriteAndXResponse : SMBAndXCommand
  18. {
  19. public const int ParametersLength = 12;
  20. // Parameters:
  21. //CommandName AndXCommand;
  22. //byte AndXReserved;
  23. //ushort AndXOffset;
  24. public uint Count; // The number of bytes written to the file, 2 bytes + 2 'CountHigh' bytes
  25. public ushort Available;
  26. public ushort Reserved;
  27. public WriteAndXResponse() : base()
  28. {}
  29. public WriteAndXResponse(byte[] buffer, int offset): base(buffer, offset, false)
  30. {
  31. Count = LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
  32. Available = LittleEndianConverter.ToUInt16(this.SMBParameters, 6);
  33. ushort countHigh = LittleEndianConverter.ToUInt16(this.SMBParameters, 8);
  34. Reserved = LittleEndianConverter.ToUInt16(this.SMBParameters, 10);
  35. Count |= (uint)(countHigh << 16);
  36. }
  37. public override byte[] GetBytes(bool isUnicode)
  38. {
  39. this.SMBParameters = new byte[ParametersLength];
  40. ushort counthHigh = (ushort)(Count >> 16);
  41. LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, (ushort)(Count & 0xFFFF));
  42. LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, Available);
  43. LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, counthHigh);
  44. LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, Reserved);
  45. return base.GetBytes(isUnicode);
  46. }
  47. public override CommandName CommandName
  48. {
  49. get
  50. {
  51. return CommandName.SMB_COM_WRITE_ANDX;
  52. }
  53. }
  54. }
  55. }