Transaction2SecondaryRequest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_TRANSACTION2_SECONDARY Request
  15. /// </summary>
  16. public class Transaction2SecondaryRequest : TransactionSecondaryRequest
  17. {
  18. public new const int SMBParametersLength = 18;
  19. // Parameters:
  20. public ushort FID;
  21. public Transaction2SecondaryRequest() : base()
  22. {
  23. }
  24. public Transaction2SecondaryRequest(byte[] buffer, int offset) : base(buffer, offset)
  25. {
  26. TotalParameterCount = LittleEndianConverter.ToUInt16(this.SMBData, 0);
  27. TotalDataCount = LittleEndianConverter.ToUInt16(this.SMBData, 2);
  28. ParameterCount = LittleEndianConverter.ToUInt16(this.SMBData, 4);
  29. ParameterOffset = LittleEndianConverter.ToUInt16(this.SMBData, 6);
  30. ParameterDisplacement = LittleEndianConverter.ToUInt16(this.SMBData, 8);
  31. DataCount = LittleEndianConverter.ToUInt16(this.SMBData, 10);
  32. DataOffset = LittleEndianConverter.ToUInt16(this.SMBData, 12);
  33. DataDisplacement = LittleEndianConverter.ToUInt16(this.SMBData, 14);
  34. FID = LittleEndianConverter.ToUInt16(this.SMBData, 16);
  35. TransParameters = ByteReader.ReadBytes(buffer, ParameterOffset, ParameterCount);
  36. TransData = ByteReader.ReadBytes(buffer, DataOffset, DataCount);
  37. }
  38. public override byte[] GetBytes(bool isUnicode)
  39. {
  40. ParameterCount = (ushort)TransParameters.Length;
  41. DataCount = (ushort)TransData.Length;
  42. ParameterOffset = (ushort)(SMB1Header.Length + SMBParametersLength);
  43. int padding1 = (4 - (ParameterOffset % 4)) % 4;
  44. ParameterOffset += (ushort)padding1;
  45. DataOffset = (ushort)(ParameterOffset + ParameterCount);
  46. int padding2 = (4 - (DataOffset % 4)) % 4;
  47. DataOffset += (ushort)padding2;
  48. this.SMBParameters = new byte[SMBParametersLength];
  49. LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, TotalParameterCount);
  50. LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, TotalDataCount);
  51. LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, ParameterCount);
  52. LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, ParameterOffset);
  53. LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, ParameterDisplacement);
  54. LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, DataCount);
  55. LittleEndianWriter.WriteUInt16(this.SMBParameters, 12, DataOffset);
  56. LittleEndianWriter.WriteUInt16(this.SMBParameters, 14, DataDisplacement);
  57. LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, FID);
  58. this.SMBData = new byte[ParameterCount + DataCount + padding1 + padding2];
  59. ByteWriter.WriteBytes(this.SMBData, padding1, TransParameters);
  60. ByteWriter.WriteBytes(this.SMBData, padding1 + ParameterCount + padding2, TransData);
  61. return base.GetBytes(isUnicode);
  62. }
  63. public override CommandName CommandName
  64. {
  65. get
  66. {
  67. return CommandName.SMB_COM_TRANSACTION2_SECONDARY;
  68. }
  69. }
  70. }
  71. }