WorkstationInfo.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. namespace SMBLibrary.Services
  12. {
  13. /// <summary>
  14. /// [MS-WKST] WKSTA_INFO Union
  15. /// </summary>
  16. public class WorkstationInfo : INDRStructure
  17. {
  18. public uint Level;
  19. public WorkstationInfoLevel Info;
  20. public WorkstationInfo()
  21. {
  22. }
  23. public WorkstationInfo(WorkstationInfoLevel info)
  24. {
  25. Level = info.Level;
  26. Info = info;
  27. }
  28. public WorkstationInfo(NDRParser parser)
  29. {
  30. Read(parser);
  31. }
  32. public void Read(NDRParser parser)
  33. {
  34. parser.BeginStructure();
  35. Level = parser.ReadUInt32();
  36. switch (Level)
  37. {
  38. case 100:
  39. WorkstationInfo100 info100 = null;
  40. parser.ReadEmbeddedStructureFullPointer<WorkstationInfo100>(ref info100);
  41. Info = info100;
  42. break;
  43. case 101:
  44. WorkstationInfo101 info101 = null;
  45. parser.ReadEmbeddedStructureFullPointer<WorkstationInfo101>(ref info101);
  46. Info = info101;
  47. break;
  48. default:
  49. throw new NotImplementedException();
  50. }
  51. parser.EndStructure();
  52. }
  53. public void Write(NDRWriter writer)
  54. {
  55. if (Info != null && Level != Info.Level)
  56. {
  57. throw new ArgumentException("Invalid WKSTA_INFO Level");
  58. }
  59. writer.BeginStructure();
  60. writer.WriteUInt32(Level);
  61. writer.WriteEmbeddedStructureFullPointer(Info);
  62. writer.EndStructure();
  63. }
  64. }
  65. }