FileBasicInformation.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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
  11. {
  12. /// <summary>
  13. /// [MS-FSCC] 2.4.7 - FileBasicInformation
  14. /// </summary>
  15. public class FileBasicInformation : FileInformation
  16. {
  17. public const int FixedLength = 40;
  18. public SetFileTime CreationTime;
  19. public SetFileTime LastAccessTime;
  20. public SetFileTime LastWriteTime;
  21. public SetFileTime ChangeTime;
  22. public FileAttributes FileAttributes;
  23. public uint Reserved;
  24. public FileBasicInformation()
  25. {
  26. }
  27. public FileBasicInformation(byte[] buffer, int offset)
  28. {
  29. CreationTime = FileTimeHelper.ReadSetFileTime(buffer, offset + 0);
  30. LastAccessTime = FileTimeHelper.ReadSetFileTime(buffer, offset + 8);
  31. LastWriteTime = FileTimeHelper.ReadSetFileTime(buffer, offset + 16);
  32. ChangeTime = FileTimeHelper.ReadSetFileTime(buffer, offset + 24);
  33. FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 32);
  34. Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 36);
  35. }
  36. public override void WriteBytes(byte[] buffer, int offset)
  37. {
  38. FileTimeHelper.WriteSetFileTime(buffer, offset + 0, CreationTime);
  39. FileTimeHelper.WriteSetFileTime(buffer, offset + 8, LastAccessTime);
  40. FileTimeHelper.WriteSetFileTime(buffer, offset + 16, LastWriteTime);
  41. FileTimeHelper.WriteSetFileTime(buffer, offset + 24, ChangeTime);
  42. LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)FileAttributes);
  43. LittleEndianWriter.WriteUInt32(buffer, offset + 36, Reserved);
  44. }
  45. public override FileInformationClass FileInformationClass
  46. {
  47. get
  48. {
  49. return FileInformationClass.FileBasicInformation;
  50. }
  51. }
  52. public override int Length
  53. {
  54. get
  55. {
  56. return FixedLength;
  57. }
  58. }
  59. }
  60. }