NTTransactCreateRequest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /// NT_TRANSACT_CREATE Request
  15. /// </summary>
  16. public class NTTransactCreateRequest : NTTransactSubcommand
  17. {
  18. public const int ParametersFixedLength = 53;
  19. // Parameters:
  20. public NTCreateFlags Flags;
  21. public uint RootDirectoryFID;
  22. public AccessMask DesiredAccess;
  23. public long AllocationSize;
  24. public ExtendedFileAttributes ExtFileAttributes;
  25. public ShareAccess ShareAccess;
  26. public CreateDisposition CreateDisposition;
  27. public CreateOptions CreateOptions;
  28. // uint SecurityDescriptiorLength;
  29. // uint EALength;
  30. // uint NameLength;
  31. public ImpersonationLevel ImpersonationLevel;
  32. public SecurityFlags SecurityFlags;
  33. public string Name; // OEM / Unicode. NOT null terminated. (MUST be aligned to start on a 2-byte boundary from the start of the NT_Trans_Parameters)
  34. // Data:
  35. public SecurityDescriptor SecurityDescriptor;
  36. public List<FileFullEAEntry> ExtendedAttributes;
  37. public NTTransactCreateRequest()
  38. {
  39. }
  40. public NTTransactCreateRequest(byte[] parameters, byte[] data, bool isUnicode)
  41. {
  42. int parametersOffset = 0;
  43. Flags = (NTCreateFlags)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  44. RootDirectoryFID = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  45. DesiredAccess = (AccessMask)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  46. AllocationSize = LittleEndianReader.ReadInt64(parameters, ref parametersOffset);
  47. ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  48. ShareAccess = (ShareAccess)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  49. CreateDisposition = (CreateDisposition)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  50. CreateOptions = (CreateOptions)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  51. uint securityDescriptiorLength = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  52. uint eaLength = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  53. uint nameLength = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  54. ImpersonationLevel = (ImpersonationLevel)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
  55. SecurityFlags = (SecurityFlags)ByteReader.ReadByte(parameters, ref parametersOffset);
  56. if (isUnicode)
  57. {
  58. parametersOffset++;
  59. }
  60. Name = SMB1Helper.ReadFixedLengthString(parameters, ref parametersOffset, isUnicode, (int)nameLength);
  61. if (securityDescriptiorLength > 0)
  62. {
  63. SecurityDescriptor = new SecurityDescriptor(data, 0);
  64. }
  65. ExtendedAttributes = FileFullEAInformation.ReadList(data, (int)securityDescriptiorLength);
  66. }
  67. public override byte[] GetParameters(bool isUnicode)
  68. {
  69. throw new NotImplementedException();
  70. }
  71. public override byte[] GetData()
  72. {
  73. throw new NotImplementedException();
  74. }
  75. public override NTTransactSubcommandName SubcommandName
  76. {
  77. get
  78. {
  79. return NTTransactSubcommandName.NT_TRANSACT_CREATE;
  80. }
  81. }
  82. }
  83. }