Transaction2QueryPathInformationRequest.cs 2.9 KB

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