ShareEnum.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. default:
  55. throw new NotImplementedException();
  56. }
  57. parser.EndStructure(); // SHARE_ENUM_UNION
  58. parser.EndStructure(); // SHARE_ENUM_STRUCT
  59. }
  60. public void Write(NDRWriter writer)
  61. {
  62. if (Info != null && Level != Info.Level)
  63. {
  64. throw new ArgumentException("Invalid SHARE_ENUM_STRUCT Level");
  65. }
  66. writer.BeginStructure(); // SHARE_ENUM_STRUCT
  67. writer.WriteUInt32(Level);
  68. writer.BeginStructure(); // SHARE_ENUM_UNION
  69. writer.WriteUInt32(Info.Level);
  70. writer.WriteEmbeddedStructureFullPointer(Info);
  71. writer.EndStructure(); // SHARE_ENUM_UNION
  72. writer.EndStructure(); // SHARE_ENUM_STRUCT
  73. }
  74. }
  75. }