SetInfoRequest.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.SMB2
  11. {
  12. /// <summary>
  13. /// SMB2 SET_INFO Request
  14. /// </summary>
  15. public class SetInfoRequest : SMB2Command
  16. {
  17. public const int FixedSize = 32;
  18. public const int DeclaredSize = 33;
  19. private ushort StructureSize;
  20. public InfoType InfoType;
  21. private byte FileInfoClass;
  22. public uint BufferLength;
  23. private ushort BufferOffset;
  24. public ushort Reserved;
  25. public uint AdditionalInformation;
  26. public FileID FileId;
  27. public byte[] Buffer = new byte[0];
  28. public SetInfoRequest() : base(SMB2CommandName.SetInfo)
  29. {
  30. StructureSize = DeclaredSize;
  31. }
  32. public SetInfoRequest(byte[] buffer, int offset) : base(buffer, offset)
  33. {
  34. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  35. InfoType = (InfoType)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2);
  36. FileInfoClass = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
  37. BufferLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  38. BufferOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 8);
  39. Reserved = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 10);
  40. AdditionalInformation = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 12);
  41. FileId = new FileID(buffer, offset + SMB2Header.Length + 16);
  42. Buffer = ByteReader.ReadBytes(buffer, offset + BufferOffset, (int)BufferLength);
  43. }
  44. public override void WriteCommandBytes(byte[] buffer, int offset)
  45. {
  46. BufferOffset = 0;
  47. BufferLength = (uint)Buffer.Length;
  48. if (Buffer.Length > 0)
  49. {
  50. BufferOffset = SMB2Header.Length + FixedSize;
  51. }
  52. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  53. ByteWriter.WriteByte(buffer, offset + 2, (byte)InfoType);
  54. ByteWriter.WriteByte(buffer, offset + 3, FileInfoClass);
  55. LittleEndianWriter.WriteUInt32(buffer, offset + 4, BufferLength);
  56. LittleEndianWriter.WriteUInt16(buffer, offset + 8, BufferOffset);
  57. LittleEndianWriter.WriteUInt16(buffer, offset + 10, Reserved);
  58. LittleEndianWriter.WriteUInt32(buffer, offset + 12, AdditionalInformation);
  59. FileId.WriteBytes(buffer, offset + 16);
  60. ByteWriter.WriteBytes(buffer, offset + FixedSize, Buffer);
  61. }
  62. public FileInformationClass FileInformationClass
  63. {
  64. get
  65. {
  66. return (FileInformationClass)FileInfoClass;
  67. }
  68. set
  69. {
  70. FileInfoClass = (byte)value;
  71. }
  72. }
  73. public FileSystemInformationClass FileSystemInformationClass
  74. {
  75. get
  76. {
  77. return (FileSystemInformationClass)FileInfoClass;
  78. }
  79. set
  80. {
  81. FileInfoClass = (byte)value;
  82. }
  83. }
  84. public SecurityInformation SecurityInformation
  85. {
  86. get
  87. {
  88. return (SecurityInformation)AdditionalInformation;
  89. }
  90. set
  91. {
  92. AdditionalInformation = (uint)value;
  93. }
  94. }
  95. public void SetFileInformation(FileInformation fileInformation)
  96. {
  97. Buffer = fileInformation.GetBytes();
  98. }
  99. public void SetFileSystemInformation(FileSystemInformation fileSystemInformation)
  100. {
  101. Buffer = fileSystemInformation.GetBytes();
  102. }
  103. public void SetSecurityInformation(SecurityDescriptor securityDescriptor)
  104. {
  105. Buffer = securityDescriptor.GetBytes();
  106. }
  107. public override int CommandLength
  108. {
  109. get
  110. {
  111. return FixedSize + Buffer.Length;
  112. }
  113. }
  114. }
  115. }