Transaction2SetFSInformationRequest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 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_FS_INFORMATION Request
  14. /// </summary>
  15. public class Transaction2SetFSInformationRequest : Transaction2Subcommand
  16. {
  17. private const ushort SMB_INFO_PASSTHROUGH = 0x03E8;
  18. public const int ParametersLength = 4;
  19. // Parameters:
  20. public ushort FID;
  21. public ushort InformationLevel; // This field MUST be a pass-through Information Level.
  22. // Data:
  23. public byte[] InformationBytes;
  24. public Transaction2SetFSInformationRequest() : base()
  25. {
  26. }
  27. public Transaction2SetFSInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  28. {
  29. FID = LittleEndianConverter.ToUInt16(parameters, 0);
  30. InformationLevel = LittleEndianConverter.ToUInt16(parameters, 2);
  31. InformationBytes = data;
  32. }
  33. public override byte[] GetSetup()
  34. {
  35. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  36. }
  37. public override byte[] GetParameters(bool isUnicode)
  38. {
  39. byte[] parameters = new byte[ParametersLength];
  40. LittleEndianWriter.WriteUInt16(parameters, 0, FID);
  41. LittleEndianWriter.WriteUInt16(parameters, 2, InformationLevel);
  42. return parameters;
  43. }
  44. public override byte[] GetData(bool isUnicode)
  45. {
  46. return InformationBytes;
  47. }
  48. public bool IsPassthroughInformationLevel
  49. {
  50. get
  51. {
  52. return (InformationLevel >= SMB_INFO_PASSTHROUGH);
  53. }
  54. }
  55. public FileSystemInformationClass FileSystemInformationClass
  56. {
  57. get
  58. {
  59. return (FileSystemInformationClass)(InformationLevel - SMB_INFO_PASSTHROUGH);
  60. }
  61. set
  62. {
  63. InformationLevel = (ushort)((ushort)value + SMB_INFO_PASSTHROUGH);
  64. }
  65. }
  66. /// <remarks>
  67. /// Support for pass-through Information Levels must be enabled.
  68. /// </remarks>
  69. public void SetFileSystemInformation(FileSystemInformation information)
  70. {
  71. FileSystemInformationClass = information.FileSystemInformationClass;
  72. InformationBytes = information.GetBytes();
  73. }
  74. public override Transaction2SubcommandName SubcommandName
  75. {
  76. get
  77. {
  78. return Transaction2SubcommandName.TRANS2_SET_FS_INFORMATION;
  79. }
  80. }
  81. }
  82. }