TransactionSecondaryRequest.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /// SMB_COM_TRANSACTION_SECONDARY Request
  15. /// </summary>
  16. public class TransactionSecondaryRequest : SMB1Command
  17. {
  18. public const int SMBParametersLength = 16;
  19. // Parameters:
  20. public ushort TotalParameterCount;
  21. public ushort TotalDataCount;
  22. protected ushort ParameterCount;
  23. protected ushort ParameterOffset;
  24. public ushort ParameterDisplacement;
  25. protected ushort DataCount;
  26. protected ushort DataOffset;
  27. public ushort DataDisplacement;
  28. // Data:
  29. // Padding (alignment to 4 byte boundary)
  30. public byte[] TransParameters; // Trans_Parameters
  31. // Padding (alignment to 4 byte boundary)
  32. public byte[] TransData; // Trans_Data
  33. public TransactionSecondaryRequest() : base()
  34. {
  35. }
  36. public TransactionSecondaryRequest(byte[] buffer, int offset) : base(buffer, offset, false)
  37. {
  38. TotalParameterCount = LittleEndianConverter.ToUInt16(this.SMBData, 0);
  39. TotalDataCount = LittleEndianConverter.ToUInt16(this.SMBData, 2);
  40. ParameterCount = LittleEndianConverter.ToUInt16(this.SMBData, 4);
  41. ParameterOffset = LittleEndianConverter.ToUInt16(this.SMBData, 6);
  42. ParameterDisplacement = LittleEndianConverter.ToUInt16(this.SMBData, 8);
  43. DataCount = LittleEndianConverter.ToUInt16(this.SMBData, 10);
  44. DataOffset = LittleEndianConverter.ToUInt16(this.SMBData, 12);
  45. DataDisplacement = LittleEndianConverter.ToUInt16(this.SMBData, 14);
  46. TransParameters = ByteReader.ReadBytes(buffer, ParameterOffset, ParameterCount);
  47. TransData = ByteReader.ReadBytes(buffer, DataOffset, DataCount);
  48. }
  49. public override byte[] GetBytes(bool isUnicode)
  50. {
  51. ParameterCount = (ushort)TransParameters.Length;
  52. DataCount = (ushort)TransData.Length;
  53. // WordCount + ByteCount are additional 3 bytes
  54. ParameterOffset = (ushort)(SMB1Header.Length + 3 + SMBParametersLength);
  55. int padding1 = (4 - (ParameterOffset % 4)) % 4;
  56. ParameterOffset += (ushort)padding1;
  57. DataOffset = (ushort)(ParameterOffset + ParameterCount);
  58. int padding2 = (4 - (DataOffset % 4)) % 4;
  59. DataOffset += (ushort)padding2;
  60. this.SMBParameters = new byte[SMBParametersLength];
  61. LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, TotalParameterCount);
  62. LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, TotalDataCount);
  63. LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, ParameterCount);
  64. LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, ParameterOffset);
  65. LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, ParameterDisplacement);
  66. LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, DataCount);
  67. LittleEndianWriter.WriteUInt16(this.SMBParameters, 12, DataOffset);
  68. LittleEndianWriter.WriteUInt16(this.SMBParameters, 14, DataDisplacement);
  69. this.SMBData = new byte[ParameterCount + DataCount + padding1 + padding2];
  70. ByteWriter.WriteBytes(this.SMBData, padding1, TransParameters);
  71. ByteWriter.WriteBytes(this.SMBData, padding1 + ParameterCount + padding2, TransData);
  72. return base.GetBytes(isUnicode);
  73. }
  74. public override CommandName CommandName
  75. {
  76. get
  77. {
  78. return CommandName.SMB_COM_TRANSACTION_SECONDARY;
  79. }
  80. }
  81. }
  82. }