ReadResponse.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.IO;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_COM_READ Response
  15. /// </summary>
  16. public class ReadResponse : SMB1Command
  17. {
  18. public const int ParametersLength = 10;
  19. public const int SupportedBufferFormat = 0x01;
  20. // Parameters:
  21. public ushort CountOfBytesReturned;
  22. public byte[] Reserved; // 8 reserved bytes
  23. // Data:
  24. public byte BufferFormat;
  25. // ushort CountOfBytesRead;
  26. public byte[] Bytes;
  27. public ReadResponse() : base()
  28. {
  29. Reserved = new byte[8];
  30. }
  31. public ReadResponse(byte[] buffer, int offset) : base(buffer, offset, false)
  32. {
  33. CountOfBytesReturned = LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
  34. Reserved = ByteReader.ReadBytes(this.SMBParameters, 2, 8);
  35. BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
  36. if (BufferFormat != SupportedBufferFormat)
  37. {
  38. throw new InvalidDataException("Unsupported Buffer Format");
  39. }
  40. ushort CountOfBytesRead = LittleEndianConverter.ToUInt16(this.SMBData, 1);
  41. Bytes = ByteReader.ReadBytes(this.SMBData, 3, CountOfBytesRead);
  42. }
  43. public override byte[] GetBytes(bool isUnicode)
  44. {
  45. this.SMBParameters = new byte[ParametersLength];
  46. LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, CountOfBytesReturned);
  47. ByteWriter.WriteBytes(this.SMBParameters, 2, Reserved, 8);
  48. this.SMBData = new byte[3 + Bytes.Length];
  49. ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
  50. LittleEndianWriter.WriteUInt16(this.SMBData, 1, (ushort)Bytes.Length);
  51. ByteWriter.WriteBytes(this.SMBData, 3, Bytes);
  52. return base.GetBytes(isUnicode);
  53. }
  54. public override CommandName CommandName
  55. {
  56. get
  57. {
  58. return CommandName.SMB_COM_READ;
  59. }
  60. }
  61. }
  62. }