Transaction2QueryPathInformationRequest.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Parameters:
  18. public QueryInformationLevel InformationLevel;
  19. public uint Reserved;
  20. public string FileName; // SMB_STRING
  21. // Data:
  22. public FullExtendedAttributeList GetExtendedAttributeList; // Used with QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST
  23. public Transaction2QueryPathInformationRequest() : base()
  24. {
  25. GetExtendedAttributeList = new FullExtendedAttributeList();
  26. }
  27. public Transaction2QueryPathInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  28. {
  29. InformationLevel = (QueryInformationLevel)LittleEndianConverter.ToUInt16(parameters, 0);
  30. Reserved = LittleEndianConverter.ToUInt32(parameters, 4);
  31. FileName = SMB1Helper.ReadSMBString(parameters, 6, isUnicode);
  32. if (InformationLevel == 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. int length = 6;
  44. if (isUnicode)
  45. {
  46. length += FileName.Length * 2 + 2;
  47. }
  48. else
  49. {
  50. length += FileName.Length + 1;
  51. }
  52. byte[] parameters = new byte[length];
  53. LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)InformationLevel);
  54. LittleEndianWriter.WriteUInt32(parameters, 2, Reserved);
  55. SMB1Helper.WriteSMBString(parameters, 6, isUnicode, FileName);
  56. return parameters;
  57. }
  58. public override byte[] GetData(bool isUnicode)
  59. {
  60. if (InformationLevel == QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
  61. {
  62. return GetExtendedAttributeList.GetBytes();
  63. }
  64. else
  65. {
  66. return new byte[0];
  67. }
  68. }
  69. public override Transaction2SubcommandName SubcommandName
  70. {
  71. get
  72. {
  73. return Transaction2SubcommandName.TRANS2_QUERY_PATH_INFORMATION;
  74. }
  75. }
  76. }
  77. }