DeleteDirectoryRequest.cs 2.0 KB

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