Transaction2QueryFileInformationRequest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_FILE_INFORMATION Request
  14. /// </summary>
  15. public class Transaction2QueryFileInformationRequest : Transaction2Subcommand
  16. {
  17. private const ushort SMB_INFO_PASSTHROUGH = 0x03E8;
  18. public const int ParametersLength = 4;
  19. // Parameters:
  20. public ushort FID;
  21. public ushort InformationLevel;
  22. // Data:
  23. public FullExtendedAttributeList GetExtendedAttributeList; // Used with QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  24. public Transaction2QueryFileInformationRequest() : base()
  25. {
  26. GetExtendedAttributeList = new FullExtendedAttributeList();
  27. }
  28. public Transaction2QueryFileInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  29. {
  30. FID = LittleEndianConverter.ToUInt16(parameters, 0);
  31. InformationLevel = LittleEndianConverter.ToUInt16(parameters, 2);
  32. if (!IsPassthroughInformationLevel && QueryInformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  33. {
  34. GetExtendedAttributeList = new FullExtendedAttributeList(data, 0);
  35. }
  36. }
  37. public override byte[] GetSetup()
  38. {
  39. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  40. }
  41. public override byte[] GetParameters(bool isUnicode)
  42. {
  43. byte[] parameters = new byte[ParametersLength];
  44. LittleEndianWriter.WriteUInt16(parameters, 0, FID);
  45. LittleEndianWriter.WriteUInt16(parameters, 2, InformationLevel);
  46. return parameters;
  47. }
  48. public override byte[] GetData(bool isUnicode)
  49. {
  50. if (!IsPassthroughInformationLevel && QueryInformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  51. {
  52. return GetExtendedAttributeList.GetBytes();
  53. }
  54. else
  55. {
  56. return new byte[0];
  57. }
  58. }
  59. public bool IsPassthroughInformationLevel
  60. {
  61. get
  62. {
  63. return (InformationLevel >= SMB_INFO_PASSTHROUGH);
  64. }
  65. }
  66. public QueryInformationLevel QueryInformationLevel
  67. {
  68. get
  69. {
  70. return (QueryInformationLevel)InformationLevel;
  71. }
  72. set
  73. {
  74. InformationLevel = (ushort)value;
  75. }
  76. }
  77. public FileInformationClass FileInformationClass
  78. {
  79. get
  80. {
  81. return (FileInformationClass)(InformationLevel - SMB_INFO_PASSTHROUGH);
  82. }
  83. set
  84. {
  85. InformationLevel = (ushort)((ushort)value + SMB_INFO_PASSTHROUGH);
  86. }
  87. }
  88. public override Transaction2SubcommandName SubcommandName
  89. {
  90. get
  91. {
  92. return Transaction2SubcommandName.TRANS2_QUERY_FILE_INFORMATION;
  93. }
  94. }
  95. }
  96. }