FindFileFullDirectoryInfo.cs 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_FIND_FILE_FULL_DIRECTORY_INFO
  15. /// </summary>
  16. public class FindFileFullDirectoryInfo : FindInformation
  17. {
  18. public const int FixedLength = 68;
  19. public uint NextEntryOffset;
  20. public uint FileIndex; // SHOULD be set to zero when sent in a response and SHOULD be ignored when received by the client
  21. public DateTime? CreationTime;
  22. public DateTime? LastAccessTime;
  23. public DateTime? LastWriteTime;
  24. public DateTime? LastAttrChangeTime;
  25. public long EndOfFile;
  26. public long AllocationSize;
  27. public ExtendedFileAttributes ExtFileAttributes;
  28. //uint FileNameLength; // In bytes, MUST exclude the null termination.
  29. public uint EASize;
  30. public string FileName; // OEM / Unicode character array. MUST be written as SMB_STRING, and read as fixed length string.
  31. public FindFileFullDirectoryInfo() : base(false)
  32. {
  33. }
  34. public FindFileFullDirectoryInfo(byte[] buffer, ref int offset, bool isUnicode) : base(false)
  35. {
  36. NextEntryOffset = LittleEndianReader.ReadUInt32(buffer, ref offset);
  37. FileIndex = LittleEndianReader.ReadUInt32(buffer, ref offset);
  38. CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  39. LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  40. LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  41. LastAttrChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  42. EndOfFile = LittleEndianReader.ReadInt64(buffer, ref offset);
  43. AllocationSize = LittleEndianReader.ReadInt64(buffer, ref offset);
  44. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(buffer, ref offset);
  45. uint fileNameLength = LittleEndianReader.ReadUInt32(buffer, ref offset);
  46. EASize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  47. FileName = SMB1Helper.ReadFixedLengthString(buffer, ref offset, isUnicode, (int)fileNameLength);
  48. }
  49. public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
  50. {
  51. uint fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length);
  52. LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
  53. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex);
  54. FileTimeHelper.WriteFileTime(buffer, ref offset, CreationTime);
  55. FileTimeHelper.WriteFileTime(buffer, ref offset, LastAccessTime);
  56. FileTimeHelper.WriteFileTime(buffer, ref offset, LastWriteTime);
  57. FileTimeHelper.WriteFileTime(buffer, ref offset, LastAttrChangeTime);
  58. LittleEndianWriter.WriteInt64(buffer, ref offset, EndOfFile);
  59. LittleEndianWriter.WriteInt64(buffer, ref offset, AllocationSize);
  60. LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)ExtFileAttributes);
  61. LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength);
  62. LittleEndianWriter.WriteUInt32(buffer, ref offset, EASize);
  63. SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
  64. }
  65. public override int GetLength(bool isUnicode)
  66. {
  67. int length = FixedLength;
  68. if (isUnicode)
  69. {
  70. length += FileName.Length * 2 + 2;
  71. }
  72. else
  73. {
  74. length += FileName.Length + 1;
  75. }
  76. return length;
  77. }
  78. public override FindInformationLevel InformationLevel
  79. {
  80. get
  81. {
  82. return FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO;
  83. }
  84. }
  85. }
  86. }