Transaction2Open2Request.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2014 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. /// TRANS2_OPEN2 Request
  15. /// </summary>
  16. public class Transaction2Open2Request : Transaction2Subcommand
  17. {
  18. // Parameters:
  19. public Open2Flags Flags;
  20. public AccessModeOptions AccessMode;
  21. public ushort Reserved1;
  22. public SMBFileAttributes FileAttributes;
  23. public DateTime? CreationTime; // UTIME (seconds since Jan 1, 1970)
  24. public OpenMode OpenMode;
  25. public uint AllocationSize;
  26. public byte[] Reserved; // 10 bytes
  27. public string FileName; // SMB_STRING
  28. // Data:
  29. public FullExtendedAttributeList ExtendedAttributeList;
  30. public Transaction2Open2Request() : base()
  31. {
  32. Reserved = new byte[10];
  33. }
  34. public Transaction2Open2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
  35. {
  36. Flags = (Open2Flags)LittleEndianConverter.ToUInt16(parameters, 0);
  37. AccessMode = new AccessModeOptions(parameters, 2);
  38. Reserved1 = LittleEndianConverter.ToUInt16(parameters, 4);
  39. FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 6);
  40. CreationTime = UTimeHelper.ReadNullableUTime(parameters, 8);
  41. OpenMode = new OpenMode(parameters, 12);
  42. AllocationSize = LittleEndianConverter.ToUInt32(parameters, 14);
  43. Reserved = ByteReader.ReadBytes(parameters, 18, 10);
  44. FileName = SMB1Helper.ReadSMBString(parameters, 28, isUnicode);
  45. ExtendedAttributeList = new FullExtendedAttributeList(data, 0);
  46. }
  47. public override byte[] GetSetup()
  48. {
  49. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  50. }
  51. public override byte[] GetParameters(bool isUnicode)
  52. {
  53. int length = 28;
  54. if (isUnicode)
  55. {
  56. length += FileName.Length * 2 + 2;
  57. }
  58. else
  59. {
  60. length += FileName.Length + 1;
  61. }
  62. byte[] parameters = new byte[length];
  63. LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)Flags);
  64. AccessMode.WriteBytes(parameters, 2);
  65. LittleEndianWriter.WriteUInt16(parameters, 4, Reserved1);
  66. LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)FileAttributes);
  67. UTimeHelper.WriteUTime(parameters, 8, CreationTime);
  68. OpenMode.WriteBytes(parameters, 12);
  69. LittleEndianWriter.WriteUInt32(parameters, 14, AllocationSize);
  70. ByteWriter.WriteBytes(parameters, 18, Reserved, 10);
  71. SMB1Helper.WriteSMBString(parameters, 28, isUnicode, FileName);
  72. return parameters;
  73. }
  74. public override byte[] GetData(bool isUnicode)
  75. {
  76. return ExtendedAttributeList.GetBytes();
  77. }
  78. public override Transaction2SubcommandName SubcommandName
  79. {
  80. get
  81. {
  82. return Transaction2SubcommandName.TRANS2_OPEN2;
  83. }
  84. }
  85. }
  86. }