FileIdBothDirectoryInformation.cs 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.17 - FileIdBothDirectoryInformation
  14. /// </summary>
  15. public class FileIdBothDirectoryInformation : QueryDirectoryFileInformation
  16. {
  17. public const int FixedLength = 104;
  18. public DateTime CreationTime;
  19. public DateTime LastAccessTime;
  20. public DateTime LastWriteTime;
  21. public DateTime ChangeTime;
  22. public ulong EndOfFile;
  23. public ulong AllocationSize;
  24. public FileAttributes FileAttributes;
  25. private uint FileNameLength;
  26. public uint EaSize;
  27. private byte ShortNameLength;
  28. public byte Reserved1;
  29. public string ShortName = String.Empty; // Short (8.3) file name in UTF16 (24 bytes)
  30. public ushort Reserved2;
  31. public ulong FileId;
  32. public string FileName = String.Empty;
  33. public FileIdBothDirectoryInformation()
  34. {
  35. }
  36. public FileIdBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
  37. {
  38. CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
  39. LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
  40. LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
  41. ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
  42. EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
  43. AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
  44. FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
  45. FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
  46. EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64);
  47. ShortNameLength = ByteReader.ReadByte(buffer, offset + 68);
  48. Reserved1 = ByteReader.ReadByte(buffer, offset + 69);
  49. ShortName = ByteReader.ReadUTF16String(buffer, offset + 70, ShortNameLength / 2);
  50. Reserved2 = LittleEndianConverter.ToUInt16(buffer, offset + 94);
  51. FileId = LittleEndianConverter.ToUInt64(buffer, offset + 96);
  52. FileName = ByteReader.ReadUTF16String(buffer, offset + 104, (int)FileNameLength / 2);
  53. }
  54. public override void WriteBytes(byte[] buffer, int offset)
  55. {
  56. base.WriteBytes(buffer, offset);
  57. ShortNameLength = (byte)(ShortName.Length * 2);
  58. FileNameLength = (uint)(FileName.Length * 2);
  59. LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
  60. LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
  61. LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
  62. LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
  63. LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
  64. LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
  65. LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
  66. LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
  67. LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize);
  68. ByteWriter.WriteByte(buffer, offset + 68, ShortNameLength);
  69. ByteWriter.WriteByte(buffer, offset + 69, Reserved1);
  70. ByteWriter.WriteUTF16String(buffer, offset + 70, ShortName);
  71. LittleEndianWriter.WriteUInt16(buffer, offset + 94, Reserved2);
  72. LittleEndianWriter.WriteUInt64(buffer, offset + 96, FileId);
  73. ByteWriter.WriteUTF16String(buffer, offset + 104, FileName);
  74. }
  75. public override FileInformationClass FileInformationClass
  76. {
  77. get
  78. {
  79. return FileInformationClass.FileIdBothDirectoryInformation;
  80. }
  81. }
  82. public override int Length
  83. {
  84. get
  85. {
  86. return FixedLength + FileName.Length * 2;
  87. }
  88. }
  89. }
  90. }