FaultPDU.cs 2.7 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_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. 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 = 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. FragmentLength = (ushort)(CommonFieldsLength + FaultFieldsLength + Data.Length + AuthVerifier.Length);
  49. byte[] buffer = new byte[FragmentLength];
  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. }
  63. }