QueryInfoRequest.cs 4.7 KB

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