Transaction2QueryFileInformationRequest.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public const int ParametersLength = 4;
  18. // Parameters:
  19. public ushort FID;
  20. public QueryInformationLevel InformationLevel;
  21. // Data:
  22. public FullExtendedAttributeList GetExtendedAttributeList; // Used with QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  23. public Transaction2QueryFileInformationRequest() : base()
  24. {
  25. GetExtendedAttributeList = new FullExtendedAttributeList();
  26. }
  27. public Transaction2QueryFileInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  28. {
  29. FID = LittleEndianConverter.ToUInt16(parameters, 0);
  30. InformationLevel = (QueryInformationLevel)LittleEndianConverter.ToUInt16(parameters, 2);
  31. if (InformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  32. {
  33. GetExtendedAttributeList = new FullExtendedAttributeList(data, 0);
  34. }
  35. }
  36. public override byte[] GetSetup()
  37. {
  38. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  39. }
  40. public override byte[] GetParameters(bool isUnicode)
  41. {
  42. byte[] parameters = new byte[ParametersLength];
  43. LittleEndianWriter.WriteUInt16(parameters, 0, FID);
  44. LittleEndianWriter.WriteUInt16(parameters, 2, (ushort)InformationLevel);
  45. return parameters;
  46. }
  47. public override byte[] GetData(bool isUnicode)
  48. {
  49. if (InformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  50. {
  51. return GetExtendedAttributeList.GetBytes();
  52. }
  53. else
  54. {
  55. return new byte[0];
  56. }
  57. }
  58. public override Transaction2SubcommandName SubcommandName
  59. {
  60. get
  61. {
  62. return Transaction2SubcommandName.TRANS2_QUERY_FILE_INFORMATION;
  63. }
  64. }
  65. }
  66. }