Transaction2FindFirst2Response.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// TRANS2_FIND_FIRST2 Response
  15. /// </summary>
  16. public class Transaction2FindFirst2Response : Transaction2Subcommand
  17. {
  18. public const int ParametersLength = 10;
  19. // Parameters:
  20. public ushort SID; // Search handle
  21. private ushort SearchCount;
  22. public bool EndOfSearch;
  23. public ushort EaErrorOffset;
  24. public ushort LastNameOffset;
  25. // Data:
  26. private byte[] FindInformationListBytes = new byte[0];
  27. public Transaction2FindFirst2Response() : base()
  28. {
  29. }
  30. public Transaction2FindFirst2Response(byte[] parameters, byte[] data, bool isUnicode) : base()
  31. {
  32. SID = LittleEndianConverter.ToUInt16(parameters, 0);
  33. SearchCount = LittleEndianConverter.ToUInt16(parameters, 2);
  34. EndOfSearch = LittleEndianConverter.ToUInt16(parameters, 4) != 0;
  35. EaErrorOffset = LittleEndianConverter.ToUInt16(parameters, 6);
  36. LastNameOffset = LittleEndianConverter.ToUInt16(parameters, 8);
  37. FindInformationListBytes = data;
  38. }
  39. public override byte[] GetParameters(bool isUnicode)
  40. {
  41. byte[] parameters = new byte[ParametersLength];
  42. LittleEndianWriter.WriteUInt16(parameters, 0, SID);
  43. LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount);
  44. LittleEndianWriter.WriteUInt16(parameters, 4, Convert.ToUInt16(EndOfSearch));
  45. LittleEndianWriter.WriteUInt16(parameters, 6, EaErrorOffset);
  46. LittleEndianWriter.WriteUInt16(parameters, 8, LastNameOffset);
  47. return parameters;
  48. }
  49. public override byte[] GetData(bool isUnicode)
  50. {
  51. return FindInformationListBytes;
  52. }
  53. public FindInformationList GetFindInformationList(FindInformationLevel findInformationLevel, bool isUnicode, bool returnResumeKeys)
  54. {
  55. return new FindInformationList(FindInformationListBytes, findInformationLevel, isUnicode, returnResumeKeys);
  56. }
  57. public void SetFindInformationList(FindInformationList findInformationList, bool isUnicode)
  58. {
  59. SearchCount = (ushort)findInformationList.Count;
  60. FindInformationListBytes = findInformationList.GetBytes(isUnicode);
  61. }
  62. public override Transaction2SubcommandName SubcommandName
  63. {
  64. get
  65. {
  66. return Transaction2SubcommandName.TRANS2_FIND_FIRST2;
  67. }
  68. }
  69. }
  70. }