Transaction2SetPathInformationRequest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_SET_PATH_INFORMATION Request
  14. /// </summary>
  15. public class Transaction2SetPathInformationRequest : 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 byte[] InformationBytes;
  25. public Transaction2SetPathInformationRequest() : base()
  26. {
  27. }
  28. public Transaction2SetPathInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  29. {
  30. InformationLevel = LittleEndianConverter.ToUInt16(parameters, 0);
  31. Reserved = LittleEndianConverter.ToUInt32(parameters, 2);
  32. FileName = SMB1Helper.ReadSMBString(parameters, 6, isUnicode);
  33. InformationBytes = data;
  34. }
  35. public override byte[] GetSetup()
  36. {
  37. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  38. }
  39. public override byte[] GetParameters(bool isUnicode)
  40. {
  41. int length = ParametersFixedLength;
  42. if (isUnicode)
  43. {
  44. length += FileName.Length * 2 + 2;
  45. }
  46. else
  47. {
  48. length += FileName.Length + 1;
  49. }
  50. byte[] parameters = new byte[length];
  51. LittleEndianWriter.WriteUInt16(parameters, 0, InformationLevel);
  52. LittleEndianWriter.WriteUInt32(parameters, 2, Reserved);
  53. SMB1Helper.WriteSMBString(parameters, 6, isUnicode, FileName);
  54. return parameters;
  55. }
  56. public override byte[] GetData(bool isUnicode)
  57. {
  58. return InformationBytes;
  59. }
  60. public bool IsPassthroughInformationLevel
  61. {
  62. get
  63. {
  64. return (InformationLevel >= SMB_INFO_PASSTHROUGH);
  65. }
  66. }
  67. public SetInformationLevel SetInformationLevel
  68. {
  69. get
  70. {
  71. return (SetInformationLevel)InformationLevel;
  72. }
  73. set
  74. {
  75. InformationLevel = (ushort)value;
  76. }
  77. }
  78. public FileInformationClass FileInformationClass
  79. {
  80. get
  81. {
  82. return (FileInformationClass)(InformationLevel - SMB_INFO_PASSTHROUGH);
  83. }
  84. set
  85. {
  86. InformationLevel = (ushort)((ushort)value + SMB_INFO_PASSTHROUGH);
  87. }
  88. }
  89. public void SetInformation(SetInformation information)
  90. {
  91. SetInformationLevel = information.InformationLevel;
  92. InformationBytes = information.GetBytes();
  93. }
  94. /// <remarks>
  95. /// Support for pass-through Information Levels must be enabled.
  96. /// </remarks>
  97. public void SetInformation(FileInformation information)
  98. {
  99. FileInformationClass = information.FileInformationClass;
  100. InformationBytes = information.GetBytes();
  101. }
  102. public override Transaction2SubcommandName SubcommandName
  103. {
  104. get
  105. {
  106. return Transaction2SubcommandName.TRANS2_SET_PATH_INFORMATION;
  107. }
  108. }
  109. }
  110. }