Transaction2FindFirst2Request.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_FIRST2 Request
  15. /// </summary>
  16. public class Transaction2FindFirst2Request : Transaction2Subcommand
  17. {
  18. // Parameters:
  19. public SMBFileAttributes SearchAttributes;
  20. public ushort SearchCount;
  21. public FindFlags Flags;
  22. public FindInformationLevel InformationLevel;
  23. public SearchStorageType SearchStorageType;
  24. public string FileName; // SMB_STRING
  25. // Data:
  26. public ExtendedAttributeNameList GetExtendedAttributeList; // Used with FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  27. public Transaction2FindFirst2Request() : base()
  28. {
  29. GetExtendedAttributeList = new ExtendedAttributeNameList();
  30. }
  31. public Transaction2FindFirst2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
  32. {
  33. SearchAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 0);
  34. SearchCount = LittleEndianConverter.ToUInt16(parameters, 2);
  35. Flags = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 4);
  36. InformationLevel = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 6);
  37. SearchStorageType = (SearchStorageType)LittleEndianConverter.ToUInt32(parameters, 8);
  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, (ushort)SearchAttributes);
  61. LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount);
  62. LittleEndianWriter.WriteUInt16(parameters, 4, (ushort)Flags);
  63. LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)InformationLevel);
  64. LittleEndianWriter.WriteUInt32(parameters, 8, (uint)SearchStorageType);
  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 bool CloseAfterRequest
  80. {
  81. get
  82. {
  83. return ((this.Flags & FindFlags.SMB_FIND_CLOSE_AFTER_REQUEST) > 0);
  84. }
  85. set
  86. {
  87. if (value)
  88. {
  89. this.Flags |= FindFlags.SMB_FIND_CLOSE_AFTER_REQUEST;
  90. }
  91. else
  92. {
  93. this.Flags &= ~FindFlags.SMB_FIND_CLOSE_AFTER_REQUEST;
  94. }
  95. }
  96. }
  97. public bool CloseAtEndOfSearch
  98. {
  99. get
  100. {
  101. return ((this.Flags & FindFlags.SMB_FIND_CLOSE_AT_EOS) > 0);
  102. }
  103. set
  104. {
  105. if (value)
  106. {
  107. this.Flags |= FindFlags.SMB_FIND_CLOSE_AT_EOS;
  108. }
  109. else
  110. {
  111. this.Flags &= ~FindFlags.SMB_FIND_CLOSE_AT_EOS;
  112. }
  113. }
  114. }
  115. public override Transaction2SubcommandName SubcommandName
  116. {
  117. get
  118. {
  119. return Transaction2SubcommandName.TRANS2_FIND_FIRST2;
  120. }
  121. }
  122. }
  123. }