FindFileNamesInfo.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_NAMES_INFO
  15. /// </summary>
  16. public class FindFileNamesInfo : FindInformation
  17. {
  18. public const int FixedLength = 12;
  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. //uint FileNameLength; // In bytes, MUST exclude the null termination.
  22. public string FileName; // OEM / Unicode character array. MUST be written as SMB_STRING, and read as fixed length string.
  23. public FindFileNamesInfo() : base(false)
  24. {
  25. }
  26. public FindFileNamesInfo(byte[] buffer, ref int offset, bool isUnicode) : base(false)
  27. {
  28. NextEntryOffset = LittleEndianReader.ReadUInt32(buffer, ref offset);
  29. FileIndex = LittleEndianReader.ReadUInt32(buffer, ref offset);
  30. uint fileNameLength = LittleEndianReader.ReadUInt32(buffer, ref offset);
  31. FileName = SMB1Helper.ReadFixedLengthString(buffer, ref offset, isUnicode, (int)fileNameLength);
  32. }
  33. public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
  34. {
  35. uint fileNameLength = (uint)(isUnicode ? FileName.Length * 2 : FileName.Length);
  36. LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
  37. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex);
  38. LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength);
  39. SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
  40. }
  41. public override int GetLength(bool isUnicode)
  42. {
  43. int length = FixedLength;
  44. if (isUnicode)
  45. {
  46. length += FileName.Length * 2 + 2;
  47. }
  48. else
  49. {
  50. length += FileName.Length + 1;
  51. }
  52. return length;
  53. }
  54. public override FindInformationLevel InformationLevel
  55. {
  56. get
  57. {
  58. return FindInformationLevel.SMB_FIND_FILE_NAMES_INFO;
  59. }
  60. }
  61. }
  62. }