TreeConnectAndXResponse.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /// SMB_COM_TREE_CONNECT_ANDX Response
  15. /// </summary>
  16. public class TreeConnectAndXResponse : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 6;
  19. // Parameters:
  20. //CommandName AndXCommand;
  21. //byte AndXReserved;
  22. //ushort AndXOffset;
  23. public OptionalSupportFlags OptionalSupport;
  24. // Data:
  25. public ServiceName Service; // OEM String
  26. public string NativeFileSystem; // SMB_STRING
  27. public TreeConnectAndXResponse() : base()
  28. {
  29. }
  30. public TreeConnectAndXResponse(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  31. {
  32. OptionalSupport = (OptionalSupportFlags)LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
  33. int dataOffset = 0;
  34. string serviceString = ByteReader.ReadNullTerminatedAnsiString(this.SMBData, ref dataOffset);
  35. NativeFileSystem = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  36. Service = ServiceNameHelper.GetServiceName(serviceString);
  37. }
  38. public override byte[] GetBytes(bool isUnicode)
  39. {
  40. this.SMBParameters = new byte[ParametersLength];
  41. LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, (ushort)OptionalSupport);
  42. // Should be written as OEM string but it doesn't really matter
  43. string serviceString = ServiceNameHelper.GetServiceString(Service);
  44. if (isUnicode)
  45. {
  46. this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length * 2 + 3];
  47. }
  48. else
  49. {
  50. this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length + 2];
  51. }
  52. int offset = 0;
  53. ByteWriter.WriteNullTerminatedAnsiString(this.SMBData, ref offset, serviceString);
  54. SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeFileSystem);
  55. return base.GetBytes(isUnicode);
  56. }
  57. public override CommandName CommandName
  58. {
  59. get
  60. {
  61. return CommandName.SMB_COM_TREE_CONNECT_ANDX;
  62. }
  63. }
  64. }
  65. }