ChangeNotifyResponse.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 CHANGE_NOTIFY Response
  14. /// </summary>
  15. public class ChangeNotifyResponse : SMB2Command
  16. {
  17. public const int FixedSize = 8;
  18. public const int DeclaredSize = 9;
  19. private ushort StructureSize;
  20. private ushort OutputBufferOffset;
  21. private uint OutputBufferLength;
  22. public byte[] OutputBuffer = new byte[0];
  23. public ChangeNotifyResponse() : base(SMB2CommandName.ChangeNotify)
  24. {
  25. Header.IsResponse = true;
  26. StructureSize = DeclaredSize;
  27. }
  28. public ChangeNotifyResponse(byte[] buffer, int offset) : base(buffer, offset)
  29. {
  30. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  31. OutputBufferOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  32. OutputBufferLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  33. OutputBuffer = ByteReader.ReadBytes(buffer, offset + OutputBufferOffset, (int)OutputBufferLength);
  34. }
  35. public override void WriteCommandBytes(byte[] buffer, int offset)
  36. {
  37. OutputBufferOffset = 0;
  38. OutputBufferLength = (uint)OutputBuffer.Length;
  39. if (OutputBuffer.Length > 0)
  40. {
  41. OutputBufferOffset = SMB2Header.Length + FixedSize;
  42. }
  43. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  44. LittleEndianWriter.WriteUInt16(buffer, offset + 2, OutputBufferOffset);
  45. LittleEndianWriter.WriteUInt32(buffer, offset + 4, OutputBufferLength);
  46. ByteWriter.WriteBytes(buffer, offset + FixedSize, OutputBuffer);
  47. }
  48. public List<FileNotifyInformation> GetFileNotifyInformation()
  49. {
  50. return FileNotifyInformation.ReadList(OutputBuffer, 0);
  51. }
  52. public void SetFileNotifyInformation(List<FileNotifyInformation> notifyInformationList)
  53. {
  54. OutputBuffer = FileNotifyInformation.GetBytes(notifyInformationList);
  55. }
  56. public override int CommandLength
  57. {
  58. get
  59. {
  60. return FixedSize + OutputBuffer.Length;
  61. }
  62. }
  63. }
  64. }