SetFileBasicInfo.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2014 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 = SMBHelper.ReadSetFileTime(buffer, offset + 0);
  34. LastAccessTime = SMBHelper.ReadSetFileTime(buffer, offset + 8);
  35. LastWriteTime = SMBHelper.ReadSetFileTime(buffer, offset + 16);
  36. LastChangeTime = SMBHelper.ReadSetFileTime(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. SMBHelper.WriteFileTime(buffer, 0, CreationTime);
  44. SMBHelper.WriteFileTime(buffer, 8, LastAccessTime);
  45. SMBHelper.WriteFileTime(buffer, 16, LastWriteTime);
  46. SMBHelper.WriteFileTime(buffer, 24, LastChangeTime);
  47. LittleEndianWriter.WriteUInt32(buffer, 32, (uint)ExtFileAttributes);
  48. LittleEndianWriter.WriteUInt32(buffer, 36, Reserved);
  49. return buffer;
  50. }
  51. }
  52. }