FindFileDirectoryInfo.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_DIRECTORY_INFO
  15. /// </summary>
  16. public class FindFileDirectoryInfo : FindInformation
  17. {
  18. public const int FixedLength = 64;
  19. // 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 string FileName; // OEM / Unicode character array. MUST be written as SMB_STRING, and read as fixed length string.
  30. public FindFileDirectoryInfo() : base()
  31. {
  32. }
  33. public FindFileDirectoryInfo(byte[] buffer, int offset, bool isUnicode) : base()
  34. {
  35. NextEntryOffset = LittleEndianReader.ReadUInt32(buffer, ref offset);
  36. FileIndex = LittleEndianReader.ReadUInt32(buffer, ref offset);
  37. CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  38. LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  39. LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  40. LastAttrChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, ref offset);
  41. EndOfFile = LittleEndianReader.ReadInt64(buffer, ref offset);
  42. AllocationSize = LittleEndianReader.ReadInt64(buffer, ref offset);
  43. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(buffer, ref offset);
  44. uint fileNameLength = LittleEndianReader.ReadUInt32(buffer, ref offset);
  45. FileName = SMB1Helper.ReadFixedLengthString(buffer, ref offset, isUnicode, (int)fileNameLength);
  46. }
  47. public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
  48. {
  49. uint fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length);
  50. LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
  51. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex);
  52. FileTimeHelper.WriteFileTime(buffer, ref offset, CreationTime);
  53. FileTimeHelper.WriteFileTime(buffer, ref offset, LastAccessTime);
  54. FileTimeHelper.WriteFileTime(buffer, ref offset, LastWriteTime);
  55. FileTimeHelper.WriteFileTime(buffer, ref offset, LastAttrChangeTime);
  56. LittleEndianWriter.WriteInt64(buffer, ref offset, EndOfFile);
  57. LittleEndianWriter.WriteInt64(buffer, ref offset, AllocationSize);
  58. LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)ExtFileAttributes);
  59. LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength);
  60. SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
  61. }
  62. public override int GetLength(bool isUnicode)
  63. {
  64. int length = FixedLength;
  65. if (isUnicode)
  66. {
  67. length += FileName.Length * 2 + 2;
  68. }
  69. else
  70. {
  71. length += FileName.Length + 1;
  72. }
  73. return length;
  74. }
  75. public override FindInformationLevel InformationLevel
  76. {
  77. get
  78. {
  79. return FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO;
  80. }
  81. }
  82. }
  83. }