TreeConnectAndXResponseExtended.cs 3.3 KB

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