FaultPDU.cs 2.9 KB

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