FileCompressionInformation.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.9 - FileCompressionInformation
  14. /// </summary>
  15. public class FileCompressionInformation : FileInformation
  16. {
  17. public const int FixedLength = 16;
  18. public ulong CompressedFileSize;
  19. public CompressionFormat CompressionFormat;
  20. public byte CompressionUnitShift;
  21. public byte ChunkShift;
  22. public byte ClusterShift;
  23. public byte[] Reserved; // 3 bytes
  24. public FileCompressionInformation()
  25. {
  26. }
  27. public FileCompressionInformation(byte[] buffer, int offset)
  28. {
  29. CompressedFileSize = LittleEndianConverter.ToUInt64(buffer, offset + 0);
  30. CompressionFormat = (CompressionFormat)LittleEndianConverter.ToUInt16(buffer, offset + 8);
  31. CompressionUnitShift = ByteReader.ReadByte(buffer, offset + 10);
  32. ChunkShift = ByteReader.ReadByte(buffer, offset + 11);
  33. ClusterShift = ByteReader.ReadByte(buffer, offset + 12);
  34. Reserved = ByteReader.ReadBytes(buffer, offset + 13, 3);
  35. }
  36. public override void WriteBytes(byte[] buffer, int offset)
  37. {
  38. LittleEndianWriter.WriteUInt64(buffer, offset + 0, CompressedFileSize);
  39. LittleEndianWriter.WriteUInt16(buffer, offset + 8, (ushort)CompressionFormat);
  40. ByteWriter.WriteByte(buffer, offset + 10, CompressionUnitShift);
  41. ByteWriter.WriteByte(buffer, offset + 11, ChunkShift);
  42. ByteWriter.WriteByte(buffer, offset + 12, ClusterShift);
  43. ByteWriter.WriteBytes(buffer, offset + 13, Reserved, 3);
  44. }
  45. public override FileInformationClass FileInformationClass
  46. {
  47. get
  48. {
  49. return FileInformationClass.FileCompressionInformation;
  50. }
  51. }
  52. public override int Length
  53. {
  54. get
  55. {
  56. return FixedLength;
  57. }
  58. }
  59. }
  60. }