NDRConformantArray.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. namespace SMBLibrary.RPC
  11. {
  12. public class NDRConformantArray<T> : List<T>, INDRStructure where T : INDRStructure, new()
  13. {
  14. /// <summary>
  15. /// See DCE 1.1: Remote Procedure Call - 14.3.3.2 - Uni-dimensional Conformant Arrays
  16. /// </summary>
  17. /// <param name="parser"></param>
  18. public void Read(NDRParser parser)
  19. {
  20. parser.BeginStructure();
  21. uint maxCount = parser.ReadUInt32();
  22. for (int index = 0; index < maxCount; index++)
  23. {
  24. T entry = new T();
  25. entry.Read(parser);
  26. this.Add(entry);
  27. }
  28. parser.EndStructure();
  29. }
  30. public void Write(NDRWriter writer)
  31. {
  32. writer.BeginStructure();
  33. uint maxCount = (uint)this.Count;
  34. writer.WriteUInt32(maxCount);
  35. for (int index = 0; index < this.Count; index++)
  36. {
  37. this[index].Write(writer);
  38. }
  39. writer.EndStructure();
  40. }
  41. }
  42. }