Transaction2FindNext2Request.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /// TRANS2_FIND_NEXT2 Request
  15. /// </summary>
  16. public class Transaction2FindNext2Request : Transaction2Subcommand
  17. {
  18. // Parameters:
  19. public ushort SID; // Search handle
  20. public ushort SearchCount;
  21. public FindInformationLevel InformationLevel;
  22. public uint ResumeKey;
  23. public FindFlags Flags;
  24. public string FileName; // SMB_STRING
  25. // Data:
  26. public ExtendedAttributeNameList GetExtendedAttributeList; // Used with FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  27. public Transaction2FindNext2Request() : base()
  28. {
  29. GetExtendedAttributeList = new ExtendedAttributeNameList();
  30. }
  31. public Transaction2FindNext2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
  32. {
  33. SID = LittleEndianConverter.ToUInt16(parameters, 0);
  34. SearchCount = LittleEndianConverter.ToUInt16(parameters, 2);
  35. InformationLevel = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 4);
  36. ResumeKey = LittleEndianConverter.ToUInt32(parameters, 6);
  37. Flags = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 10);
  38. FileName = SMB1Helper.ReadSMBString(parameters, 12, isUnicode);
  39. if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  40. {
  41. GetExtendedAttributeList = new ExtendedAttributeNameList(data, 0);
  42. }
  43. }
  44. public override byte[] GetSetup()
  45. {
  46. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  47. }
  48. public override byte[] GetParameters(bool isUnicode)
  49. {
  50. int length = 12;
  51. if (isUnicode)
  52. {
  53. length += FileName.Length * 2 + 2;
  54. }
  55. else
  56. {
  57. length += FileName.Length + 1;
  58. }
  59. byte[] parameters = new byte[length];
  60. LittleEndianWriter.WriteUInt16(parameters, 0, SID);
  61. LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount);
  62. LittleEndianWriter.WriteUInt16(parameters, 4, (ushort)InformationLevel);
  63. LittleEndianWriter.WriteUInt32(parameters, 6, ResumeKey);
  64. LittleEndianWriter.WriteUInt16(parameters, 10, (ushort)Flags);
  65. SMB1Helper.WriteSMBString(parameters, 12, isUnicode, FileName);
  66. return parameters;
  67. }
  68. public override byte[] GetData(bool isUnicode)
  69. {
  70. if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  71. {
  72. return GetExtendedAttributeList.GetBytes();
  73. }
  74. else
  75. {
  76. return new byte[0];
  77. }
  78. }
  79. public override Transaction2SubcommandName SubcommandName
  80. {
  81. get
  82. {
  83. return Transaction2SubcommandName.TRANS2_FIND_NEXT2;
  84. }
  85. }
  86. }
  87. }