TransactionSubcommand.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2014-2019 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 TransactionSubcommand
  14. {
  15. public TransactionSubcommand()
  16. {
  17. }
  18. public virtual byte[] GetSetup()
  19. {
  20. return new byte[0];
  21. }
  22. public virtual byte[] GetParameters()
  23. {
  24. return new byte[0];
  25. }
  26. public virtual byte[] GetData(bool isUnicode)
  27. {
  28. return new byte[0];
  29. }
  30. public abstract TransactionSubcommandName SubcommandName
  31. {
  32. get;
  33. }
  34. public static TransactionSubcommand GetSubcommandRequest(byte[] setup, byte[] parameters, byte[] data, bool isUnicode)
  35. {
  36. if (setup.Length == 4)
  37. {
  38. TransactionSubcommandName subcommandName = (TransactionSubcommandName)LittleEndianConverter.ToUInt16(setup, 0);
  39. switch (subcommandName)
  40. {
  41. case TransactionSubcommandName.TRANS_SET_NMPIPE_STATE:
  42. return new TransactionSetNamedPipeStateRequest(setup, parameters);
  43. case TransactionSubcommandName.TRANS_RAW_READ_NMPIPE:
  44. return new TransactionRawReadNamedPipeRequest(setup);
  45. case TransactionSubcommandName.TRANS_QUERY_NMPIPE_STATE:
  46. return new TransactionQueryNamedPipeStateRequest(setup, parameters);
  47. case TransactionSubcommandName.TRANS_QUERY_NMPIPE_INFO:
  48. return new TransactionQueryNamedPipeInfoRequest(setup, parameters);
  49. case TransactionSubcommandName.TRANS_PEEK_NMPIPE:
  50. return new TransactionPeekNamedPipeRequest(setup);
  51. case TransactionSubcommandName.TRANS_TRANSACT_NMPIPE:
  52. return new TransactionTransactNamedPipeRequest(setup, data);
  53. case TransactionSubcommandName.TRANS_RAW_WRITE_NMPIPE:
  54. return new TransactionRawWriteNamedPipeRequest(setup, data);
  55. case TransactionSubcommandName.TRANS_READ_NMPIPE:
  56. return new TransactionReadNamedPipeRequest(setup);
  57. case TransactionSubcommandName.TRANS_WRITE_NMPIPE:
  58. return new TransactionWriteNamedPipeRequest(setup, data);
  59. case TransactionSubcommandName.TRANS_WAIT_NMPIPE:
  60. return new TransactionWaitNamedPipeRequest(setup);
  61. case TransactionSubcommandName.TRANS_CALL_NMPIPE:
  62. return new TransactionCallNamedPipeRequest(setup, data);
  63. }
  64. }
  65. throw new InvalidDataException();
  66. }
  67. }
  68. }