BindPDU.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2014-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 System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.RPC
  12. {
  13. /// <summary>
  14. /// rpcconn_bind_hdr_t
  15. /// </summary>
  16. public class BindPDU : RPCPDU
  17. {
  18. public const int BindFieldsFixedLength = 8;
  19. public ushort MaxTransmitFragmentSize; // max_xmit_frag
  20. public ushort MaxReceiveFragmentSize; // max_recv_frag
  21. public uint AssociationGroupID; // assoc_group_id
  22. public ContextList ContextList;
  23. public byte[] AuthVerifier;
  24. public BindPDU() : base()
  25. {
  26. PacketType = PacketTypeName.Bind;
  27. ContextList = new ContextList();
  28. AuthVerifier = new byte[0];
  29. }
  30. public BindPDU(byte[] buffer, int offset) : base(buffer, offset)
  31. {
  32. offset += CommonFieldsLength;
  33. MaxTransmitFragmentSize = LittleEndianReader.ReadUInt16(buffer, ref offset);
  34. MaxReceiveFragmentSize = LittleEndianReader.ReadUInt16(buffer, ref offset);
  35. AssociationGroupID = LittleEndianReader.ReadUInt32(buffer, ref offset);
  36. ContextList = new ContextList(buffer, offset);
  37. offset += ContextList.Length;
  38. AuthVerifier = ByteReader.ReadBytes(buffer, offset, AuthLength);
  39. }
  40. public override byte[] GetBytes()
  41. {
  42. AuthLength =(ushort)AuthVerifier.Length;
  43. byte[] buffer = new byte[Length];
  44. WriteCommonFieldsBytes(buffer);
  45. int offset = CommonFieldsLength;
  46. LittleEndianWriter.WriteUInt16(buffer, ref offset, MaxTransmitFragmentSize);
  47. LittleEndianWriter.WriteUInt16(buffer, ref offset, MaxReceiveFragmentSize);
  48. LittleEndianWriter.WriteUInt32(buffer, ref offset, AssociationGroupID);
  49. ContextList.WriteBytes(buffer, ref offset);
  50. ByteWriter.WriteBytes(buffer, offset, AuthVerifier);
  51. return buffer;
  52. }
  53. public override int Length
  54. {
  55. get
  56. {
  57. return CommonFieldsLength + BindFieldsFixedLength + ContextList.Length + AuthLength;
  58. }
  59. }
  60. }
  61. }