ShareEnum.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 SMBLibrary.RPC;
  11. using Utilities;
  12. namespace SMBLibrary.Services
  13. {
  14. /// <summary>
  15. /// [MS-SRVS] SHARE_ENUM_STRUCT and the embedded SHARE_ENUM_UNION
  16. /// </summary>
  17. public class ShareEnum : INDRStructure
  18. {
  19. public uint Level;
  20. public IShareInfoContainer Info;
  21. public ShareEnum()
  22. {
  23. }
  24. public ShareEnum(IShareInfoContainer info)
  25. {
  26. Level = info.Level;
  27. Info = info;
  28. }
  29. public ShareEnum(NDRParser parser)
  30. {
  31. Read(parser);
  32. }
  33. public void Read(NDRParser parser)
  34. {
  35. parser.BeginStructure(); // SHARE_ENUM_STRUCT
  36. Level = parser.ReadUInt32();
  37. parser.BeginStructure(); // SHARE_ENUM_UNION
  38. // 14.3.8 - For a non-encapsulated union, the discriminant is marshalled into the transmitted data stream twice.
  39. // once as the field or parameter, which is referenced by the switch_is construct, in the procedure argument list;
  40. // and once as the first part of the union representation.
  41. uint level = parser.ReadUInt32();
  42. switch (level)
  43. {
  44. case 0:
  45. ShareInfo0Container info0 = null;
  46. parser.ReadEmbeddedStructureFullPointer<ShareInfo0Container>(ref info0);
  47. Info = info0;
  48. break;
  49. case 1:
  50. ShareInfo1Container info1 = null;
  51. parser.ReadEmbeddedStructureFullPointer<ShareInfo1Container>(ref info1);
  52. Info = info1;
  53. break;
  54. case 2:
  55. case 501:
  56. case 502:
  57. case 503:
  58. throw new NotImplementedException();
  59. default:
  60. break;
  61. }
  62. parser.EndStructure(); // SHARE_ENUM_UNION
  63. parser.EndStructure(); // SHARE_ENUM_STRUCT
  64. }
  65. public void Write(NDRWriter writer)
  66. {
  67. if (Info != null && Level != Info.Level)
  68. {
  69. throw new ArgumentException("SHARE_ENUM_STRUCT Level mismatch");
  70. }
  71. writer.BeginStructure(); // SHARE_ENUM_STRUCT
  72. writer.WriteUInt32(Level);
  73. writer.BeginStructure(); // SHARE_ENUM_UNION
  74. writer.WriteUInt32(Level);
  75. writer.WriteEmbeddedStructureFullPointer(Info);
  76. writer.EndStructure(); // SHARE_ENUM_UNION
  77. writer.EndStructure(); // SHARE_ENUM_STRUCT
  78. }
  79. }
  80. }