NTCreateAndXResponse.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Response
  15. /// </summary>
  16. public class NTCreateAndXResponse : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 68;
  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 NamedPipeStatus NMPipeStatus;
  35. public bool Directory;
  36. public NTCreateAndXResponse() : base()
  37. {
  38. }
  39. public NTCreateAndXResponse(byte[] buffer, int offset) : base(buffer, offset, false)
  40. {
  41. int parametersOffset = 4;
  42. OpLockLevel = (OpLockLevel)ByteReader.ReadByte(this.SMBParameters, ref parametersOffset);
  43. FID = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  44. CreateDisposition = (CreateDisposition)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  45. CreateTime = SMB1Helper.ReadNullableFileTime(buffer, ref parametersOffset);
  46. LastAccessTime = SMB1Helper.ReadNullableFileTime(buffer, ref parametersOffset);
  47. LastWriteTime = SMB1Helper.ReadNullableFileTime(buffer, ref parametersOffset);
  48. LastChangeTime = SMB1Helper.ReadNullableFileTime(buffer, ref parametersOffset);
  49. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
  50. AllocationSize = LittleEndianReader.ReadInt64(buffer, ref parametersOffset);
  51. EndOfFile = LittleEndianReader.ReadInt64(buffer, ref parametersOffset);
  52. ResourceType = (ResourceType)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
  53. NMPipeStatus = NamedPipeStatus.Read(this.SMBParameters, ref parametersOffset);
  54. Directory = (ByteReader.ReadByte(this.SMBParameters, ref parametersOffset) > 0);
  55. }
  56. public override byte[] GetBytes(bool isUnicode)
  57. {
  58. this.SMBParameters = new byte[ParametersLength];
  59. int parametersOffset = 4;
  60. ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, (byte)OpLockLevel);
  61. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID);
  62. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)CreateDisposition);
  63. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, CreateTime);
  64. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastAccessTime);
  65. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastWriteTime);
  66. FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastChangeTime);
  67. LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)ExtFileAttributes);
  68. LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, AllocationSize);
  69. LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, EndOfFile);
  70. LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType);
  71. NMPipeStatus.WriteBytes(this.SMBParameters, ref parametersOffset);
  72. ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, Convert.ToByte(Directory));
  73. return base.GetBytes(isUnicode);
  74. }
  75. public override CommandName CommandName
  76. {
  77. get
  78. {
  79. return CommandName.SMB_COM_NT_CREATE_ANDX;
  80. }
  81. }
  82. }
  83. }