ResponsePDU.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_response_hdr_t
  15. /// </summary>
  16. public class ResponsePDU : RPCPDU
  17. {
  18. public const int ResponseFieldsLength = 8;
  19. public uint AllocationHint;
  20. public ushort ContextID;
  21. public byte CancelCount;
  22. public byte Reserved;
  23. public byte[] Data;
  24. public byte[] AuthVerifier;
  25. public ResponsePDU() : base()
  26. {
  27. PacketType = PacketTypeName.Response;
  28. AuthVerifier = new byte[0];
  29. }
  30. public ResponsePDU(byte[] buffer, int offset) : base(buffer, offset)
  31. {
  32. offset += CommonFieldsLength;
  33. AllocationHint = LittleEndianReader.ReadUInt32(buffer, ref offset);
  34. ContextID = LittleEndianReader.ReadUInt16(buffer, ref offset);
  35. CancelCount = ByteReader.ReadByte(buffer, ref offset);
  36. Reserved = ByteReader.ReadByte(buffer, ref offset);
  37. int dataLength = FragmentLength - AuthLength - offset;
  38. Data = ByteReader.ReadBytes(buffer, ref offset, dataLength);
  39. AuthVerifier = ByteReader.ReadBytes(buffer, offset, AuthLength);
  40. }
  41. public override byte[] GetBytes()
  42. {
  43. AuthLength = (ushort)AuthVerifier.Length;
  44. byte[] buffer = new byte[Length];
  45. WriteCommonFieldsBytes(buffer);
  46. int offset = CommonFieldsLength;
  47. LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationHint);
  48. LittleEndianWriter.WriteUInt16(buffer, ref offset, ContextID);
  49. ByteWriter.WriteByte(buffer, ref offset, CancelCount);
  50. ByteWriter.WriteByte(buffer, ref offset, Reserved);
  51. ByteWriter.WriteBytes(buffer, ref offset, Data);
  52. ByteWriter.WriteBytes(buffer, ref offset, AuthVerifier);
  53. return buffer;
  54. }
  55. public override int Length
  56. {
  57. get
  58. {
  59. return CommonFieldsLength + ResponseFieldsLength + Data.Length + AuthVerifier.Length;
  60. }
  61. }
  62. }
  63. }