QueryInfoResponse.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Response
  14. /// </summary>
  15. public class QueryInfoResponse : SMB2Command
  16. {
  17. public const int FixedSize = 8;
  18. public const int DeclaredSize = 9;
  19. private ushort StructureSize;
  20. private ushort OutputBufferOffset;
  21. private uint OutputBufferLength;
  22. public byte[] OutputBuffer = new byte[0];
  23. public QueryInfoResponse() : base(SMB2CommandName.QueryInfo)
  24. {
  25. Header.IsResponse = true;
  26. StructureSize = DeclaredSize;
  27. }
  28. public QueryInfoResponse(byte[] buffer, int offset) : base(buffer, offset)
  29. {
  30. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  31. OutputBufferOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  32. OutputBufferLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  33. OutputBuffer = ByteReader.ReadBytes(buffer, offset + OutputBufferOffset, (int)OutputBufferLength);
  34. }
  35. public override void WriteCommandBytes(byte[] buffer, int offset)
  36. {
  37. OutputBufferOffset = 0;
  38. OutputBufferLength = (uint)OutputBuffer.Length;
  39. if (OutputBuffer.Length > 0)
  40. {
  41. OutputBufferOffset = SMB2Header.Length + FixedSize;
  42. }
  43. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  44. LittleEndianWriter.WriteUInt16(buffer, offset + 2, OutputBufferOffset);
  45. LittleEndianWriter.WriteUInt32(buffer, offset + 4, OutputBufferLength);
  46. ByteWriter.WriteBytes(buffer, offset + FixedSize, OutputBuffer);
  47. }
  48. public FileInformation GetFileInformation(FileInformationClass informationClass)
  49. {
  50. return FileInformation.GetFileInformation(OutputBuffer, 0, informationClass);
  51. }
  52. public FileSystemInformation GetFileSystemInformation(FileSystemInformationClass informationClass)
  53. {
  54. return FileSystemInformation.GetFileSystemInformation(OutputBuffer, 0, informationClass);
  55. }
  56. public SecurityDescriptor GetSecurityInformation()
  57. {
  58. return new SecurityDescriptor(OutputBuffer, 0);
  59. }
  60. public void SetFileInformation(FileInformation fileInformation)
  61. {
  62. OutputBuffer = fileInformation.GetBytes();
  63. }
  64. public void SetFileSystemInformation(FileSystemInformation fileSystemInformation)
  65. {
  66. OutputBuffer = fileSystemInformation.GetBytes();
  67. }
  68. public void SetSecurityInformation(SecurityDescriptor securityDescriptor)
  69. {
  70. OutputBuffer = securityDescriptor.GetBytes();
  71. }
  72. public override int CommandLength
  73. {
  74. get
  75. {
  76. return FixedSize + OutputBuffer.Length;
  77. }
  78. }
  79. }
  80. }