NTCreateAndXResponseExtended.cs 6.0 KB

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