ContextElement.cs 2.3 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. /// p_cont_elem_t
  15. /// </summary>
  16. public class ContextElement // Presentation Context Element
  17. {
  18. public ushort ContextID;
  19. // byte NumberOfTransferSyntaxItems;
  20. public byte Reserved;
  21. public SyntaxID AbstractSyntax;
  22. public List<SyntaxID> TransferSyntaxList = new List<SyntaxID>();
  23. public ContextElement()
  24. {
  25. }
  26. public ContextElement(byte[] buffer, int offset)
  27. {
  28. ContextID = LittleEndianConverter.ToUInt16(buffer, offset + 0);
  29. byte numberOfTransferSyntaxItems = ByteReader.ReadByte(buffer, offset + 2);
  30. Reserved = ByteReader.ReadByte(buffer, offset + 3);
  31. AbstractSyntax = new SyntaxID(buffer, offset + 4);
  32. offset += 4 + SyntaxID.Length;
  33. for (int index = 0; index < numberOfTransferSyntaxItems; index++)
  34. {
  35. SyntaxID syntax = new SyntaxID(buffer, offset);
  36. TransferSyntaxList.Add(syntax);
  37. offset += SyntaxID.Length;
  38. }
  39. }
  40. public void WriteBytes(byte[] buffer, int offset)
  41. {
  42. byte numberOfTransferSyntaxItems = (byte)TransferSyntaxList.Count;
  43. LittleEndianWriter.WriteUInt16(buffer, offset + 0, ContextID);
  44. ByteWriter.WriteByte(buffer, offset + 2, numberOfTransferSyntaxItems);
  45. ByteWriter.WriteByte(buffer, offset + 3, Reserved);
  46. AbstractSyntax.WriteBytes(buffer, offset + 4);
  47. offset += 4 + SyntaxID.Length;
  48. for (int index = 0; index < numberOfTransferSyntaxItems; index++)
  49. {
  50. TransferSyntaxList[index].WriteBytes(buffer, offset);
  51. offset += SyntaxID.Length;
  52. }
  53. }
  54. public int Length
  55. {
  56. get
  57. {
  58. return 4 + SyntaxID.Length * (TransferSyntaxList.Count + 1);
  59. }
  60. }
  61. }
  62. }