SessionSetupAndXRequestExtended.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_SESSION_SETUP_ANDX Extended Request
  15. /// </summary>
  16. public class SessionSetupAndXRequestExtended : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 24;
  19. // Parameters:
  20. public ushort MaxBufferSize;
  21. public ushort MaxMpxCount;
  22. public ushort VcNumber;
  23. public uint SessionKey;
  24. //ushort SecurityBlobLength;
  25. public uint Reserved;
  26. public ServerCapabilities Capabilities;
  27. // Data:
  28. public byte[] SecurityBlob;
  29. public string NativeOS; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
  30. public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  31. public SessionSetupAndXRequestExtended(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  32. {
  33. MaxBufferSize = LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
  34. MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 6);
  35. VcNumber = LittleEndianConverter.ToUInt16(this.SMBParameters, 8);
  36. SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 10);
  37. ushort securityBlobLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 14);
  38. Reserved = LittleEndianConverter.ToUInt32(this.SMBParameters, 16);
  39. Capabilities = (ServerCapabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 20);
  40. SecurityBlob = ByteReader.ReadBytes(this.SMBData, 0, securityBlobLength);
  41. int dataOffset = SecurityBlob.Length;
  42. if (isUnicode)
  43. {
  44. int padding = securityBlobLength % 2;
  45. dataOffset += padding;
  46. }
  47. NativeOS = SMBHelper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  48. NativeLanMan = SMBHelper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  49. }
  50. public override CommandName CommandName
  51. {
  52. get
  53. {
  54. return CommandName.SMB_COM_SESSION_SETUP_ANDX;
  55. }
  56. }
  57. }
  58. }