ContextList.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 2014 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_list_t
  15. /// Presentation Context List
  16. /// </summary>
  17. public class ContextList : List<ContextElement>
  18. {
  19. //byte NumberOfContextElements;
  20. public byte Reserved1;
  21. public ushort Reserved2;
  22. public ContextList() : base()
  23. {
  24. }
  25. public ContextList(byte[] buffer, int offset) : base()
  26. {
  27. byte numberOfContextElements = ByteReader.ReadByte(buffer, offset + 0);
  28. Reserved1 = ByteReader.ReadByte(buffer, offset + 1);
  29. Reserved2 = LittleEndianConverter.ToUInt16(buffer, offset + 2);
  30. offset += 4;
  31. for (int index = 0; index < numberOfContextElements; index++)
  32. {
  33. ContextElement element = new ContextElement(buffer, offset);
  34. this.Add(element);
  35. offset += element.Length;
  36. }
  37. }
  38. public void WriteBytes(byte[] buffer, int offset)
  39. {
  40. byte numberOfContextElements = (byte)this.Count;
  41. ByteWriter.WriteByte(buffer, offset + 0, numberOfContextElements);
  42. ByteWriter.WriteByte(buffer, offset + 1, Reserved1);
  43. LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved2);
  44. offset += 4;
  45. for (int index = 0; index < numberOfContextElements; index++)
  46. {
  47. this[index].WriteBytes(buffer, offset);
  48. offset += this[index].Length;
  49. }
  50. }
  51. public void WriteBytes(byte[] buffer, ref int offset)
  52. {
  53. WriteBytes(buffer, offset);
  54. offset += this.Length;
  55. }
  56. public int Length
  57. {
  58. get
  59. {
  60. int length = 4;
  61. for (int index = 0; index < this.Count; index++)
  62. {
  63. length += this[index].Length;
  64. }
  65. return length;
  66. }
  67. }
  68. }
  69. }