TransactionQueryNamedPipeInfoResponse.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 2014-2019 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. /// TRANS_QUERY_NMPIPE_INFO Response
  15. /// </summary>
  16. public class TransactionQueryNamedPipeInfoResponse : TransactionSubcommand
  17. {
  18. public const int ParametersLength = 0;
  19. // Data:
  20. public ushort OutputBufferSize;
  21. public ushort InputBufferSize;
  22. public byte MaximumInstances;
  23. public byte CurrentInstances;
  24. public byte PipeNameLength;
  25. public string PipeName; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  26. public TransactionQueryNamedPipeInfoResponse() : base()
  27. {}
  28. public TransactionQueryNamedPipeInfoResponse(byte[] data, bool isUnicode) : base()
  29. {
  30. OutputBufferSize = LittleEndianConverter.ToUInt16(data, 0);
  31. InputBufferSize = LittleEndianConverter.ToUInt16(data, 2);
  32. MaximumInstances = ByteReader.ReadByte(data, 4);
  33. CurrentInstances = ByteReader.ReadByte(data, 5);
  34. PipeNameLength = ByteReader.ReadByte(data, 6);
  35. // Note: Trans_Parameters is aligned to 4 byte boundary
  36. PipeName = SMB1Helper.ReadSMBString(data, 8, isUnicode);
  37. }
  38. public override byte[] GetData(bool isUnicode)
  39. {
  40. int length = 8;
  41. if (isUnicode)
  42. {
  43. length += PipeName.Length * 2 + 2;
  44. }
  45. else
  46. {
  47. length += PipeName.Length + 1;
  48. }
  49. byte[] data = new byte[length];
  50. LittleEndianWriter.WriteUInt16(data, 0, OutputBufferSize);
  51. LittleEndianWriter.WriteUInt16(data, 2, InputBufferSize);
  52. ByteWriter.WriteByte(data, 4, MaximumInstances);
  53. ByteWriter.WriteByte(data, 5, CurrentInstances);
  54. ByteWriter.WriteByte(data, 6, PipeNameLength);
  55. SMB1Helper.WriteSMBString(data, 8, isUnicode, PipeName);
  56. return data;
  57. }
  58. public override TransactionSubcommandName SubcommandName
  59. {
  60. get
  61. {
  62. return TransactionSubcommandName.TRANS_QUERY_NMPIPE_INFO;
  63. }
  64. }
  65. }
  66. }