CloseResponse.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 CLOSE Response
  14. /// </summary>
  15. public class CloseResponse : SMB2Command
  16. {
  17. public const int DeclaredSize = 60;
  18. private ushort StructureSize;
  19. public CloseFlags Flags;
  20. public uint Reserved;
  21. public DateTime? CreationTime;
  22. public DateTime? LastAccessTime;
  23. public DateTime? LastWriteTime;
  24. public DateTime? ChangeTime;
  25. public long AllocationSize;
  26. public long EndofFile;
  27. public FileAttributes FileAttributes;
  28. public CloseResponse() : base(SMB2CommandName.Close)
  29. {
  30. Header.IsResponse = true;
  31. StructureSize = DeclaredSize;
  32. }
  33. public CloseResponse(byte[] buffer, int offset) : base(buffer, offset)
  34. {
  35. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  36. Flags = (CloseFlags)LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  37. Reserved = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  38. CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 8);
  39. LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 16);
  40. LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 24);
  41. ChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 32);
  42. AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 40);
  43. EndofFile = LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 48);
  44. FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 56);
  45. }
  46. public override void WriteCommandBytes(byte[] buffer, int offset)
  47. {
  48. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  49. LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Flags);
  50. LittleEndianWriter.WriteUInt32(buffer, offset + 4, Reserved);
  51. FileTimeHelper.WriteFileTime(buffer, offset + 8, CreationTime);
  52. FileTimeHelper.WriteFileTime(buffer, offset + 16, LastAccessTime);
  53. FileTimeHelper.WriteFileTime(buffer, offset + 24, LastWriteTime);
  54. FileTimeHelper.WriteFileTime(buffer, offset + 32, ChangeTime);
  55. LittleEndianWriter.WriteInt64(buffer, offset + 40, AllocationSize);
  56. LittleEndianWriter.WriteInt64(buffer, offset + 48, EndofFile);
  57. LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
  58. }
  59. public override int CommandLength
  60. {
  61. get
  62. {
  63. return DeclaredSize;
  64. }
  65. }
  66. }
  67. }