QueryFileCompressionInfo.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_COMPRESSION_INFO
  15. /// </summary>
  16. public class QueryFileCompressionInfo : QueryInformation
  17. {
  18. public const int Length = 16;
  19. public long CompressedFileSize;
  20. public CompressionFormat CompressionFormat;
  21. public byte CompressionUnitShift;
  22. public byte ChunkShift;
  23. public byte ClusterShift;
  24. public byte[] Reserved; // 3 bytes
  25. public QueryFileCompressionInfo()
  26. {
  27. Reserved = new byte[3];
  28. }
  29. public QueryFileCompressionInfo(byte[] buffer, int offset)
  30. {
  31. CompressedFileSize = LittleEndianReader.ReadInt64(buffer, ref offset);
  32. CompressionFormat = (CompressionFormat)LittleEndianReader.ReadUInt16(buffer, ref offset);
  33. CompressionUnitShift = ByteReader.ReadByte(buffer, ref offset);
  34. ChunkShift = ByteReader.ReadByte(buffer, ref offset);
  35. ClusterShift = ByteReader.ReadByte(buffer, ref offset);
  36. Reserved = ByteReader.ReadBytes(buffer, ref offset, 3);
  37. }
  38. public override byte[] GetBytes()
  39. {
  40. byte[] buffer = new byte[Length];
  41. int offset = 0;
  42. LittleEndianWriter.WriteInt64(buffer, ref offset, CompressedFileSize);
  43. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)CompressionFormat);
  44. ByteWriter.WriteByte(buffer, ref offset, CompressionUnitShift);
  45. ByteWriter.WriteByte(buffer, ref offset, ChunkShift);
  46. ByteWriter.WriteByte(buffer, ref offset, ClusterShift);
  47. ByteWriter.WriteBytes(buffer, ref offset, Reserved, 3);
  48. return buffer;
  49. }
  50. public override QueryInformationLevel InformationLevel
  51. {
  52. get
  53. {
  54. return QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO;
  55. }
  56. }
  57. }
  58. }