CheckDirectoryRequest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_CHECK_DIRECTORY Request
  15. /// </summary>
  16. public class CheckDirectoryRequest : SMB1Command
  17. {
  18. public const byte SupportedBufferFormat = 0x04;
  19. // Data:
  20. public byte BufferFormat;
  21. public string DirectoryName; // SMB_STRING
  22. public CheckDirectoryRequest() : base()
  23. {
  24. BufferFormat = SupportedBufferFormat;
  25. DirectoryName = String.Empty;
  26. }
  27. public CheckDirectoryRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  28. {
  29. BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
  30. if (BufferFormat != SupportedBufferFormat)
  31. {
  32. throw new InvalidDataException("Unsupported Buffer Format");
  33. }
  34. DirectoryName = SMB1Helper.ReadSMBString(this.SMBData, 1, isUnicode);
  35. }
  36. public override byte[] GetBytes(bool isUnicode)
  37. {
  38. int length = 1;
  39. if (isUnicode)
  40. {
  41. length += DirectoryName.Length * 2 + 2;
  42. }
  43. else
  44. {
  45. length += DirectoryName.Length + 1;
  46. }
  47. this.SMBData = new byte[1 + length];
  48. ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
  49. SMB1Helper.WriteSMBString(this.SMBData, 1, isUnicode, DirectoryName);
  50. return base.GetBytes(isUnicode);
  51. }
  52. public override CommandName CommandName
  53. {
  54. get
  55. {
  56. return CommandName.SMB_COM_CHECK_DIRECTORY;
  57. }
  58. }
  59. }
  60. }