NTCreateAndXResponseExtended.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_NT_CREATE_ANDX Extended Response
  15. /// </summary>
  16. public class NTCreateAndXResponseExtended : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 100;
  19. // [MS-SMB] Section 2.2.4.9.2 and Note <49>:
  20. // Windows-based SMB servers send 50 (0x32) words in the extended response although they set the WordCount field to 0x2A.
  21. public const int DeclaredParametersLength = 84;
  22. // Parameters:
  23. // CommandName AndXCommand;
  24. // byte AndXReserved;
  25. // ushort AndXOffset;
  26. public OpLockLevel OpLockLevel;
  27. public ushort FID;
  28. public CreateDisposition CreateDisposition;
  29. public DateTime? CreateTime;
  30. public DateTime? LastAccessTime;
  31. public DateTime? LastWriteTime;
  32. public DateTime? LastChangeTime;
  33. public ExtendedFileAttributes ExtFileAttributes;
  34. public long AllocationSize;
  35. public long EndOfFile;
  36. public ResourceType ResourceType;
  37. public ushort NMPipeStatus_or_FileStatusFlags;
  38. public bool Directory;
  39. public Guid VolumeGuid;
  40. public ulong FileID;
  41. public AccessMask MaximalAccessRights;
  42. public AccessMask GuestMaximalAccessRights;
  43. public NTCreateAndXResponseExtended() : base()
  44. {
  45. }
  46. public NTCreateAndXResponseExtended(byte[] buffer, int offset) : base(buffer, offset, false)
  47. {
  48. int parametersOffset = 4;
  49. OpLockLevel = (OpLockLevel)ByteReader.ReadByte(this.SMBParameters, ref parametersOffset);
  50. FID = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  51. CreateDisposition = (CreateDisposition)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  52. CreateTime = FileTimeHelper.ReadNullableFileTime(this.SMBParameters, ref parametersOffset);
  53. LastAccessTime = FileTimeHelper.ReadNullableFileTime(this.SMBParameters, ref parametersOffset);
  54. LastWriteTime = FileTimeHelper.ReadNullableFileTime(this.SMBParameters, ref parametersOffset);
  55. LastChangeTime = FileTimeHelper.ReadNullableFileTime(this.SMBParameters, ref parametersOffset);
  56. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  57. AllocationSize = LittleEndianReader.ReadInt64(this.SMBParameters, ref parametersOffset);
  58. EndOfFile = LittleEndianReader.ReadInt64(this.SMBParameters, ref parametersOffset);
  59. ResourceType = (ResourceType)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  60. NMPipeStatus_or_FileStatusFlags = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  61. Directory = (ByteReader.ReadByte(this.SMBParameters, ref parametersOffset) > 0);
  62. VolumeGuid = LittleEndianReader.ReadGuid(this.SMBParameters, ref parametersOffset);
  63. FileID = LittleEndianReader.ReadUInt64(this.SMBParameters, ref parametersOffset);
  64. MaximalAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  65. GuestMaximalAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  66. }
  67. public override byte[] GetBytes(bool isUnicode)
  68. {
  69. this.SMBParameters = new byte[ParametersLength];
  70. int parametersOffset = 4;
  71. ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, (byte)OpLockLevel);
  72. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID);
  73. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)CreateDisposition);
  74. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, CreateTime);
  75. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastAccessTime);
  76. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastWriteTime);
  77. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastChangeTime);
  78. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)ExtFileAttributes);
  79. LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, AllocationSize);
  80. LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, EndOfFile);
  81. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType);
  82. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, NMPipeStatus_or_FileStatusFlags);
  83. ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, Convert.ToByte(Directory));
  84. LittleEndianWriter.WriteGuidBytes(this.SMBParameters, ref parametersOffset, VolumeGuid);
  85. LittleEndianWriter.WriteUInt64(this.SMBParameters, ref parametersOffset, FileID);
  86. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)MaximalAccessRights);
  87. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)GuestMaximalAccessRights);
  88. return base.GetBytes(isUnicode);
  89. }
  90. public NamedPipeStatus NMPipeStatus
  91. {
  92. get
  93. {
  94. return new NamedPipeStatus(NMPipeStatus_or_FileStatusFlags);
  95. }
  96. set
  97. {
  98. NMPipeStatus_or_FileStatusFlags = value.ToUInt16();
  99. }
  100. }
  101. public FileStatusFlags FileStatusFlags
  102. {
  103. get
  104. {
  105. return (FileStatusFlags)NMPipeStatus_or_FileStatusFlags;
  106. }
  107. set
  108. {
  109. NMPipeStatus_or_FileStatusFlags = (ushort)value;
  110. }
  111. }
  112. public override CommandName CommandName
  113. {
  114. get
  115. {
  116. return CommandName.SMB_COM_NT_CREATE_ANDX;
  117. }
  118. }
  119. }
  120. }