SetInformationRequest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.IO;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_COM_SET_INFORMATION Request
  15. /// </summary>
  16. public class SetInformationRequest : SMB1Command
  17. {
  18. public const int ParametersLength = 16;
  19. public const int SupportedBufferFormat = 0x04;
  20. // Parameters:
  21. public SMBFileAttributes FileAttributes;
  22. public DateTime? LastWriteTime;
  23. public byte[] Reserved; // 10 bytes
  24. // Data:
  25. public byte BufferFormat;
  26. public string FileName; // SMB_STRING
  27. public SetInformationRequest() : base()
  28. {
  29. Reserved = new byte[10];
  30. BufferFormat = SupportedBufferFormat;
  31. }
  32. public SetInformationRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  33. {
  34. FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
  35. LastWriteTime = UTimeHelper.ReadNullableUTime(this.SMBParameters, 2);
  36. Reserved = ByteReader.ReadBytes(this.SMBParameters, 6, 10);
  37. BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
  38. if (BufferFormat != SupportedBufferFormat)
  39. {
  40. throw new InvalidDataException("Unsupported Buffer Format");
  41. }
  42. FileName = SMB1Helper.ReadSMBString(this.SMBData, 1, isUnicode);
  43. }
  44. public override byte[] GetBytes(bool isUnicode)
  45. {
  46. this.SMBParameters = new byte[ParametersLength];
  47. LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)FileAttributes);
  48. UTimeHelper.WriteUTime(this.SMBParameters, 2, LastWriteTime);
  49. ByteWriter.WriteBytes(this.SMBParameters, 6, Reserved, 10);
  50. int length = 1;
  51. if (isUnicode)
  52. {
  53. length += FileName.Length * 2 + 2;
  54. }
  55. else
  56. {
  57. length += FileName.Length + 1;
  58. }
  59. this.SMBData = new byte[length];
  60. ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
  61. SMB1Helper.WriteSMBString(this.SMBData, 1, isUnicode, FileName);
  62. return base.GetBytes(isUnicode);
  63. }
  64. public override CommandName CommandName
  65. {
  66. get
  67. {
  68. return CommandName.SMB_COM_SET_INFORMATION;
  69. }
  70. }
  71. }
  72. }