NTTransactSubcommand.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2014-2017 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.IO;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. public abstract class NTTransactSubcommand
  14. {
  15. public NTTransactSubcommand()
  16. {
  17. }
  18. public virtual byte[] GetSetup()
  19. {
  20. return new byte[0];
  21. }
  22. public virtual byte[] GetParameters(bool isUnicode)
  23. {
  24. return new byte[0];
  25. }
  26. public virtual byte[] GetData()
  27. {
  28. return new byte[0];
  29. }
  30. public abstract NTTransactSubcommandName SubcommandName
  31. {
  32. get;
  33. }
  34. public static NTTransactSubcommand GetSubcommandRequest(NTTransactSubcommandName subcommandName, byte[] setup, byte[] parameters, byte[] data, bool isUnicode)
  35. {
  36. switch (subcommandName)
  37. {
  38. case NTTransactSubcommandName.NT_TRANSACT_CREATE:
  39. return new NTTransactCreateRequest(parameters, data, isUnicode);
  40. case NTTransactSubcommandName.NT_TRANSACT_IOCTL:
  41. return new NTTransactIOCTLRequest(setup, data);
  42. case NTTransactSubcommandName.NT_TRANSACT_SET_SECURITY_DESC:
  43. return new NTTransactSetSecurityDescriptor(parameters, data);
  44. case NTTransactSubcommandName.NT_TRANSACT_NOTIFY_CHANGE:
  45. return new NTTransactNotifyChangeRequest(setup);
  46. case NTTransactSubcommandName.NT_TRANSACT_QUERY_SECURITY_DESC:
  47. return new NTTransactQuerySecurityDescriptorRequest(parameters);
  48. }
  49. throw new InvalidDataException();
  50. }
  51. }
  52. }