ResponsePDU.cs 2.4 KB

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