FaultPDU.cs 2.9 KB

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