OpenAndXResponse.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Response
  15. /// </summary>
  16. public class OpenAndXResponse : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 30;
  19. // Parameters:
  20. // CommandName AndXCommand;
  21. // byte AndXReserved;
  22. // ushort AndXOffset;
  23. public ushort FID;
  24. public SMBFileAttributes FileAttrs;
  25. public DateTime? LastWriteTime; // UTime
  26. public uint FileDataSize;
  27. public AccessRights AccessRights;
  28. public ResourceType ResourceType;
  29. public NamedPipeStatus NMPipeStatus;
  30. public OpenResults OpenResults;
  31. public byte[] Reserved; // 6 bytes
  32. public OpenAndXResponse() : base()
  33. {
  34. Reserved = new byte[6];
  35. }
  36. public OpenAndXResponse(byte[] buffer, int offset) : base(buffer, offset, false)
  37. {
  38. int parametersOffset = 4;
  39. FID = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  40. FileAttrs = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  41. LastWriteTime = UTimeHelper.ReadNullableUTime(this.SMBParameters, ref parametersOffset);
  42. FileDataSize = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  43. AccessRights = (AccessRights)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  44. ResourceType = (ResourceType)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  45. NMPipeStatus = NamedPipeStatus.Read(this.SMBParameters, ref parametersOffset);
  46. OpenResults = OpenResults.Read(this.SMBParameters, ref parametersOffset);
  47. Reserved = ByteReader.ReadBytes(this.SMBParameters, ref parametersOffset, 6);
  48. }
  49. public override byte[] GetBytes(bool isUnicode)
  50. {
  51. this.SMBParameters = new byte[ParametersLength];
  52. int parametersOffset = 4;
  53. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID);
  54. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)FileAttrs);
  55. UTimeHelper.WriteUTime(this.SMBParameters, ref parametersOffset, LastWriteTime);
  56. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, FileDataSize);
  57. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)AccessRights);
  58. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType);
  59. NMPipeStatus.WriteBytes(this.SMBParameters, ref parametersOffset);
  60. OpenResults.WriteBytes(this.SMBParameters, ref parametersOffset);
  61. ByteWriter.WriteBytes(this.SMBParameters, ref parametersOffset, Reserved, 6);
  62. return base.GetBytes(isUnicode);
  63. }
  64. public override CommandName CommandName
  65. {
  66. get
  67. {
  68. return CommandName.SMB_COM_OPEN_ANDX;
  69. }
  70. }
  71. }
  72. }