QueryFileStandardInfo.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_STANDARD_INFO
  15. /// </summary>
  16. public class QueryFileStandardInfo : QueryInformation
  17. {
  18. public const int Length = 22;
  19. public long AllocationSize;
  20. public long EndOfFile;
  21. public uint NumberOfLinks;
  22. public bool DeletePending;
  23. public bool Directory;
  24. public QueryFileStandardInfo()
  25. {
  26. }
  27. public QueryFileStandardInfo(byte[] buffer, int offset)
  28. {
  29. AllocationSize = LittleEndianReader.ReadInt64(buffer, ref offset);
  30. EndOfFile = LittleEndianReader.ReadInt64(buffer, ref offset);
  31. NumberOfLinks = LittleEndianReader.ReadUInt32(buffer, ref offset);
  32. DeletePending = (ByteReader.ReadByte(buffer, ref offset) > 0);
  33. Directory = (ByteReader.ReadByte(buffer, ref offset) > 0);
  34. }
  35. public override byte[] GetBytes()
  36. {
  37. byte[] buffer = new byte[Length];
  38. int offset = 0;
  39. LittleEndianWriter.WriteInt64(buffer, ref offset, AllocationSize);
  40. LittleEndianWriter.WriteInt64(buffer, ref offset, EndOfFile);
  41. LittleEndianWriter.WriteUInt32(buffer, ref offset, NumberOfLinks);
  42. ByteWriter.WriteByte(buffer, ref offset, Convert.ToByte(DeletePending));
  43. ByteWriter.WriteByte(buffer, ref offset, Convert.ToByte(Directory));
  44. return buffer;
  45. }
  46. public override QueryInformationLevel InformationLevel
  47. {
  48. get
  49. {
  50. return QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO;
  51. }
  52. }
  53. }
  54. }