OpenAndXRequest.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_COM_OPEN_ANDX Request
  15. /// </summary>
  16. public class OpenAndXRequest : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 30;
  19. // Parameters:
  20. //CommandName AndXCommand;
  21. //byte AndXReserved;
  22. //ushort AndXOffset;
  23. public OpenFlags Flags;
  24. public AccessModeOptions AccessMode;
  25. public SMBFileAttributes SearchAttrs;
  26. public SMBFileAttributes FileAttrs;
  27. public DateTime? CreationTime; // UTime
  28. public OpenMode OpenMode;
  29. public uint AllocationSize;
  30. public uint Timeout;
  31. public uint Reserved;
  32. // Data:
  33. public string FileName; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
  34. public OpenAndXRequest() : base()
  35. {
  36. }
  37. public OpenAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  38. {
  39. int parametersOffset = 4;
  40. Flags = (OpenFlags)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  41. AccessMode = AccessModeOptions.Read(this.SMBParameters, ref parametersOffset);
  42. SearchAttrs = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  43. FileAttrs = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  44. CreationTime = UTimeHelper.ReadNullableUTime(this.SMBParameters, ref parametersOffset);
  45. OpenMode = OpenMode.Read(this.SMBParameters, ref parametersOffset);
  46. AllocationSize = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  47. Timeout = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  48. Reserved = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  49. int dataOffset = 0;
  50. if (isUnicode)
  51. {
  52. dataOffset = 1; // 1 byte padding for 2 byte alignment
  53. }
  54. FileName = SMB1Helper.ReadSMBString(this.SMBData, dataOffset, isUnicode);
  55. }
  56. public override byte[] GetBytes(bool isUnicode)
  57. {
  58. throw new NotImplementedException();
  59. }
  60. public override CommandName CommandName
  61. {
  62. get
  63. {
  64. return CommandName.SMB_COM_OPEN_ANDX;
  65. }
  66. }
  67. }
  68. }