QueryInfoStandard.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_INFO_STANDARD
  15. /// </summary>
  16. public class QueryInfoStandard : QueryInformation
  17. {
  18. public const int Length = 22;
  19. public DateTime CreationDateTime;
  20. public DateTime LastAccessDateTime;
  21. public DateTime LastWriteDateTime;
  22. public uint FileDataSize;
  23. public uint AllocationSize;
  24. public SMBFileAttributes Attributes;
  25. public QueryInfoStandard()
  26. {
  27. }
  28. public QueryInfoStandard(byte[] buffer, int offset)
  29. {
  30. CreationDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  31. LastAccessDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  32. LastWriteDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  33. FileDataSize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  34. AllocationSize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  35. Attributes = (SMBFileAttributes)LittleEndianReader.ReadUInt16(buffer, ref offset);
  36. }
  37. public override byte[] GetBytes()
  38. {
  39. byte[] buffer = new byte[Length];
  40. int offset = 0;
  41. SMB1Helper.WriteSMBDateTime(buffer, ref offset, CreationDateTime);
  42. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastAccessDateTime);
  43. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastWriteDateTime);
  44. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileDataSize);
  45. LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationSize);
  46. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Attributes);
  47. return buffer;
  48. }
  49. public override QueryInformationLevel InformationLevel
  50. {
  51. get
  52. {
  53. return QueryInformationLevel.SMB_INFO_STANDARD;
  54. }
  55. }
  56. }
  57. }