Transaction2SetPathInformationRequest.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_SET_PATH_INFORMATION Request
  15. /// </summary>
  16. public class Transaction2SetPathInformationRequest : Transaction2Subcommand
  17. {
  18. public const int ParametersFixedLength = 6;
  19. // Parameters:
  20. public SetInformationLevel InformationLevel;
  21. public uint Reserved;
  22. public string FileName; // SMB_STRING
  23. // Data:
  24. public SetInformation SetInfo;
  25. public Transaction2SetPathInformationRequest() : base()
  26. {}
  27. public Transaction2SetPathInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
  28. {
  29. InformationLevel = (SetInformationLevel)LittleEndianConverter.ToUInt16(parameters, 0);
  30. Reserved = LittleEndianConverter.ToUInt32(parameters, 2);
  31. FileName = SMB1Helper.ReadSMBString(parameters, 6, isUnicode);
  32. }
  33. public override byte[] GetSetup()
  34. {
  35. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  36. }
  37. public override byte[] GetParameters(bool isUnicode)
  38. {
  39. int length = ParametersFixedLength;
  40. if (isUnicode)
  41. {
  42. length += FileName.Length * 2 + 2;
  43. }
  44. else
  45. {
  46. length += FileName.Length + 1;
  47. }
  48. byte[] parameters = new byte[length];
  49. LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)InformationLevel);
  50. LittleEndianWriter.WriteUInt32(parameters, 2, Reserved);
  51. SMB1Helper.WriteSMBString(parameters, 6, isUnicode, FileName);
  52. return parameters;
  53. }
  54. public override byte[] GetData(bool isUnicode)
  55. {
  56. return SetInfo.GetBytes();
  57. }
  58. public override Transaction2SubcommandName SubcommandName
  59. {
  60. get
  61. {
  62. return Transaction2SubcommandName.TRANS2_SET_PATH_INFORMATION;
  63. }
  64. }
  65. }
  66. }