Transaction2QueryPathInformationRequest.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 Utilities;
  10. namespace SMBLibrary.SMB1
  11. {
  12. /// <summary>
  13. /// TRANS2_QUERY_PATH_INFORMATION Request
  14. /// </summary>
  15. public class Transaction2QueryPathInformationRequest : Transaction2Subcommand
  16. {
  17. private const ushort SMB_INFO_PASSTHROUGH = 0x03E8;
  18. public const int ParametersFixedLength = 6;
  19. // Parameters:
  20. public ushort InformationLevel;
  21. public uint Reserved;
  22. public string FileName; // SMB_STRING
  23. // Data:
  24. public FullExtendedAttributeList GetExtendedAttributeList; // Used with QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  25. public Transaction2QueryPathInformationRequest() : base()
  26. {
  27. GetExtendedAttributeList = new FullExtendedAttributeList();
  28. }
  29. public Transaction2QueryPathInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  30. {
  31. InformationLevel = LittleEndianConverter.ToUInt16(parameters, 0);
  32. Reserved = LittleEndianConverter.ToUInt32(parameters, 4);
  33. FileName = SMB1Helper.ReadSMBString(parameters, 6, isUnicode);
  34. if (!IsPassthroughInformationLevel && QueryInformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  35. {
  36. GetExtendedAttributeList = new FullExtendedAttributeList(data, 0);
  37. }
  38. }
  39. public override byte[] GetSetup()
  40. {
  41. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  42. }
  43. public override byte[] GetParameters(bool isUnicode)
  44. {
  45. int length = ParametersFixedLength;
  46. if (isUnicode)
  47. {
  48. length += FileName.Length * 2 + 2;
  49. }
  50. else
  51. {
  52. length += FileName.Length + 1;
  53. }
  54. byte[] parameters = new byte[length];
  55. LittleEndianWriter.WriteUInt16(parameters, 0, InformationLevel);
  56. LittleEndianWriter.WriteUInt32(parameters, 2, Reserved);
  57. SMB1Helper.WriteSMBString(parameters, 6, isUnicode, FileName);
  58. return parameters;
  59. }
  60. public override byte[] GetData(bool isUnicode)
  61. {
  62. if (!IsPassthroughInformationLevel && QueryInformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  63. {
  64. return GetExtendedAttributeList.GetBytes();
  65. }
  66. else
  67. {
  68. return new byte[0];
  69. }
  70. }
  71. public bool IsPassthroughInformationLevel
  72. {
  73. get
  74. {
  75. return (InformationLevel >= SMB_INFO_PASSTHROUGH);
  76. }
  77. }
  78. public QueryInformationLevel QueryInformationLevel
  79. {
  80. get
  81. {
  82. return (QueryInformationLevel)InformationLevel;
  83. }
  84. set
  85. {
  86. InformationLevel = (ushort)value;
  87. }
  88. }
  89. public FileInformationClass FileInformationClass
  90. {
  91. get
  92. {
  93. return (FileInformationClass)(InformationLevel - SMB_INFO_PASSTHROUGH);
  94. }
  95. set
  96. {
  97. InformationLevel = (ushort)((ushort)value + SMB_INFO_PASSTHROUGH);
  98. }
  99. }
  100. public override Transaction2SubcommandName SubcommandName
  101. {
  102. get
  103. {
  104. return Transaction2SubcommandName.TRANS2_QUERY_PATH_INFORMATION;
  105. }
  106. }
  107. }
  108. }