Transaction2Open2Request.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. CreationTime = SMB1Helper.UTimeNotSpecified;
  33. Reserved = new byte[10];
  34. }
  35. public Transaction2Open2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
  36. {
  37. Flags = (Open2Flags)LittleEndianConverter.ToUInt16(parameters, 0);
  38. AccessMode = new AccessModeOptions(parameters, 2);
  39. Reserved1 = LittleEndianConverter.ToUInt16(parameters, 4);
  40. FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 6);
  41. CreationTime = SMB1Helper.ReadUTime(parameters, 8);
  42. OpenMode = new OpenMode(parameters, 12);
  43. AllocationSize = LittleEndianConverter.ToUInt32(parameters, 14);
  44. Reserved = ByteReader.ReadBytes(parameters, 18, 10);
  45. FileName = SMB1Helper.ReadSMBString(parameters, 28, isUnicode);
  46. ExtendedAttributeList = new FullExtendedAttributeList(data, 0);
  47. }
  48. public override byte[] GetSetup()
  49. {
  50. return LittleEndianConverter.GetBytes((ushort)SubcommandName);
  51. }
  52. public override byte[] GetParameters(bool isUnicode)
  53. {
  54. int length = 28;
  55. if (isUnicode)
  56. {
  57. length += FileName.Length * 2 + 2;
  58. }
  59. else
  60. {
  61. length += FileName.Length + 1;
  62. }
  63. byte[] parameters = new byte[length];
  64. LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)Flags);
  65. AccessMode.WriteBytes(parameters, 2);
  66. LittleEndianWriter.WriteUInt16(parameters, 4, Reserved1);
  67. LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)FileAttributes);
  68. SMB1Helper.WriteUTime(parameters, 8, CreationTime);
  69. OpenMode.WriteBytes(parameters, 12);
  70. LittleEndianWriter.WriteUInt32(parameters, 14, AllocationSize);
  71. ByteWriter.WriteBytes(parameters, 18, Reserved, 10);
  72. SMB1Helper.WriteSMBString(parameters, 28, isUnicode, FileName);
  73. return parameters;
  74. }
  75. public override byte[] GetData(bool isUnicode)
  76. {
  77. return ExtendedAttributeList.GetBytes();
  78. }
  79. public override Transaction2SubcommandName SubcommandName
  80. {
  81. get
  82. {
  83. return Transaction2SubcommandName.TRANS2_OPEN2;
  84. }
  85. }
  86. }
  87. }