Transaction2SetFileInformationRequest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_FILE_INFORMATION Request
  14. /// </summary>
  15. public class Transaction2SetFileInformationRequest : Transaction2Subcommand
  16. {
  17. private const ushort SMB_INFO_PASSTHROUGH = 0x03E8;
  18. public const int ParametersLength = 6;
  19. // Parameters:
  20. public ushort FID;
  21. public ushort InformationLevel;
  22. public ushort Reserved;
  23. // Data:
  24. public byte[] InformationBytes;
  25. public Transaction2SetFileInformationRequest() : base()
  26. {
  27. }
  28. public Transaction2SetFileInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  29. {
  30. FID = LittleEndianConverter.ToUInt16(parameters, 0);
  31. InformationLevel = LittleEndianConverter.ToUInt16(parameters, 2);
  32. Reserved = LittleEndianConverter.ToUInt16(parameters, 4);
  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. byte[] parameters = new byte[ParametersLength];
  42. LittleEndianWriter.WriteUInt16(parameters, 0, FID);
  43. LittleEndianWriter.WriteUInt16(parameters, 2, InformationLevel);
  44. LittleEndianWriter.WriteUInt16(parameters, 4, Reserved);
  45. return parameters;
  46. }
  47. public override byte[] GetData(bool isUnicode)
  48. {
  49. return InformationBytes;
  50. }
  51. public bool IsPassthroughInformationLevel
  52. {
  53. get
  54. {
  55. return (InformationLevel >= SMB_INFO_PASSTHROUGH);
  56. }
  57. }
  58. public SetInformationLevel SetInformationLevel
  59. {
  60. get
  61. {
  62. return (SetInformationLevel)InformationLevel;
  63. }
  64. set
  65. {
  66. InformationLevel = (ushort)value;
  67. }
  68. }
  69. public FileInformationClass FileInformationClass
  70. {
  71. get
  72. {
  73. return (FileInformationClass)(InformationLevel - SMB_INFO_PASSTHROUGH);
  74. }
  75. set
  76. {
  77. InformationLevel = (ushort)((ushort)value + SMB_INFO_PASSTHROUGH);
  78. }
  79. }
  80. public void SetInformation(SetInformation information)
  81. {
  82. SetInformationLevel = information.InformationLevel;
  83. InformationBytes = information.GetBytes();
  84. }
  85. /// <remarks>
  86. /// Support for pass-through Information Levels must be enabled.
  87. /// </remarks>
  88. public void SetInformation(FileInformation information)
  89. {
  90. FileInformationClass = information.FileInformationClass;
  91. InformationBytes = information.GetBytes();
  92. }
  93. public override Transaction2SubcommandName SubcommandName
  94. {
  95. get
  96. {
  97. return Transaction2SubcommandName.TRANS2_SET_FILE_INFORMATION;
  98. }
  99. }
  100. }
  101. }