QueryFileBasicInfo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_QUERY_FILE_BASIC_INFO
  15. /// </summary>
  16. public class QueryFileBasicInfo : QueryInformation
  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 QueryFileBasicInfo()
  26. {
  27. }
  28. public QueryFileBasicInfo(byte[] buffer, int offset)
  29. {
  30. CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  31. LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  32. LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  33. LastChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  34. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(buffer, ref offset);
  35. Reserved = LittleEndianReader.ReadUInt32(buffer, ref offset);
  36. }
  37. public override byte[] GetBytes()
  38. {
  39. byte[] buffer = new byte[Length];
  40. int offset = 0;
  41. FileTimeHelper.WriteFileTime(buffer, ref offset, CreationTime);
  42. FileTimeHelper.WriteFileTime(buffer, ref offset, LastAccessTime);
  43. FileTimeHelper.WriteFileTime(buffer, ref offset, LastWriteTime);
  44. FileTimeHelper.WriteFileTime(buffer, ref offset, LastChangeTime);
  45. LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)ExtFileAttributes);
  46. LittleEndianWriter.WriteUInt32(buffer, ref offset, Reserved);
  47. return buffer;
  48. }
  49. public override QueryInformationLevel InformationLevel
  50. {
  51. get
  52. {
  53. return QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO;
  54. }
  55. }
  56. }
  57. }