ChangeNotifyRequest.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 Request
  14. /// </summary>
  15. public class ChangeNotifyRequest : SMB2Command
  16. {
  17. public const int DeclaredSize = 32;
  18. private ushort StructureSize;
  19. public ChangeNotifyFlags Flags;
  20. public uint OutputBufferLength;
  21. public FileID FileId;
  22. public NotifyChangeFilter CompletionFilter;
  23. public uint Reserved;
  24. public ChangeNotifyRequest() : base(SMB2CommandName.ChangeNotify)
  25. {
  26. StructureSize = DeclaredSize;
  27. }
  28. public ChangeNotifyRequest(byte[] buffer, int offset) : base(buffer, offset)
  29. {
  30. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  31. Flags = (ChangeNotifyFlags)LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  32. OutputBufferLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  33. FileId = new FileID(buffer, offset + SMB2Header.Length + 8);
  34. CompletionFilter = (NotifyChangeFilter)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 24);
  35. Reserved = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 28);
  36. }
  37. public override void WriteCommandBytes(byte[] buffer, int offset)
  38. {
  39. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  40. LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Flags);
  41. LittleEndianWriter.WriteUInt32(buffer, offset + 4, OutputBufferLength);
  42. FileId.WriteBytes(buffer, offset + 8);
  43. LittleEndianWriter.WriteUInt32(buffer, offset + 24, (uint)CompletionFilter);
  44. LittleEndianWriter.WriteUInt32(buffer, offset + 28, Reserved);
  45. }
  46. public bool WatchTree
  47. {
  48. get
  49. {
  50. return ((Flags & ChangeNotifyFlags.WatchTree) > 0);
  51. }
  52. set
  53. {
  54. if (value)
  55. {
  56. Flags |= ChangeNotifyFlags.WatchTree;
  57. }
  58. else
  59. {
  60. Flags &= ~ChangeNotifyFlags.WatchTree;
  61. }
  62. }
  63. }
  64. public override int CommandLength
  65. {
  66. get
  67. {
  68. return DeclaredSize;
  69. }
  70. }
  71. }
  72. }