Transaction2Subcommand.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Transaction2Subcommand
  14. {
  15. public Transaction2Subcommand()
  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(bool isUnicode)
  27. {
  28. return new byte[0];
  29. }
  30. public abstract Transaction2SubcommandName SubcommandName
  31. {
  32. get;
  33. }
  34. public static Transaction2Subcommand GetSubcommandRequest(byte[] setup, byte[] parameters, byte[] data, bool isUnicode)
  35. {
  36. if (setup.Length == 2)
  37. {
  38. Transaction2SubcommandName subcommandName = (Transaction2SubcommandName)LittleEndianConverter.ToUInt16(setup, 0);
  39. switch (subcommandName)
  40. {
  41. case Transaction2SubcommandName.TRANS2_OPEN2:
  42. return new Transaction2Open2Request(parameters, data, isUnicode);
  43. case Transaction2SubcommandName.TRANS2_FIND_FIRST2:
  44. return new Transaction2FindFirst2Request(parameters, data, isUnicode);
  45. case Transaction2SubcommandName.TRANS2_FIND_NEXT2:
  46. return new Transaction2FindNext2Request(parameters, data, isUnicode);
  47. case Transaction2SubcommandName.TRANS2_QUERY_FS_INFORMATION:
  48. return new Transaction2QueryFSInformationRequest(parameters, data, isUnicode);
  49. case Transaction2SubcommandName.TRANS2_QUERY_PATH_INFORMATION:
  50. return new Transaction2QueryPathInformationRequest(parameters, data, isUnicode);
  51. case Transaction2SubcommandName.TRANS2_SET_PATH_INFORMATION:
  52. return new Transaction2SetPathInformationRequest(parameters, data, isUnicode);
  53. case Transaction2SubcommandName.TRANS2_QUERY_FILE_INFORMATION:
  54. return new Transaction2QueryFileInformationRequest(parameters, data, isUnicode);
  55. case Transaction2SubcommandName.TRANS2_SET_FILE_INFORMATION:
  56. return new Transaction2SetFileInformationRequest(parameters, data, isUnicode);
  57. case Transaction2SubcommandName.TRANS2_CREATE_DIRECTORY:
  58. return new Transaction2CreateDirectoryRequest(parameters, data, isUnicode);
  59. case Transaction2SubcommandName.TRANS2_GET_DFS_REFERRAL:
  60. return new Transaction2GetDfsReferralRequest(parameters, data);
  61. }
  62. }
  63. throw new InvalidDataException();
  64. }
  65. }
  66. }