SetFileBasicInfo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_SET_FILE_BASIC_INFO
  15. /// </summary>
  16. public class SetFileBasicInfo : SetInformation
  17. {
  18. public const int Length = 40;
  19. public DateTime? CreationTime;
  20. public DateTime? LastAccessTime;
  21. public DateTime? LastWriteTime;
  22. public DateTime? LastChangeTime;
  23. public ExtendedFileAttributes ExtFileAttributes;
  24. public uint Reserved;
  25. public SetFileBasicInfo()
  26. {
  27. }
  28. public SetFileBasicInfo(byte[] buffer) : this(buffer, 0)
  29. {
  30. }
  31. public SetFileBasicInfo(byte[] buffer, int offset)
  32. {
  33. CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
  34. LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 8);
  35. LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 16);
  36. LastChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 24);
  37. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 32);
  38. Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 36);
  39. }
  40. public override byte[] GetBytes()
  41. {
  42. byte[] buffer = new byte[Length];
  43. FileTimeHelper.WriteFileTime(buffer, 0, CreationTime);
  44. FileTimeHelper.WriteFileTime(buffer, 8, LastAccessTime);
  45. FileTimeHelper.WriteFileTime(buffer, 16, LastWriteTime);
  46. FileTimeHelper.WriteFileTime(buffer, 24, LastChangeTime);
  47. LittleEndianWriter.WriteUInt32(buffer, 32, (uint)ExtFileAttributes);
  48. LittleEndianWriter.WriteUInt32(buffer, 36, Reserved);
  49. return buffer;
  50. }
  51. public override SetInformationLevel InformationLevel
  52. {
  53. get
  54. {
  55. return SetInformationLevel.SMB_SET_FILE_BASIC_INFO;
  56. }
  57. }
  58. }
  59. }